You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jclouds.apache.org by Andrew Gaul <ga...@apache.org> on 2013/05/11 00:50:18 UTC

Re: git commit: JCLOUDS-27: Allow repeatable Payload with InputSupplier input

Sorry for the duplicate commit; I am still trying to wrap my head around
the workflow.  I had to cherry-pick from my local branch into master
then push to remote master to succeed.  Thanks Adrian for the
suggestion!

On Fri, May 10, 2013 at 10:43:31PM +0000, gaul@apache.org wrote:
> Updated Branches:
>   refs/heads/slice-supplier [created] 6b48babcf
> 
> 
> 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/6b48babc
> Tree: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/tree/6b48babc
> Diff: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/diff/6b48babc
> 
> Branch: refs/heads/slice-supplier
> Commit: 6b48babcf07b0a6930015956272eaf5f8a9b6772
> Parents: ffc05ee
> Author: Andrew Gaul <ga...@maginatics.com>
> Authored: Fri May 10 15:39:48 2013 -0700
> Committer: Andrew Gaul <ga...@maginatics.com>
> Committed: Fri May 10 15:39:48 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/6b48babc/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 5af5066..a7f814c 100644
> --- a/core/src/main/java/org/jclouds/io/internal/BasePayloadSlicer.java
> +++ b/core/src/main/java/org/jclouds/io/internal/BasePayloadSlicer.java
> @@ -36,6 +36,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;
>  
>  /**
>   * 
> @@ -58,14 +59,16 @@ public class BasePayloadSlicer implements PayloadSlicer {
>           returnVal = doSlice((String) 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) {
> @@ -73,7 +76,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) {
> @@ -85,6 +88,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");

-- 
Andrew Gaul
http://gaul.org/