mirror of https://github.com/apache/jclouds.git
JCLOUDS-410 note that ByteArrayPayload needs to handle offsets.
This commit is contained in:
parent
9105ae55fa
commit
5511bad765
|
@ -34,11 +34,9 @@ import javax.inject.Singleton;
|
||||||
import org.jclouds.io.ByteStreams2;
|
import org.jclouds.io.ByteStreams2;
|
||||||
import org.jclouds.io.ContentMetadata;
|
import org.jclouds.io.ContentMetadata;
|
||||||
import org.jclouds.io.Payload;
|
import org.jclouds.io.Payload;
|
||||||
|
import org.jclouds.io.Payloads;
|
||||||
import org.jclouds.io.PayloadSlicer;
|
import org.jclouds.io.PayloadSlicer;
|
||||||
import org.jclouds.io.payloads.BaseMutableContentMetadata;
|
import org.jclouds.io.payloads.BaseMutableContentMetadata;
|
||||||
import org.jclouds.io.payloads.ByteArrayPayload;
|
|
||||||
import org.jclouds.io.payloads.ByteSourcePayload;
|
|
||||||
import org.jclouds.io.payloads.InputStreamPayload;
|
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
|
@ -120,7 +118,7 @@ public class BasePayloadSlicer implements PayloadSlicer {
|
||||||
Payload payload = null;
|
Payload payload = null;
|
||||||
|
|
||||||
if (content.length > 0) {
|
if (content.length > 0) {
|
||||||
payload = new ByteArrayPayload(content);
|
payload = Payloads.newByteArrayPayload(content);
|
||||||
ContentMetadata cm = metaData.toBuilder().contentLength((long)content.length).contentMD5((HashCode) null).build();
|
ContentMetadata cm = metaData.toBuilder().contentLength((long)content.length).contentMD5((HashCode) null).build();
|
||||||
payload.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(cm));
|
payload.setContentMetadata(BaseMutableContentMetadata.fromContentMetadata(cm));
|
||||||
}
|
}
|
||||||
|
@ -173,19 +171,18 @@ public class BasePayloadSlicer implements PayloadSlicer {
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw Throwables.propagate(ioe);
|
throw Throwables.propagate(ioe);
|
||||||
}
|
}
|
||||||
return new InputStreamPayload(ByteStreams.limit(content, length));
|
return Payloads.newInputStreamPayload(ByteStreams.limit(content, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Payload doSlice(ByteSource content, long offset, long length) {
|
protected Payload doSlice(ByteSource content, long offset, long length) {
|
||||||
return new ByteSourcePayload(content.slice(offset, length));
|
return Payloads.newByteSourcePayload(content.slice(offset, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Payload doSlice(byte[] content, long offset, long length) {
|
protected Payload doSlice(byte[] content, long offset, long length) {
|
||||||
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");
|
||||||
checkArgument(length <= Integer.MAX_VALUE, "length is too big for an array");
|
checkArgument(length <= Integer.MAX_VALUE, "length is too big for an array");
|
||||||
returnVal = new ByteSourcePayload(ByteSource.wrap(content).slice(offset, length));
|
// TODO(adriancole): Make ByteArrayPayload carry offset, length as opposed to wrapping here.
|
||||||
return returnVal;
|
return Payloads.newByteSourcePayload(ByteSource.wrap(content).slice(offset, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Payload copyMetadataAndSetLength(Payload input, Payload returnVal, long length) {
|
protected Payload copyMetadataAndSetLength(Payload input, Payload returnVal, long length) {
|
||||||
|
|
|
@ -44,7 +44,7 @@ import org.jclouds.blobstore.ContainerNotFoundException;
|
||||||
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
|
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
|
||||||
import org.jclouds.http.HttpResponseException;
|
import org.jclouds.http.HttpResponseException;
|
||||||
import org.jclouds.http.options.GetOptions;
|
import org.jclouds.http.options.GetOptions;
|
||||||
import org.jclouds.io.payloads.ByteArrayPayload;
|
import org.jclouds.io.Payloads;
|
||||||
import org.jclouds.util.Strings2;
|
import org.jclouds.util.Strings2;
|
||||||
import org.jclouds.util.Throwables2;
|
import org.jclouds.util.Throwables2;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -358,9 +358,9 @@ public class AzureBlobClientLiveTest extends BaseBlobStoreIntegrationTest {
|
||||||
String blockIdB = BaseEncoding.base64().encode((blockBlob + "-" + B).getBytes());
|
String blockIdB = BaseEncoding.base64().encode((blockBlob + "-" + B).getBytes());
|
||||||
String blockIdC = BaseEncoding.base64().encode((blockBlob + "-" + C).getBytes());
|
String blockIdC = BaseEncoding.base64().encode((blockBlob + "-" + C).getBytes());
|
||||||
getApi().createContainer(blockContainer);
|
getApi().createContainer(blockContainer);
|
||||||
getApi().putBlock(blockContainer, blockBlob, blockIdA, new ByteArrayPayload(A.getBytes()));
|
getApi().putBlock(blockContainer, blockBlob, blockIdA, Payloads.newByteArrayPayload(A.getBytes()));
|
||||||
getApi().putBlock(blockContainer, blockBlob, blockIdB, new ByteArrayPayload(B.getBytes()));
|
getApi().putBlock(blockContainer, blockBlob, blockIdB, Payloads.newByteArrayPayload(B.getBytes()));
|
||||||
getApi().putBlock(blockContainer, blockBlob, blockIdC, new ByteArrayPayload(C.getBytes()));
|
getApi().putBlock(blockContainer, blockBlob, blockIdC, Payloads.newByteArrayPayload(C.getBytes()));
|
||||||
getApi().putBlockList(blockContainer, blockBlob, Arrays.asList(blockIdA, blockIdB, blockIdC));
|
getApi().putBlockList(blockContainer, blockBlob, Arrays.asList(blockIdA, blockIdB, blockIdC));
|
||||||
ListBlobBlocksResponse blocks = getApi().getBlockList(blockContainer, blockBlob);
|
ListBlobBlocksResponse blocks = getApi().getBlockList(blockContainer, blockBlob);
|
||||||
assertEquals(3, blocks.getBlocks().size());
|
assertEquals(3, blocks.getBlocks().size());
|
||||||
|
|
Loading…
Reference in New Issue