public static void copy(ContentMetadata fromMd, MutableContentMetadata toMd) { toMd.setContentLength(fromMd.getContentLength()); toMd.setContentMD5(fromMd.getContentMD5()); toMd.setContentType(fromMd.getContentType()); toMd.setContentDisposition(fromMd.getContentDisposition()); toMd.setContentEncoding(fromMd.getContentEncoding()); toMd.setContentLanguage(fromMd.getContentLanguage()); toMd.setExpires(fromMd.getExpires()); }
private void writeCommonMetadataAttr(UserDefinedFileAttributeView view, Blob blob) throws IOException { ContentMetadata metadata = blob.getMetadata().getContentMetadata(); writeStringAttributeIfPresent(view, XATTR_CACHE_CONTROL, metadata.getCacheControl()); writeStringAttributeIfPresent( view, XATTR_CONTENT_DISPOSITION, metadata.getContentDisposition()); writeStringAttributeIfPresent(view, XATTR_CONTENT_ENCODING, metadata.getContentEncoding()); writeStringAttributeIfPresent(view, XATTR_CONTENT_LANGUAGE, metadata.getContentLanguage()); writeStringAttributeIfPresent(view, XATTR_CONTENT_TYPE, metadata.getContentType()); Date expires = metadata.getExpires(); if (expires != null) { ByteBuffer buf = ByteBuffer.allocate(Longs.BYTES).putLong(expires.getTime()); buf.flip(); view.write(XATTR_EXPIRES, buf); } for (Map.Entry<String, String> entry : blob.getMetadata().getUserMetadata().entrySet()) { writeStringAttributeIfPresent( view, XATTR_USER_METADATA_PREFIX + entry.getKey(), entry.getValue()); } }
@SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument( checkNotNull(input, "input") instanceof ContentMetadata, "this binder is only valid for ContentMetadata"); checkNotNull(request, "request"); ContentMetadata contentMetadata = (ContentMetadata) input; ImmutableMap.Builder<String, String> headers = ImmutableMap.builder(); String cacheControl = contentMetadata.getCacheControl(); if (cacheControl != null) { headers.put(AzureStorageHeaders.CACHE_CONTROL, cacheControl); } String contentDisposition = contentMetadata.getContentDisposition(); if (contentDisposition != null) { headers.put(AzureStorageHeaders.CONTENT_DISPOSITION, contentDisposition); } String contentEncoding = contentMetadata.getContentEncoding(); if (contentEncoding != null) { headers.put(AzureStorageHeaders.CONTENT_ENCODING, contentEncoding); } String contentLanguage = contentMetadata.getContentLanguage(); if (contentLanguage != null) { headers.put(AzureStorageHeaders.CONTENT_LANGUAGE, contentLanguage); } String contentType = contentMetadata.getContentType(); if (contentType != null) { headers.put(AzureStorageHeaders.CONTENT_TYPE, contentType); } return (R) request.toBuilder().replaceHeaders(Multimaps.forMap(headers.build())).build(); }