in blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java [529:610]
public String copyBlob(String fromContainer, String fromName, String toContainer, String toName,
CopyOptions options) {
Blob blob = getBlob(fromContainer, fromName);
if (blob == null) {
throw new KeyNotFoundException(fromContainer, fromName, "while copying");
}
String eTag = blob.getMetadata().getETag();
if (eTag != null) {
eTag = maybeQuoteETag(eTag);
if (options.ifMatch() != null && !maybeQuoteETag(options.ifMatch()).equals(eTag)) {
throw returnResponseException(412);
}
if (options.ifNoneMatch() != null && maybeQuoteETag(options.ifNoneMatch()).equals(eTag)) {
throw returnResponseException(412);
}
}
Date lastModified = blob.getMetadata().getLastModified();
if (lastModified != null) {
if (options.ifModifiedSince() != null && lastModified.compareTo(options.ifModifiedSince()) <= 0) {
throw returnResponseException(412);
}
if (options.ifUnmodifiedSince() != null && lastModified.compareTo(options.ifUnmodifiedSince()) >= 0) {
throw returnResponseException(412);
}
}
InputStream is = null;
try {
is = blob.getPayload().openStream();
ContentMetadata metadata = blob.getMetadata().getContentMetadata();
BlobBuilder.PayloadBlobBuilder builder = blobBuilder(toName)
.payload(is);
Long contentLength = metadata.getContentLength();
if (contentLength != null) {
builder.contentLength(contentLength);
}
ContentMetadata contentMetadata = options.contentMetadata();
if (contentMetadata != null) {
String cacheControl = contentMetadata.getCacheControl();
if (cacheControl != null) {
builder.cacheControl(cacheControl);
}
String contentDisposition = contentMetadata.getContentDisposition();
if (contentDisposition != null) {
builder.contentDisposition(contentDisposition);
}
String contentEncoding = contentMetadata.getContentEncoding();
if (contentEncoding != null) {
builder.contentEncoding(contentEncoding);
}
String contentLanguage = contentMetadata.getContentLanguage();
if (contentLanguage != null) {
builder.contentLanguage(contentLanguage);
}
String contentType = contentMetadata.getContentType();
if (contentType != null) {
builder.contentType(contentType);
}
} else {
builder.cacheControl(metadata.getCacheControl())
.contentDisposition(metadata.getContentDisposition())
.contentEncoding(metadata.getContentEncoding())
.contentLanguage(metadata.getContentLanguage())
.contentType(metadata.getContentType());
}
Map<String, String> userMetadata = options.userMetadata();
if (userMetadata != null) {
builder.userMetadata(userMetadata);
} else {
builder.userMetadata(blob.getMetadata().getUserMetadata());
}
return putBlob(toContainer, builder.build());
} catch (IOException ioe) {
throw Throwables.propagate(ioe);
} finally {
Closeables2.closeQuietly(is);
}
}