mirror of
https://github.com/apache/jclouds.git
synced 2025-02-07 10:39:03 +00:00
JCLOUDS-27: Allow repeatable Payload with InputSupplier input
This allows HTTP retries to work. Also remove duplicated calls to ByteStreams.slice.
This commit is contained in:
parent
0253e9eb86
commit
85e976e7f5
@ -34,6 +34,7 @@ import org.jclouds.io.payloads.InputStreamSupplierPayload;
|
|||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import com.google.common.io.Files;
|
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);
|
returnVal = doSlice((byte[]) input.getRawContent(), offset, length);
|
||||||
} else if (input.getRawContent() instanceof byte[]) {
|
} else if (input.getRawContent() instanceof byte[]) {
|
||||||
returnVal = doSlice((byte[]) input.getRawContent(), offset, length);
|
returnVal = doSlice((byte[]) input.getRawContent(), offset, length);
|
||||||
|
} else if (input.getRawContent() instanceof InputStream) {
|
||||||
|
returnVal = doSlice((InputStream) input.getRawContent(), offset, length);
|
||||||
} else {
|
} else {
|
||||||
returnVal = doSlice(input.getInput(), offset, length);
|
returnVal = doSlice(input, offset, length);
|
||||||
}
|
}
|
||||||
return copyMetadataAndSetLength(input, returnVal, length);
|
return copyMetadataAndSetLength(input, returnVal, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Payload doSlice(Payload content, long offset, long 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) {
|
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) {
|
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) {
|
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));
|
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) {
|
protected Payload doSlice(byte[] content, long offset, long length) {
|
||||||
Payload returnVal;
|
Payload returnVal;
|
||||||
checkArgument(offset <= Integer.MAX_VALUE, "offset is too big for an array");
|
checkArgument(offset <= Integer.MAX_VALUE, "offset is too big for an array");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user