/** * Downloads a range of bytes from the file to the given byte buffer. * * @param buffer * A <code>byte</code> array which represents the buffer to which the file bytes are downloaded. * @param bufferOffset * An <code>int</code> which represents the byte offset to use as the starting point for the target. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public final int downloadToByteArray(final byte[] buffer, final int bufferOffset) throws StorageException { return this .downloadToByteArray(buffer, bufferOffset, null /* accessCondition */, null /* options */, null /* opContext */); }
/** * Downloads a range of bytes from the file to the given byte buffer. * * @param buffer * A <code>byte</code> array which represents the buffer to which the file bytes are downloaded. * @param bufferOffset * An <code>int</code> which represents the byte offset to use as the starting point for the target. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public final int downloadToByteArray(final byte[] buffer, final int bufferOffset) throws StorageException { return this .downloadToByteArray(buffer, bufferOffset, null /* accessCondition */, null /* options */, null /* opContext */); }
protected static void doDownloadTest(CloudFile file, int fileSize, int bufferSize, int bufferOffset) throws StorageException, IOException, URISyntaxException { final Random randGenerator = new Random(); final byte[] buffer = new byte[fileSize]; randGenerator.nextBytes(buffer); byte[] resultBuffer = new byte[bufferSize]; FileRequestOptions options = new FileRequestOptions(); file.upload(new ByteArrayInputStream(buffer), buffer.length); file.downloadToByteArray(resultBuffer, bufferOffset, null, options, null); for (int i = 0; i < file.getProperties().getLength(); i++) { Assert.assertEquals(buffer[i], resultBuffer[bufferOffset + i]); } if (bufferOffset + fileSize < bufferSize) { for (int k = bufferOffset + fileSize; k < bufferSize; k++) { Assert.assertEquals(0, resultBuffer[k]); } } }
file.downloadToByteArray(resultBuffer, 1024); Assert.fail();
private void doUploadFromByteArrayTest(CloudFile file, int bufferSize, int bufferOffset, int count) throws Exception { byte[] buffer = FileTestHelper.getRandomBuffer(bufferSize); byte[] downloadedBuffer = new byte[bufferSize]; file.uploadFromByteArray(buffer, bufferOffset, count); file.downloadToByteArray(downloadedBuffer, 0); int i = 0; for (; i < count; i++) { assertEquals(buffer[i + bufferOffset], downloadedBuffer[i]); } for (; i < downloadedBuffer.length; i++) { assertEquals(0, downloadedBuffer[i]); } }
fileRef.downloadToByteArray(result, 0);
fileRef.downloadToByteArray(result, 0);
/** * Test clearing file ranges. * * @throws URISyntaxException * @throws StorageException */ @Test public void testCloudFileClearRange() throws URISyntaxException, StorageException, IOException { int fileLengthToUse = 8 * 512; byte[] buffer = FileTestHelper.getRandomBuffer(8 * 512); String fileName = FileTestHelper.generateRandomFileName(); final CloudFile fileRef = this.share.getRootDirectoryReference().getFileReference(fileName); fileRef.create(fileLengthToUse); // Upload one page (page 0) ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer); fileRef.uploadRange(inputStream, 0, fileLengthToUse); fileRef.clearRange(3 * 512, 2 * 512); byte[] result = new byte[fileLengthToUse]; fileRef.downloadToByteArray(result, 0); int i = 0; for (; i < 3 * 512; i++) { assertEquals(buffer[i], result[i]); } for (; i < 5 * 512; i++) { assertEquals(0, result[i]); } for (; i < 8 * 512; i++) { assertEquals(buffer[i], result[i]); } }
fileRef.uploadProperties(null, options, null); fileRef.download(new ByteArrayOutputStream(), null, options, null); fileRef.downloadToByteArray(new byte[4096], 0);