Interface BlobAppendableUpload.AppendableUploadWriteableByteChannel
- All Superinterfaces:
AutoCloseable,Channel,Closeable,WritableByteChannel
- Enclosing interface:
- BlobAppendableUpload
WritableByteChannel returned from BlobAppendableUpload.open().
This interface allows writing bytes to an Appendable Upload, and provides methods to close this channel -- optionally finalizing the upload.
The write(ByteBuffer) method of this channel is non-blocking.
- Since:
- 2.51.0 This new api is in preview and is subject to breaking changes.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()This method is blockingvoidThis method is blockingvoidThis method is blockingvoidflush()This method is blockingintwrite(ByteBuffer src) This method is non-blocking
-
Method Details
-
write
This method is non-blockingConsume as many bytes as can fit in the underlying outbound queue. The size of the outbound queue is determined from
BlobAppendableUploadConfig.getFlushPolicy().getMaxPendingBytes(). If the outbound queue is full, and can not fit more bytes, this method will return 0.If your application needs to empty its ByteBuffer before progressing, use our helper method
StorageChannelUtils.blockingEmptyTo(ByteBuffer, WritableByteChannel)like so:try (AppendableUploadWriteableByteChannel channel = session.open()) { int written = StorageChannelUtils.blockingEmptyTo(byteBuffer, channel); }- Specified by:
writein interfaceWritableByteChannel- Parameters:
src- The buffer from which bytes are to be retrieved- Returns:
- The number of bytes written, possibly zero
- Throws:
ClosedChannelException- If this channel is closedIOException- If some other I/O error occurs
-
flush
This method is blockingBlock the invoking thread, waiting until the number of bytes written so far has been acknowledged by Google Cloud Storage.
- Throws:
IOException- if an error happens while waiting for the flush to completeInterruptedIOException- if the current thread is interrupted while waiting- Since:
- 2.56.0 This new api is in preview and is subject to breaking changes.
-
finalizeAndClose
This method is blockingFinalize the upload and close this instance to further
write(ByteBuffer)ing. This will close any underlying stream and release any releasable resources once out of scope.Once this method is called, and returns no more writes to the object will be allowed by GCS.
This method and
close()are mutually exclusive. If one of the other methods are called before this method, this method will be a no-op.- Throws:
IOException- Since:
- 2.51.0 This new api is in preview and is subject to breaking changes.
- See Also:
-
closeWithoutFinalizing
This method is blockingClose this instance to further
write(ByteBuffer)ing without finalizing the upload. This will close any underlying stream and release any releasable resources once out of scope.This method,
finalizeAndClose()andclose()are mutually exclusive. If one of the other methods are called before this method, this method will be a no-op.- Throws:
IOException- Since:
- 2.51.0 This new api is in preview and is subject to breaking changes.
- See Also:
-
close
This method is blockingClose this instance to further
write(ByteBuffer)ing.Whether the upload is finalized during this depends on the
BlobAppendableUploadConfig.getCloseAction()provided to create theBlobAppendableUpload. IfBlobAppendableUploadConfig.getCloseAction()==BlobAppendableUploadConfig.CloseAction.FINALIZE_WHEN_CLOSING,finalizeAndClose()will be called. IfBlobAppendableUploadConfig.getCloseAction()==BlobAppendableUploadConfig.CloseAction.CLOSE_WITHOUT_FINALIZING,closeWithoutFinalizing()will be called.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException- Since:
- 2.51.0 This new api is in preview and is subject to breaking changes.
- See Also:
-