From 85e976e7f5b2fdc863f654a3761415501ce60c72 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Fri, 10 May 2013 15:39:48 -0700 Subject: [PATCH] JCLOUDS-27: Allow repeatable Payload with InputSupplier input This allows HTTP retries to work. Also remove duplicated calls to ByteStreams.slice. --- .../org/jclouds/io/internal/BasePayloadSlicer.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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 54a91b0400..7b30d22654 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) 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 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");