private String putDirectoryBlob(final String containerName, final Blob blob) throws IOException {
    String blobKey = blob.getMetadata().getName();
    ContentMetadata metadata = blob.getMetadata().getContentMetadata();
    Long contentLength = metadata.getContentLength();
    if (contentLength != null && contentLength != 0) {
      throw new IllegalArgumentException("Directory blob cannot have content: " + blobKey);
    }
    File outputFile = getFileForBlobKey(containerName, blobKey);
    Path outputPath = outputFile.toPath();
    if (!outputFile.isDirectory() && !outputFile.mkdirs()) {
      throw new IOException("Unable to mkdir: " + outputPath);
    }

    UserDefinedFileAttributeView view = getUserDefinedFileAttributeView(outputPath);
    if (view != null) {
      try {
        view.write(XATTR_CONTENT_MD5, ByteBuffer.wrap(DIRECTORY_MD5));
        writeCommonMetadataAttr(view, blob);
      } catch (IOException e) {
        logger.debug("xattrs not supported on %s", outputPath);
      }
    } else {
      logger.warn("xattr not supported on %s", blobKey);
    }

    return base16().lowerCase().encode(DIRECTORY_MD5);
  }
示例#2
0
 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());
 }
示例#3
0
    private Payload createPayload(byte[] content) {
      Payload payload = null;

      if (content.length > 0) {
        payload = new ByteArrayPayload(content);
        ContentMetadata cm =
            metaData.toBuilder().contentLength((long) content.length).contentMD5(null).build();
        payload.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(cm));
      }

      return payload;
    }
 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();
  }