Updated Branches:
  refs/heads/1.6.x 0253e9eb8 -> 85e976e7f

JCLOUDS-27: Allow repeatable Payload with InputSupplier input

This allows HTTP retries to work.  Also remove duplicated calls to
ByteStreams.slice.


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

Branch: refs/heads/1.6.x
Commit: 85e976e7f5b2fdc863f654a3761415501ce60c72
Parents: 0253e9e
Author: Andrew Gaul <[email protected]>
Authored: Fri May 10 15:39:48 2013 -0700
Committer: Andrew Gaul <[email protected]>
Committed: Fri May 17 10:09:36 2013 -0700

----------------------------------------------------------------------
 .../org/jclouds/io/internal/BasePayloadSlicer.java |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/85e976e7/core/src/main/java/org/jclouds/io/internal/BasePayloadSlicer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/jclouds/io/internal/BasePayloadSlicer.java 
b/core/src/main/java/org/jclouds/io/internal/BasePayloadSlicer.java
index 54a91b0..7b30d22 100644
--- a/core/src/main/java/org/jclouds/io/internal/BasePayloadSlicer.java
+++ b/core/src/main/java/org/jclouds/io/internal/BasePayloadSlicer.java
@@ -34,6 +34,7 @@ import org.jclouds.io.payloads.InputStreamSupplierPayload;
 import com.google.common.base.Throwables;
 import com.google.common.io.ByteStreams;
 import com.google.common.io.Files;
+import com.google.common.io.InputSupplier;
 
 /**
  * 
@@ -56,14 +57,16 @@ public class BasePayloadSlicer implements PayloadSlicer {
          returnVal = doSlice((byte[]) input.getRawContent(), offset, length);
       } else if (input.getRawContent() instanceof byte[]) {
          returnVal = doSlice((byte[]) input.getRawContent(), offset, length);
+      } else if (input.getRawContent() instanceof InputStream) {
+         returnVal = doSlice((InputStream) input.getRawContent(), offset, 
length);
       } else {
-         returnVal = doSlice(input.getInput(), offset, length);
+         returnVal = doSlice(input, offset, length);
       }
       return copyMetadataAndSetLength(input, returnVal, length);
    }
 
    protected Payload doSlice(Payload content, long offset, long length) {
-      return new InputStreamSupplierPayload(ByteStreams.slice(content, offset, 
length));
+      return doSlice((InputSupplier<? extends InputStream>) content, offset, 
length);
    }
 
    protected Payload doSlice(String content, long offset, long length) {
@@ -71,7 +74,7 @@ public class BasePayloadSlicer implements PayloadSlicer {
    }
 
    protected Payload doSlice(File content, long offset, long length) {
-      return new 
InputStreamSupplierPayload(ByteStreams.slice(Files.newInputStreamSupplier(content),
 offset, length));
+      return doSlice(Files.newInputStreamSupplier(content), offset, length);
    }
 
    protected Payload doSlice(InputStream content, long offset, long length) {
@@ -83,6 +86,10 @@ public class BasePayloadSlicer implements PayloadSlicer {
       return new InputStreamPayload(ByteStreams.limit(content, length));
    }
 
+   protected Payload doSlice(InputSupplier<? extends InputStream> content, 
long offset, long length) {
+      return new InputStreamSupplierPayload(ByteStreams.slice(content, offset, 
length));
+   }
+
    protected Payload doSlice(byte[] content, long offset, long length) {
       Payload returnVal;
       checkArgument(offset <= Integer.MAX_VALUE, "offset is too big for an 
array");

Reply via email to