You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ga...@apache.org on 2015/11/20 00:11:02 UTC

jclouds git commit: Avoid buffering ByteSource when not needed

Repository: jclouds
Updated Branches:
  refs/heads/master 2efcb2c5a -> 8d87bfc61


Avoid buffering ByteSource when not needed

This allows range requests of large files to work.  Regression from
79fe91bd035461d9344c03bda276cb12a7a10b1a.


Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/8d87bfc6
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/8d87bfc6
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/8d87bfc6

Branch: refs/heads/master
Commit: 8d87bfc61bd5190cd0711f6be0189f70741a8c61
Parents: 2efcb2c
Author: Andrew Gaul <ga...@apache.org>
Authored: Thu Nov 19 14:57:05 2015 -0800
Committer: Andrew Gaul <ga...@apache.org>
Committed: Thu Nov 19 15:10:23 2015 -0800

----------------------------------------------------------------------
 .../jclouds/blobstore/config/LocalBlobStore.java | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds/blob/8d87bfc6/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java
----------------------------------------------------------------------
diff --git a/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java b/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java
index 9c65be7..8d799c6 100644
--- a/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java
+++ b/blobstore/src/main/java/org/jclouds/blobstore/config/LocalBlobStore.java
@@ -84,8 +84,6 @@ import org.jclouds.io.ByteStreams2;
 import org.jclouds.io.ContentMetadata;
 import org.jclouds.io.ContentMetadataCodec;
 import org.jclouds.io.Payload;
-import org.jclouds.io.payloads.ByteArrayPayload;
-import org.jclouds.io.payloads.FilePayload;
 import org.jclouds.logging.Logger;
 import org.jclouds.util.Closeables2;
 
@@ -662,17 +660,16 @@ public final class LocalBlobStore implements BlobStore {
             long size = 0;
             ImmutableList.Builder<ByteSource> streams = ImmutableList.builder();
 
-            // We must call getRawContent to work around Blob.setPayload calling ByteSourcePayload.release. If the
-            // Local blobstore returns a ByteArrayPayload or FilePayload it uses a stream, otherwise it uses a
-            // byte array.
+            // Try to convert payload to ByteSource, otherwise wrap it.
             ByteSource byteSource;
             try {
-               Object inputStream = blob.getPayload().getRawContent();
-               byteSource = (inputStream instanceof ByteArrayPayload || inputStream instanceof FilePayload) ?
-                     (ByteSource) blob.getPayload().getRawContent()
-                     : ByteSource.wrap(ByteStreams2.toByteArrayAndClose(blob.getPayload().openStream()));
-            } catch (IOException e) {
-               throw new RuntimeException(e);
+               byteSource = (ByteSource) blob.getPayload().getRawContent();
+            } catch (ClassCastException cce) {
+               try {
+                  byteSource = ByteSource.wrap(ByteStreams2.toByteArrayAndClose(blob.getPayload().openStream()));
+               } catch (IOException e) {
+                  throw new RuntimeException(e);
+               }
             }
 
             for (String s : options.getRanges()) {