diff --git a/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemAsyncBlobStore.java b/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemAsyncBlobStore.java index 66b8dde35a..d186ac196c 100644 --- a/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemAsyncBlobStore.java +++ b/apis/filesystem/src/main/java/org/jclouds/filesystem/FilesystemAsyncBlobStore.java @@ -343,33 +343,9 @@ public class FilesystemAsyncBlobStore extends BaseAsyncBlobStore { return immediateFuture(result); } - /** - * Load the blob with the given key belonging to the container with the given - * name. There must exist a resource on the file system whose complete name - * is given concatenating the container name and the key - * - * @param container - * it's the name of the container the blob belongs to - * @param key - * it's the key of the blob - * - * @return the blob belonging to the given container with the given key - */ private Blob loadBlob(final String container, final String key) { logger.debug("Opening blob in container: %s - %s", container, key); - BlobBuilder builder = blobUtils.blobBuilder(); - builder.name(key); - File file = storageStrategy.getFileForBlobKey(container, key); - try { - builder.payload(file).calculateMD5(); - } catch (IOException e) { - logger.error("An error occurred calculating MD5 for blob %s from container ", key, container); - Throwables.propagateIfPossible(e); - } - Blob blob = builder.build(); - if (blob.getPayload().getContentMetadata().getContentMD5() != null) - blob.getMetadata().setETag(CryptoStreams.hex(blob.getPayload().getContentMetadata().getContentMD5())); - return blob; + return storageStrategy.getBlob(container, key); } protected static class DelimiterFilter implements Predicate { diff --git a/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/FilesystemStorageStrategy.java b/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/FilesystemStorageStrategy.java index 2e341c49d9..a0c8662b63 100644 --- a/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/FilesystemStorageStrategy.java +++ b/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/FilesystemStorageStrategy.java @@ -123,6 +123,20 @@ public interface FilesystemStorageStrategy { */ boolean blobExists(String container, String key); + /** + * Load the blob with the given key belonging to the container with the given + * name. There must exist a resource on the file system whose complete name + * is given concatenating the container name and the key + * + * @param container + * it's the name of the container the blob belongs to + * @param key + * it's the key of the blob + * + * @return the blob belonging to the given container with the given key + */ + Blob getBlob(final String containerName, final String blobName); + /** * Returns all the blobs key inside a container * @param container diff --git a/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java b/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java index 2818cdfa97..b3ea8bf275 100644 --- a/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java +++ b/apis/filesystem/src/main/java/org/jclouds/filesystem/strategy/internal/FilesystemStorageStrategyImpl.java @@ -38,6 +38,7 @@ import org.apache.commons.io.filefilter.DirectoryFileFilter; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.BlobBuilder; import org.jclouds.blobstore.options.ListContainerOptions; +import org.jclouds.crypto.CryptoStreams; import org.jclouds.filesystem.predicates.validators.FilesystemBlobKeyValidator; import org.jclouds.filesystem.predicates.validators.FilesystemContainerNameValidator; import org.jclouds.filesystem.reference.FilesystemConstants; @@ -91,6 +92,23 @@ public class FilesystemStorageStrategyImpl implements FilesystemStorageStrategy return buildPathAndChecksIfFileExists(container, key); } + @Override + public Blob getBlob(final String container, final String key) { + BlobBuilder builder = blobBuilders.get(); + builder.name(key); + File file = getFileForBlobKey(container, key); + try { + builder.payload(file).calculateMD5(); + } catch (IOException e) { + logger.error("An error occurred calculating MD5 for blob %s from container ", key, container); + Throwables.propagateIfPossible(e); + } + Blob blob = builder.build(); + if (blob.getPayload().getContentMetadata().getContentMD5() != null) + blob.getMetadata().setETag(CryptoStreams.hex(blob.getPayload().getContentMetadata().getContentMD5())); + return blob; + } + @Override public boolean createContainer(String container) { logger.debug("Creating container %s", container);