throws StorageException, IOException { ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer, offset, length); this.append(inputStream, length, accessCondition, options, opContext); inputStream.close();
throws StorageException, IOException { ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer, offset, length); this.append(inputStream, length, accessCondition, options, opContext); inputStream.close();
/** * Appends a stream to an append blob. This API should be used strictly in a single writer scenario because the API * internally uses the append-offset conditional header to avoid duplicate blocks which does not work in a multiple * writer scenario. * <p> * If you are doing writes in a single writer scenario, please look at * {@link BlobRequestOptions#setAbsorbConditionalErrorsOnRetry(Boolean)} and see if setting this flag * to <code>true</code> is acceptable for you. * * @param sourceStream * A {@link InputStream} object providing the blob content to append. * @param length * A <code>long</code> which represents the length, in bytes, of the stream data, or -1 if unknown. * @throws StorageException * If a storage service error occurred. * @throws IOException * If an I/O exception occurred. */ @DoesServiceRequest public void append(InputStream sourceStream, final long length) throws StorageException, IOException { this.append(sourceStream, length, null /* accessCondition */, null /* options */, null /* operationContext */); }
long fileLength = file.length(); InputStream inputStream = new BufferedInputStream(new FileInputStream(file)); this.append(inputStream, fileLength, accessCondition, options, opContext); inputStream.close();
long fileLength = file.length(); InputStream inputStream = new BufferedInputStream(new FileInputStream(file)); this.append(inputStream, fileLength, accessCondition, options, opContext); inputStream.close();
/** * Appends a stream to an append blob. This API should be used strictly in a single writer scenario because the API * internally uses the append-offset conditional header to avoid duplicate blocks which does not work in a multiple * writer scenario. * <p> * If you are doing writes in a single writer scenario, please look at * {@link BlobRequestOptions#setAbsorbConditionalErrorsOnRetry(Boolean)} and see if setting this flag * to <code>true</code> is acceptable for you. * * @param sourceStream * A {@link InputStream} object providing the blob content to append. * @param length * A <code>long</code> which represents the length, in bytes, of the stream data, or -1 if unknown. * @throws StorageException * If a storage service error occurred. * @throws IOException * If an I/O exception occurred. */ @DoesServiceRequest public void append(InputStream sourceStream, final long length) throws StorageException, IOException { this.append(sourceStream, length, null /* accessCondition */, null /* options */, null /* operationContext */); }
@Test public void testAppendBlobAppendFromStream() throws StorageException, IOException, URISyntaxException { // Every time append a buffer that is bigger than a single block. byte[] buffer = BlobTestHelper.getRandomBuffer(6 * 1024 * 1024); CloudAppendBlob blob = this.container.getAppendBlobReference("blob1"); blob.createOrReplace(); blob.append(new ByteArrayInputStream(buffer), buffer.length); blob.downloadAttributes(); assertEquals(6 * 1024 * 1024, blob.getProperties().getLength()); blob.append(new ByteArrayInputStream(buffer), buffer.length); blob.downloadAttributes(); assertEquals(12 * 1024 * 1024, blob.getProperties().getLength()); blob.append(new ByteArrayInputStream(buffer), buffer.length, null /* accessCondition */, null /* options */, null /* operationContext */); blob.downloadAttributes(); assertEquals(18 * 1024 * 1024, blob.getProperties().getLength()); }
@Test public void testAppendBlobAppendFromStreamWithLength() throws StorageException, IOException, URISyntaxException { // Every time append a buffer that is bigger than a single block. byte[] buffer = BlobTestHelper.getRandomBuffer(6 * 1024 * 1024); CloudAppendBlob blob = this.container.getAppendBlobReference("blob1"); blob.createOrReplace(); blob.append(new ByteArrayInputStream(buffer), 5 * 1024 * 1024); blob.downloadAttributes(); assertEquals(5 * 1024 * 1024, blob.getProperties().getLength()); blob.append(new ByteArrayInputStream(buffer), 5 * 1024 * 1024); blob.downloadAttributes(); assertEquals(10 * 1024 * 1024, blob.getProperties().getLength()); blob.append(new ByteArrayInputStream(buffer), 5 * 1024 * 1024, null /* accessCondition */, null /* options */, null /* operationContext */); blob.downloadAttributes(); assertEquals(15 * 1024 * 1024, blob.getProperties().getLength()); } }