/** * This implementation invokes {@link #getBlob(String,String, GetOptions)} */ @Override public Blob getBlob(String containerName, String key) { return getBlob(containerName, key, GetOptions.NONE); }
/** This implementation invokes {@link #list(String, ListContainerOptions)} */ @Override public PageSet<? extends StorageMetadata> list(String containerName) { return this.list(containerName, ListContainerOptions.NONE); }
@Override public String putBlob(String containerName, Blob blob) { return putBlob(containerName, blob, PutOptions.NONE); }
@Override public DatabagItem deleteDatabagItem(String databagName, String databagItemId) { DatabagItem item = blobToDatabagItem.apply(databags.getBlob(databagName, databagItemId)); databags.removeBlob(databagName, databagItemId); return item; }
Blob blobPart = getBlob(mpu.containerName(), MULTIPART_PREFIX + mpu.id() + "-" + mpu.blobName() + "-" + part.partNumber()); contentLength += blobPart.getMetadata().getContentMetadata().getContentLength(); blobs.add(blobPart); .append("\"") .toString(); PayloadBlobBuilder blobBuilder = blobBuilder(mpu.blobName()) .userMetadata(mpu.blobMetadata().getUserMetadata()) .payload(new MultiBlobInputStream(blobs.build())) putBlob(mpu.containerName(), blobBuilder.build()); removeBlob(mpu.containerName(), MULTIPART_PREFIX + mpu.id() + "-" + mpu.blobName() + "-" + part.partNumber()); removeBlob(mpu.containerName(), MULTIPART_PREFIX + mpu.id() + "-" + mpu.blobName() + "-stub"); setBlobAccess(mpu.containerName(), mpu.blobName(), mpu.putOptions().getBlobAccess());
@Override 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"); 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); if (lastModified != null) { if (options.ifModifiedSince() != null && lastModified.compareTo(options.ifModifiedSince()) <= 0) { throw returnResponseException(412); throw returnResponseException(412); is = blob.getPayload().openStream(); ContentMetadata metadata = blob.getMetadata().getContentMetadata(); BlobBuilder.PayloadBlobBuilder builder = blobBuilder(toName) .payload(is); Long contentLength = metadata.getContentLength(); return putBlob(toContainer, builder.build()); } catch (IOException ioe) { throw Throwables.propagate(ioe);
throw cnfe(containerName); Blob blob = loadBlob(containerName, key); eTag = maybeQuoteETag(eTag); if (options.getIfMatch() != null) { if (!eTag.equals(maybeQuoteETag(options.getIfMatch()))) throw returnResponseException(412); if (eTag.equals(maybeQuoteETag(options.getIfNoneMatch()))) throw returnResponseException(304); blob = copyBlob(blob);
throw cnfe(containerName); if (options != null) { if (options.getDir() != null && !options.getDir().isEmpty()) { contents = filterDirectory(contents, options); } else if (!Strings.isNullOrEmpty(options.getPrefix())) { contents = filterPrefix(contents, options); } else if (!options.isRecursive() || (options.getDelimiter() != null)) { String delimiter = options.getDelimiter() == null ? storageStrategy.getSeparator() : options.getDelimiter(); contents = extractCommonPrefixes(contents, delimiter, null);
@Override public DatabagItem createDatabagItem(String databagName, DatabagItem databagItem) { Blob blob = databags.blobBuilder(databagItem.getId()).payload(databagItem.toString()).build(); databags.putBlob(databagName, blob); return databagItem; }
@Override public String putBlob(String containerName, Blob blob, PutOptions options) { checkNotNull(containerName, "containerName must be set"); checkNotNull(blob, "blob must be set"); String blobKey = blob.getMetadata().getName(); logger.debug("Put blob with key [%s] to container [%s]", blobKey, containerName); if (!storageStrategy.containerExists(containerName)) { throw cnfe(containerName); } try { String eTag = storageStrategy.putBlob(containerName, blob); setBlobAccess(containerName, blobKey, options.getBlobAccess()); return eTag; } catch (IOException e) { String message = e.getMessage(); if (message != null && message.startsWith("MD5 hash code mismatch")) { HttpResponseException exception = returnResponseException(400); exception.initCause(e); throw exception; } logger.error(e, "An error occurred storing the new blob with name [%s] to container [%s].", blobKey, containerName); throw propagate(e); } }
@Override public MultipartPart uploadMultipartPart(MultipartUpload mpu, int partNumber, Payload payload) { String partName = MULTIPART_PREFIX + mpu.id() + "-" + mpu.blobName() + "-" + partNumber; Blob blob = blobBuilder(partName) .payload(payload) .build(); String partETag = putBlob(mpu.containerName(), blob); BlobMetadata metadata = blobMetadata(mpu.containerName(), partName); // TODO: racy, how to get this from payload? long partSize = metadata.getContentMetadata().getContentLength(); return MultipartPart.create(partNumber, partSize, partETag, metadata.getLastModified()); }
@Override public void abortMultipartUpload(MultipartUpload mpu) { List<MultipartPart> parts = listMultipartUpload(mpu); for (MultipartPart part : parts) { removeBlob(mpu.containerName(), MULTIPART_PREFIX + mpu.id() + "-" + mpu.blobName() + "-" + part.partNumber()); } removeBlob(mpu.containerName(), MULTIPART_PREFIX + mpu.id() + "-" + mpu.blobName() + "-stub"); }
@Override public void removeBlob(String containerName, final String key) { if (!storageStrategy.containerExists(containerName)) { throw cnfe(containerName); } storageStrategy.removeBlob(containerName, key); }
@Override public void removeBlobs(String container, Iterable<String> names) { for (String name : names) { removeBlob(container, name); } }
/** * This implementation invokes {@link #countBlobs} with the * {@link ListContainerOptions#recursive} option. */ @Override public long countBlobs(String containerName) { return countBlobs(containerName, recursive()); }
private Blob copyBlob(Blob blob) { Blob returnVal = blobFactory.create(BlobStoreUtils.copy(blob.getMetadata())); returnVal.setPayload(blob.getPayload()); copyPayloadHeadersToBlob(blob.getPayload(), returnVal); return returnVal; }
/** * This implementation invokes {@link #clearContainer} with the * {@link ListContainerOptions#recursive} option. */ @Override public void clearContainer(String containerName) { clearContainer(containerName, recursive()); }
long contentLength = 0; for (MultipartPart part : parts) { Blob blobPart = getBlob(mpu.containerName(), MULTIPART_PREFIX + mpu.id() + "-" + mpu.blobName() + "-" + part.partNumber()); contentLength += blobPart.getMetadata().getContentMetadata().getContentLength(); InputStream is; PayloadBlobBuilder blobBuilder = blobBuilder(mpu.blobName()) .userMetadata(mpu.blobMetadata().getUserMetadata()) .payload(new SequenceInputStream(Iterators.asEnumeration(streams.build().iterator()))) String eTag = putBlob(mpu.containerName(), blobBuilder.build()); removeBlob(mpu.containerName(), MULTIPART_PREFIX + mpu.id() + "-" + mpu.blobName() + "-" + part.partNumber()); removeBlob(mpu.containerName(), MULTIPART_PREFIX + mpu.id() + "-" + mpu.blobName() + "-stub"); setBlobAccess(mpu.containerName(), mpu.blobName(), mpu.putOptions().getBlobAccess());
@Override 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"); 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); if (lastModified != null) { if (options.ifModifiedSince() != null && lastModified.compareTo(options.ifModifiedSince()) <= 0) { throw returnResponseException(412); throw returnResponseException(412); is = blob.getPayload().openStream(); ContentMetadata metadata = blob.getMetadata().getContentMetadata(); BlobBuilder.PayloadBlobBuilder builder = blobBuilder(toName) .payload(is); Long contentLength = metadata.getContentLength(); return putBlob(toContainer, builder.build()); } catch (IOException ioe) { throw Throwables.propagate(ioe);
throw cnfe(containerName); Blob blob = loadBlob(containerName, key); eTag = maybeQuoteETag(eTag); if (options.getIfMatch() != null) { if (!eTag.equals(maybeQuoteETag(options.getIfMatch()))) throw returnResponseException(412); if (eTag.equals(maybeQuoteETag(options.getIfNoneMatch()))) throw returnResponseException(304); blob = copyBlob(blob);