in apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/blobstore/RegionScopedSwiftBlobStore.java [286:363]
public String copyBlob(String fromContainer, String fromName, String toContainer, String toName,
CopyOptions options) {
ObjectApi objectApi = api.getObjectApi(regionId, toContainer);
org.jclouds.openstack.swift.v1.options.CopyOptions swiftOptions = new org.jclouds.openstack.swift.v1.options.CopyOptions();
if (options.ifMatch() != null) {
swiftOptions.ifMatch(options.ifMatch());
}
if (options.ifNoneMatch() != null) {
throw new UnsupportedOperationException("Swift does not support ifNoneMatch");
}
if (options.ifModifiedSince() != null) {
swiftOptions.ifModifiedSince(options.ifModifiedSince());
}
if (options.ifUnmodifiedSince() != null) {
swiftOptions.ifUnmodifiedSince(options.ifUnmodifiedSince());
}
Map<String, String> systemMetadata = Maps.newHashMap();
ContentMetadata contentMetadata = options.contentMetadata();
Map<String, String> userMetadata = options.userMetadata();
if (contentMetadata != null || userMetadata != null) {
if (contentMetadata != null) {
String contentDisposition = contentMetadata.getContentDisposition();
if (contentDisposition != null) {
systemMetadata.put(HttpHeaders.CONTENT_DISPOSITION, contentDisposition);
}
String contentEncoding = contentMetadata.getContentEncoding();
if (contentEncoding != null) {
systemMetadata.put(HttpHeaders.CONTENT_ENCODING, contentEncoding);
}
String contentLanguage = contentMetadata.getContentLanguage();
if (contentLanguage != null) {
systemMetadata.put(HttpHeaders.CONTENT_LANGUAGE, contentLanguage);
}
String contentType = contentMetadata.getContentType();
if (contentType != null) {
systemMetadata.put(HttpHeaders.CONTENT_TYPE, contentType);
}
}
if (userMetadata == null) {
userMetadata = Maps.newHashMap();
}
} else {
SwiftObject metadata = api.getObjectApi(regionId, fromContainer).getWithoutBody(fromName);
if (metadata == null) {
throw new KeyNotFoundException(fromContainer, fromName, "Swift could not find the specified source key");
}
contentMetadata = metadata.getPayload().getContentMetadata();
String contentDisposition = contentMetadata.getContentDisposition();
if (contentDisposition != null) {
systemMetadata.put(HttpHeaders.CONTENT_DISPOSITION, contentDisposition);
}
String contentEncoding = contentMetadata.getContentEncoding();
if (contentEncoding != null) {
systemMetadata.put(HttpHeaders.CONTENT_ENCODING, contentEncoding);
}
String contentLanguage = contentMetadata.getContentLanguage();
if (contentLanguage != null) {
systemMetadata.put(HttpHeaders.CONTENT_LANGUAGE, contentLanguage);
}
String contentType = contentMetadata.getContentType();
if (contentType != null) {
systemMetadata.put(HttpHeaders.CONTENT_TYPE, contentType);
}
userMetadata = metadata.getMetadata();
}
objectApi.copy(toName, fromContainer, fromName, userMetadata, systemMetadata, swiftOptions);
// TODO: Swift copy object *appends* user metadata, does not overwrite
return objectApi.getWithoutBody(toName).getETag();
}