@Test
@Category({ DevFabricTests.class, DevStoreTests.class })
public void testBlockBlobDownloadRangeTest() throws URISyntaxException, StorageException, IOException {
byte[] buffer = BlobTestHelper.getRandomBuffer(2 * 1024);
CloudBlockBlob blob = this.container.getBlockBlobReference("blob1");
ByteArrayInputStream wholeBlob = new ByteArrayInputStream(buffer);
blob.upload(wholeBlob, -1);
ByteArrayOutputStream blobStream = new ByteArrayOutputStream();
try {
blob.downloadRange(0, new Long(0), blobStream, null, null, null);
}
catch (IndexOutOfBoundsException ex) {
}
blob.downloadRange(0, new Long(1024), blobStream);
assertEquals(blobStream.size(), 1024);
BlobTestHelper.assertStreamsAreEqualAtIndex(new ByteArrayInputStream(blobStream.toByteArray()), wholeBlob, 0,
0, 1024, 2 * 1024);
CloudBlockBlob blob2 = this.container.getBlockBlobReference("blob1");
try {
blob.downloadRange(1024, new Long(0), blobStream, null, null, null);
}
catch (IndexOutOfBoundsException ex) {
}
ByteArrayOutputStream blobStream2 = new ByteArrayOutputStream();
blob2.downloadRange(1024, new Long(1024), blobStream2);
BlobTestHelper.assertStreamsAreEqualAtIndex(new ByteArrayInputStream(blobStream2.toByteArray()), wholeBlob,
1024, 1024, 1024, 2 * 1024);
blob2.downloadAttributes();
BlobTestHelper.assertAreEqual(blob, blob2);
}