@VisibleForTesting void parseLastModifiedOrThrowException(HttpResponse from, MutableBlobMetadata metadata) throws HttpException { String lastModified = from.getFirstHeaderOrNull(HttpHeaders.LAST_MODIFIED); if (lastModified == null) { // scaleup-storage uses the wrong case for the last modified header if ((lastModified = from.getFirstHeaderOrNull("Last-modified")) == null) throw new HttpException(HttpHeaders.LAST_MODIFIED + " header not present in response: " + from); } // Walrus if (lastModified.startsWith("20")) { metadata.setLastModified(dateParser.iso8601DateParse(lastModified.replace("+0000", "Z"))); } else { metadata.setLastModified(dateParser.rfc822DateParse(lastModified)); } if (metadata.getLastModified() == null) throw new HttpException("could not parse: " + HttpHeaders.LAST_MODIFIED + ": " + lastModified); }
@VisibleForTesting void parseLastModifiedOrThrowException(HttpResponse from, MutableBlobMetadata metadata) throws HttpException { String lastModified = from.getFirstHeaderOrNull(HttpHeaders.LAST_MODIFIED); if (lastModified == null) { // scaleup-storage uses the wrong case for the last modified header if ((lastModified = from.getFirstHeaderOrNull("Last-modified")) == null) throw new HttpException(HttpHeaders.LAST_MODIFIED + " header not present in response: " + from); } // Walrus if (lastModified.startsWith("20")) { metadata.setLastModified(dateParser.iso8601DateParse(lastModified.replace("+0000", "Z"))); } else { metadata.setLastModified(dateParser.rfc822DateParse(lastModified)); } if (metadata.getLastModified() == null) throw new HttpException("could not parse: " + HttpHeaders.LAST_MODIFIED + ": " + lastModified); }
@VisibleForTesting void parseLastModifiedOrThrowException(HttpResponse from, MutableBlobMetadata metadata) throws HttpException { String lastModified = from.getFirstHeaderOrNull(HttpHeaders.LAST_MODIFIED); if (lastModified == null) { // scaleup-storage uses the wrong case for the last modified header if ((lastModified = from.getFirstHeaderOrNull("Last-modified")) == null) throw new HttpException(HttpHeaders.LAST_MODIFIED + " header not present in response: " + from); } // Walrus if (lastModified.startsWith("20")) { metadata.setLastModified(dateParser.iso8601DateParse(lastModified.replace("+0000", "Z"))); } else { metadata.setLastModified(dateParser.rfc822DateParse(lastModified)); } if (metadata.getLastModified() == null) throw new HttpException("could not parse: " + HttpHeaders.LAST_MODIFIED + ": " + lastModified); }
@VisibleForTesting void parseLastModifiedOrThrowException(HttpResponse from, MutableBlobMetadata metadata) throws HttpException { String lastModified = from.getFirstHeaderOrNull(HttpHeaders.LAST_MODIFIED); if (lastModified == null) { // scaleup-storage uses the wrong case for the last modified header if ((lastModified = from.getFirstHeaderOrNull("Last-modified")) == null) throw new HttpException(HttpHeaders.LAST_MODIFIED + " header not present in response: " + from); } // Walrus if (lastModified.startsWith("20")) { metadata.setLastModified(dateParser.iso8601DateParse(lastModified.replace("+0000", "Z"))); } else { metadata.setLastModified(dateParser.rfc822DateParse(lastModified)); } if (metadata.getLastModified() == null) throw new HttpException("could not parse: " + HttpHeaders.LAST_MODIFIED + ": " + lastModified); }
@VisibleForTesting void parseLastModifiedOrThrowException(HttpResponse from, MutableBlobMetadata metadata) throws HttpException { String lastModified = from.getFirstHeaderOrNull(HttpHeaders.LAST_MODIFIED); if (lastModified == null) { // scaleup-storage uses the wrong case for the last modified header if ((lastModified = from.getFirstHeaderOrNull("Last-modified")) == null) throw new HttpException(HttpHeaders.LAST_MODIFIED + " header not present in response: " + from); } // Walrus if (lastModified.startsWith("20")) { metadata.setLastModified(dateParser.iso8601DateParse(lastModified.replace("+0000", "Z"))); } else { metadata.setLastModified(dateParser.rfc822DateParse(lastModified)); } if (metadata.getLastModified() == null) throw new HttpException("could not parse: " + HttpHeaders.LAST_MODIFIED + ": " + lastModified); }
@VisibleForTesting void parseLastModifiedOrThrowException(HttpResponse from, MutableBlobMetadata metadata) throws HttpException { String lastModified = from.getFirstHeaderOrNull(HttpHeaders.LAST_MODIFIED); if (lastModified == null) { // scaleup-storage uses the wrong case for the last modified header if ((lastModified = from.getFirstHeaderOrNull("Last-modified")) == null) throw new HttpException(HttpHeaders.LAST_MODIFIED + " header not present in response: " + from); } // Walrus if (lastModified.startsWith("20")) { metadata.setLastModified(dateParser.iso8601DateParse(lastModified.replace("+0000", "Z"))); } else { metadata.setLastModified(dateParser.rfc822DateParse(lastModified)); } if (metadata.getLastModified() == null) throw new HttpException("could not parse: " + HttpHeaders.LAST_MODIFIED + ": " + lastModified); }
@VisibleForTesting void parseLastModifiedOrThrowException(HttpResponse from, MutableBlobMetadata metadata) throws HttpException { String lastModified = from.getFirstHeaderOrNull(HttpHeaders.LAST_MODIFIED); if (lastModified == null) { // scaleup-storage uses the wrong case for the last modified header if ((lastModified = from.getFirstHeaderOrNull("Last-modified")) == null) throw new HttpException(HttpHeaders.LAST_MODIFIED + " header not present in response: " + from); } // Walrus if (lastModified.startsWith("20")) { metadata.setLastModified(dateParser.iso8601DateParse(lastModified.replace("+0000", "Z"))); } else { metadata.setLastModified(dateParser.rfc822DateParse(lastModified)); } if (metadata.getLastModified() == null) throw new HttpException("could not parse: " + HttpHeaders.LAST_MODIFIED + ": " + lastModified); }
public MutableBlobMetadata apply(AtmosObject from) { if (from == null) return null; MutableBlobMetadata to = new MutableBlobMetadataImpl(); to.setId(from.getSystemMetadata().getObjectID()); to.setLastModified(from.getSystemMetadata().getLastUserDataModification()); HttpUtils.copy(from.getContentMetadata(), to.getContentMetadata()); to.setName(objectName.apply(from)); to.setUri(from.getContentMetadata().getUri()); to.setContainer(Iterables.get(Splitter.on('/').split(from.getContentMetadata().getPath()),0)); if (from.getAllHeaders().containsEntry("x-emc-groupacl", "other=READ")) to.setPublicUri(shareUrl.apply(from.getContentMetadata().getPath())); if (from.getSystemMetadata().getType() == FileType.DIRECTORY) { to.setType(StorageType.FOLDER); } else { to.setType(StorageType.BLOB); } Map<String, String> lowerKeyMetadata = Maps.newHashMap(); for (Entry<String, String> entry : from.getUserMetadata().getMetadata().entrySet()) { String key = entry.getKey().toLowerCase(); if (!systemMetadata.contains(key)) lowerKeyMetadata.put(key, entry.getValue()); } to.setUserMetadata(lowerKeyMetadata); return to; } }
private Blob createUpdatedCopyOfBlobInContainer(String containerName, Blob in, byte[] input, HashCode contentMd5) { checkNotNull(containerName, "containerName"); checkNotNull(in, "blob"); checkNotNull(input, "input"); checkNotNull(contentMd5, "contentMd5"); Payload payload = Payloads.newByteSourcePayload(ByteSource.wrap(input)); MutableContentMetadata oldMd = in.getPayload().getContentMetadata(); HttpUtils.copy(oldMd, payload.getContentMetadata()); payload.getContentMetadata().setContentMD5(contentMd5); payload.getContentMetadata().setContentLength((long) input.length); Blob blob = blobFactory.create(BlobStoreUtils.copy(in.getMetadata())); blob.setPayload(payload); blob.getMetadata().setContainer(containerName); blob.getMetadata().setLastModified(new Date()); blob.getMetadata().setSize((long) input.length); String eTag = base16().lowerCase().encode(contentMd5.asBytes()); blob.getMetadata().setETag(eTag); // Set HTTP headers to match metadata blob.getAllHeaders().replaceValues(HttpHeaders.LAST_MODIFIED, ImmutableList.of(dateService.rfc822DateFormat(blob.getMetadata().getLastModified()))); blob.getAllHeaders().replaceValues(HttpHeaders.ETAG, ImmutableList.of(eTag)); copyPayloadHeadersToBlob(payload, blob); blob.getAllHeaders().putAll(Multimaps.forMap(blob.getMetadata().getUserMetadata())); return blob; }
private Blob createUpdatedCopyOfBlobInContainer(String containerName, Blob in, byte[] input, HashCode contentMd5) { checkNotNull(containerName, "containerName"); checkNotNull(in, "blob"); checkNotNull(input, "input"); checkNotNull(contentMd5, "contentMd5"); Payload payload = Payloads.newByteSourcePayload(ByteSource.wrap(input)); MutableContentMetadata oldMd = in.getPayload().getContentMetadata(); HttpUtils.copy(oldMd, payload.getContentMetadata()); payload.getContentMetadata().setContentMD5(contentMd5); payload.getContentMetadata().setContentLength((long) input.length); Blob blob = blobFactory.create(BlobStoreUtils.copy(in.getMetadata())); blob.setPayload(payload); blob.getMetadata().setContainer(containerName); blob.getMetadata().setLastModified(new Date()); blob.getMetadata().setSize((long) input.length); String eTag = base16().lowerCase().encode(contentMd5.asBytes()); blob.getMetadata().setETag(eTag); // Set HTTP headers to match metadata blob.getAllHeaders().replaceValues(HttpHeaders.LAST_MODIFIED, ImmutableList.of(dateService.rfc822DateFormat(blob.getMetadata().getLastModified()))); blob.getAllHeaders().replaceValues(HttpHeaders.ETAG, ImmutableList.of(eTag)); copyPayloadHeadersToBlob(payload, blob); blob.getAllHeaders().putAll(Multimaps.forMap(blob.getMetadata().getUserMetadata())); return blob; }
private MutableBlobMetadata toBlobMetadata(String container, B2Object b2Object) { MutableBlobMetadata metadata = new MutableBlobMetadataImpl(); metadata.setContainer(container); metadata.setETag(b2Object.contentSha1()); // B2 does not support ETag, fake it with SHA-1 metadata.setLastModified(b2Object.uploadTimestamp()); metadata.setName(b2Object.fileName()); metadata.setSize(b2Object.contentLength()); MutableContentMetadata contentMetadata = new BaseMutableContentMetadata(); contentMetadata.setContentLength(b2Object.contentLength()); contentMetadata.setContentType(b2Object.contentType()); metadata.setContentMetadata(contentMetadata); metadata.setUserMetadata(b2Object.fileInfo()); try { metadata.setPublicUri(URI.create(auth.get().downloadUrl() + "/file/" + container + "/" + URLEncoder.encode(b2Object.fileName(), "UTF-8"))); } catch (UnsupportedEncodingException uee) { throw new RuntimeException(uee); } return metadata; } }
private MutableBlobMetadata toBlobMetadata(String container, B2Object b2Object) { MutableBlobMetadata metadata = new MutableBlobMetadataImpl(); metadata.setContainer(container); metadata.setETag(b2Object.contentSha1()); // B2 does not support ETag, fake it with SHA-1 metadata.setLastModified(b2Object.uploadTimestamp()); metadata.setName(b2Object.fileName()); metadata.setSize(b2Object.contentLength()); MutableContentMetadata contentMetadata = new BaseMutableContentMetadata(); contentMetadata.setContentLength(b2Object.contentLength()); contentMetadata.setContentType(b2Object.contentType()); metadata.setContentMetadata(contentMetadata); metadata.setUserMetadata(b2Object.fileInfo()); try { metadata.setPublicUri(URI.create(auth.get().downloadUrl() + "/file/" + container + "/" + URLEncoder.encode(b2Object.fileName(), "UTF-8"))); } catch (UnsupportedEncodingException uee) { throw new RuntimeException(uee); } return metadata; } }
@Override public MutableBlobMetadata apply(GridFSDBFile input) { MutableBlobMetadata metadata = new MutableBlobMetadataImpl(); MutableContentMetadata contentMetadata = metadata.getContentMetadata(); String contentType = input.getContentType(); if (contentType != null) { contentMetadata.setContentType(contentType); } contentMetadata.setContentLength(input.getLength()); metadata.setETag(input.getMD5()); metadata.setLastModified(input.getUploadDate()); metadata.setName(input.getFilename()); metadata.getUserMetadata().putAll(input.getMetaData().toMap()); // TODO: support populating metadata.getContentMetadata().setContentMD5() return metadata; } }
public MutableBlobMetadata apply(ObjectMetadata from) { if (from == null) return null; MutableBlobMetadata to = new MutableBlobMetadataImpl(); HttpUtils.copy(from.getContentMetadata(), to.getContentMetadata()); to.setUri(from.getUri()); to.setContainer(from.getBucket()); to.setETag(from.getETag()); to.setName(from.getKey()); to.setLastModified(from.getLastModified()); to.setUserMetadata(from.getUserMetadata()); to.setLocation(locationOfBucket.apply(from.getBucket())); to.setType(StorageType.BLOB); to.setSize(from.getContentMetadata().getContentLength()); return to; } }
public MutableBlobMetadata apply(BlobProperties from) { if (from == null) return null; MutableBlobMetadata to = new MutableBlobMetadataImpl(); HttpUtils.copy(from.getContentMetadata(), to.getContentMetadata()); to.setUserMetadata(from.getMetadata()); to.setETag(from.getETag()); to.setLastModified(from.getLastModified()); to.setName(from.getName()); String directoryName = ifDirectoryReturnName.execute(to); if (directoryName != null) { to.setName(directoryName); to.setType(StorageType.RELATIVE_PATH); } else { to.setType(StorageType.BLOB); } return to; } }
public MutableBlobMetadata apply(ObjectMetadata from) { if (from == null) return null; MutableBlobMetadata to = new MutableBlobMetadataImpl(); HttpUtils.copy(from.getContentMetadata(), to.getContentMetadata()); to.setETag(from.getETag()); to.setName(from.getKey()); to.setLastModified(from.getLastModified()); to.setUserMetadata(from.getUserMetadata()); String directoryName = ifDirectoryReturnName.execute(to); if (directoryName != null) { to.setName(directoryName); to.setType(StorageType.RELATIVE_PATH); } else { to.setType(StorageType.BLOB); } return to; } }
public MutableBlobMetadata apply(ObjectInfo from) { if (from == null) return null; MutableBlobMetadata to = new MutableBlobMetadataImpl(); to.getContentMetadata().setContentMD5(from.getHash()); if (from.getContentType() != null) to.getContentMetadata().setContentType(from.getContentType()); if (from.getHash() != null) to.setETag(base16().lowerCase().encode(from.getHash())); to.setName(from.getName()); to.setContainer(from.getContainer()); to.setUri(from.getUri()); to.getContentMetadata().setContentLength(from.getBytes()); if (from.getLastModified() != null) to.setLastModified(from.getLastModified()); if (from instanceof MutableObjectInfoWithMetadata) to.setUserMetadata(((MutableObjectInfoWithMetadata) from).getMetadata()); String directoryName = ifDirectoryReturnName.execute(to); if (directoryName != null) { to.setName(directoryName); to.setType(StorageType.RELATIVE_PATH); } else { to.setType(StorageType.BLOB); } return to; } }
public MutableBlobMetadata apply(ObjectMetadata from) { if (from == null) return null; MutableBlobMetadata to = new MutableBlobMetadataImpl(); HttpUtils.copy(from.getContentMetadata(), to.getContentMetadata()); to.setUri(from.getUri()); to.setContainer(from.getBucket()); to.setETag(from.getETag()); to.setName(from.getKey()); to.setLastModified(from.getLastModified()); to.setUserMetadata(from.getUserMetadata()); to.setLocation(locationOfBucket.apply(from.getBucket())); to.setType(StorageType.BLOB); to.setSize(from.getContentMetadata().getContentLength()); to.setTier((from.getStorageClass() == null ? ObjectMetadata.StorageClass.STANDARD : from.getStorageClass()).toTier()); return to; } }
public MutableBlobMetadata apply(ObjectMetadata from) { if (from == null) return null; MutableBlobMetadata to = new MutableBlobMetadataImpl(); HttpUtils.copy(from.getContentMetadata(), to.getContentMetadata()); to.setUri(from.getUri()); to.setContainer(from.getBucket()); to.setETag(from.getETag()); to.setName(from.getKey()); to.setLastModified(from.getLastModified()); to.setUserMetadata(from.getUserMetadata()); to.setLocation(locationOfBucket.apply(from.getBucket())); to.setType(StorageType.BLOB); to.setSize(from.getContentMetadata().getContentLength()); to.setTier((from.getStorageClass() == null ? ObjectMetadata.StorageClass.STANDARD : from.getStorageClass()).toTier()); return to; } }
public MutableBlobMetadata apply(GoogleCloudStorageObject from) { if (from == null) { return null; } MutableBlobMetadata to = new MutableBlobMetadataImpl(); to.getContentMetadata().setContentMD5(toHashCode(from.md5Hash())); to.getContentMetadata().setContentType(from.contentType()); to.getContentMetadata().setContentDisposition(from.contentDisposition()); to.getContentMetadata().setContentEncoding(from.contentEncoding()); to.getContentMetadata().setContentLanguage(from.contentLanguage()); to.getContentMetadata().setContentLength(from.size()); to.setLastModified(from.updated()); to.setContainer(from.bucket()); to.setUserMetadata(from.metadata()); to.setETag(from.etag()); to.setName(from.name()); to.setUri(from.selfLink()); to.setId(from.id()); to.setPublicUri(from.mediaLink()); to.setType(StorageType.BLOB); to.setSize(from.size()); to.setTier(from.storageClass().toTier()); return to; }