@Override public Void call() { try { byte[] buffer = BlobTestHelper.getRandomBuffer(this.length*this.writes); for (int i = 0; i < writes; i ++) { this.blobOutputStream.write(buffer, i*this.length, this.length); if ((i+1)%flushPeriod == 0) { this.blobOutputStream.flush(); } } } catch (Exception e) { fail("flushHelper should succeed."); } return null; } }
return new BlobOutputStream(this, accessCondition, options, opContext);
/** * Flushes this output stream and forces any buffered output bytes to be written out. If any data remains in the * buffer it is committed to the service. * * @throws IOException * If an I/O error occurs. */ @Override @DoesServiceRequest public void flush() throws IOException { this.checkStreamState(); this.dispatchWrite(); // Waits for all submitted tasks to complete Set<Future<Void>> requests = new HashSet<Future<Void>>(this.futureSet); for (Future<Void> request : requests) { // wait for the future to complete try { request.get(); } catch (Exception e) { throw Utility.initIOException(e); } // If that task threw an error, fail fast this.checkStreamState(); } }
this.checkStreamState(); this.flush(); this.commit();
this.waitForTaskToComplete(); this.clearCompletedFutures(); final String blockID = this.getCurrentBlockId();
do { try { blob.openOutputStream().close(); leaseId = blob.acquireLease(INTERVAL, null); log.info("Acquired lease {}", leaseId);
BlobOutputStream blobOutputStream = blockBlob.openOutputStream(null, options, null); for (int i = 0; i < writes; i ++) { blobOutputStream.write(buffer, i*length, length); blobOutputStream.flush(); blocks = blockBlob.downloadBlockList(BlockListingFilter.UNCOMMITTED, null, null, null); assertEquals((int)Math.ceil((i+1)/flushPeriod), blocks.size()); blobOutputStream.close(); blocks = blockBlob.downloadBlockList(BlockListingFilter.COMMITTED, null, null, null);
/** * Writes <code>b.length</code> bytes from the specified byte array to this output stream. * * @param data * A <code>byte</code> array which represents the data to write. * * @throws IOException * If an I/O error occurs. In particular, an IOException may be thrown if the output stream has been * closed. */ @Override @DoesServiceRequest public void write(final byte[] data) throws IOException { this.write(data, 0, data.length); }
@Override public Void call() { try { stream.flush(); } catch (IOException e) { fail("The flush should succeed."); } return null; } }
do { try { blob.openOutputStream().close(); leaseId = blob.acquireLease(INTERVAL, null); log.info("Acquired lease {}", leaseId);
private void smallPutThresholdHelper(int length, int writes, BlobRequestOptions options) throws URISyntaxException, StorageException, IOException { byte[] buffer = BlobTestHelper.getRandomBuffer(length*writes); String blobName = BlobTestHelper.generateRandomBlobNameWithPrefix("concurrency"); CloudBlockBlob blockBlob = this.container.getBlockBlobReference(blobName); blockBlob.setStreamWriteSizeInBytes(length); BlobOutputStream blobOutputStream = blockBlob.openOutputStream(null, options, null); for (int i = 0; i < writes; i ++) { blobOutputStream.write(buffer, i*length, length); } blobOutputStream.flush(); ArrayList<BlockEntry> blocks = blockBlob.downloadBlockList(BlockListingFilter.UNCOMMITTED, null, null, null); assertEquals(writes, blocks.size()); blobOutputStream.close(); blocks = blockBlob.downloadBlockList(BlockListingFilter.COMMITTED, null, null, null); assertEquals(writes, blocks.size()); byte[] outBuffer = new byte[writes*length]; blockBlob.downloadToByteArray(outBuffer, 0); for (int i = 0; i < length*writes; i ++) { assertEquals(buffer[i], outBuffer[i]); } }
/** * Writes the specified byte to this output stream. The general contract for write is that one byte is written to * the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits * of b are ignored. * * @param byteVal * An <code>int</code> which represents the bye value to write. * * @throws IOException * If an I/O error occurs. In particular, an IOException may be thrown if the output stream has been * closed. */ @Override @DoesServiceRequest public void write(final int byteVal) throws IOException { this.write(new byte[] { (byte) (byteVal & 0xFF) }); }
private synchronized void writeInternal(final byte[] data, int offset, int length) throws IOException { while (length > 0) { this.checkStreamState(); this.dispatchWrite();
@Test public void outOfBandSingleFile_rename() throws Exception { //NOTE: manual use of CloubBlockBlob targets working directory explicitly. // WASB driver methods prepend working directory implicitly. String workingDir = "user/" + UserGroupInformation.getCurrentUser().getShortUserName() + "/"; CloudBlockBlob blob = testAccount.getBlobReference(workingDir + "testFolder5/a/input/file"); BlobOutputStream s = blob.openOutputStream(); s.close(); Path srcFilePath = new Path("testFolder5/a/input/file"); assertTrue(fs.exists(srcFilePath)); Path destFilePath = new Path("testFolder5/file2"); fs.rename(srcFilePath, destFilePath); }
@Test public void testAppendBlockOperations() throws Exception { CloudBlobContainer container = getTestAccount().getRealContainer(); OperationContext context = new OperationContext(); context.getResponseReceivedEventHandler().addListener( new ResponseReceivedEventHandler()); context.getSendingRequestEventHandler().addListener( new SendingRequestEventHandler()); CloudAppendBlob appendBlob = container.getAppendBlobReference( "testAppendBlockOperations"); assertNull(lastOperationTypeSent); assertNull(lastOperationTypeReceived); assertEquals(0, lastContentLengthReceived); try ( BlobOutputStream output = appendBlob.openWriteNew(null, null, context); ) { assertEquals(BlobOperationDescriptor.OperationType.CreateBlob, lastOperationTypeReceived); assertEquals(0, lastContentLengthReceived); String message = "this is a test"; output.write(message.getBytes("UTF-8")); output.flush(); assertEquals(BlobOperationDescriptor.OperationType.AppendBlock, lastOperationTypeSent); assertEquals(BlobOperationDescriptor.OperationType.AppendBlock, lastOperationTypeReceived); assertEquals(message.length(), lastContentLengthReceived); } }
/** * Writes <code>b.length</code> bytes from the specified byte array to this output stream. * <p> * If you are using {@link CloudAppendBlob} and are certain of 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 data * A <code>byte</code> array which represents the data to write. * * @throws IOException * If an I/O error occurs. In particular, an IOException may be thrown if the output stream has been * closed. */ @Override @DoesServiceRequest public void write(final byte[] data) throws IOException { this.write(data, 0, data.length); }
return new BlobOutputStream(this, length, accessCondition, options, opContext);