mirror of https://github.com/apache/jclouds.git
Harmonize filesystem and transient loadBlob
Move getBlob into FilesystemStorageStrategyImpl, similar to TransientStorageStrategy.
This commit is contained in:
parent
a30aad05ed
commit
1199c54f67
|
@ -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<StorageMetadata> {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue