@VisibleForTesting
 void addUserMetadataTo(HttpResponse from, MutableContainerPropertiesWithMetadata metadata) {
   for (Entry<String, String> header : from.getHeaders().entries()) {
     if (header.getKey() != null && header.getKey().startsWith(metadataPrefix))
       metadata
           .getMetadata()
           .put(
               (header.getKey().substring(metadataPrefix.length())).toLowerCase(),
               header.getValue());
   }
 }
Пример #2
0
 @Override
 public Container apply(HttpResponse from) {
   String bytesUsed = from.getFirstHeaderOrNull(CONTAINER_BYTES_USED);
   String objectCount = from.getFirstHeaderOrNull(CONTAINER_OBJECT_COUNT);
   Container c =
       Container.builder()
           .name(name)
           .bytesUsed(bytesUsed != null ? Long.valueOf(bytesUsed) : null)
           .objectCount(objectCount != null ? Long.valueOf(objectCount) : null)
           .anybodyRead(
               CONTAINER_ACL_ANYBODY_READ.equals(from.getFirstHeaderOrNull(CONTAINER_READ)))
           .metadata(EntriesWithoutMetaPrefix.INSTANCE.apply(from.getHeaders()))
           .build();
   return c;
 }
  @Override
  public B2Object apply(HttpResponse from) {
    Payload payload = from.getPayload();
    MutableContentMetadata contentMeta = payload.getContentMetadata();

    String fileId = from.getFirstHeaderOrNull(B2Headers.FILE_ID);
    String fileName;
    try {
      fileName = URLDecoder.decode(from.getFirstHeaderOrNull(B2Headers.FILE_NAME), "UTF-8");
    } catch (UnsupportedEncodingException uee) {
      throw Throwables.propagate(uee);
    }
    String contentSha1 = from.getFirstHeaderOrNull(B2Headers.CONTENT_SHA1);
    ImmutableMap.Builder<String, String> fileInfo = ImmutableMap.builder();
    for (Map.Entry<String, String> entry : from.getHeaders().entries()) {
      if (entry
          .getKey()
          .regionMatches(
              true, 0, B2Headers.FILE_INFO_PREFIX, 0, B2Headers.FILE_INFO_PREFIX.length())) {
        String value;
        try {
          value = URLDecoder.decode(entry.getValue(), "UTF-8");
        } catch (UnsupportedEncodingException uee) {
          throw Throwables.propagate(uee);
        }
        fileInfo.put(entry.getKey().substring(B2Headers.FILE_INFO_PREFIX.length()), value);
      }
    }
    Date uploadTimestamp =
        new Date(Long.parseLong(from.getFirstHeaderOrNull(B2Headers.UPLOAD_TIMESTAMP)));
    String contentRange = from.getFirstHeaderOrNull(HttpHeaders.CONTENT_RANGE);

    return B2Object.create(
        fileId,
        fileName,
        null,
        null,
        contentMeta.getContentLength(),
        contentSha1,
        contentMeta.getContentType(),
        fileInfo.build(),
        null,
        uploadTimestamp.getTime(),
        contentRange,
        payload);
  }
 public Boolean apply(HttpResponse from) {
   checkNotNull(from, "http response");
   return from.getHeaders().containsEntry("x-emc-groupacl", "other=READ");
 }