Interface BlobAppendableUpload.AppendableUploadWriteableByteChannel (2.57.0)

public static interface BlobAppendableUpload.AppendableUploadWriteableByteChannel extends WritableByteChannel

The 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.

Implements

WritableByteChannel

Methods

close()

public abstract void close()

This method is blocking

Close this instance to further #write(ByteBuffer)ing.

Whether the upload is finalized during this depends on the BlobAppendableUploadConfig#getCloseAction() provided to create the BlobAppendableUpload. If BlobAppendableUploadConfig#getCloseAction()== CloseAction#FINALIZE_WHEN_CLOSING, #finalizeAndClose() will be called. If BlobAppendableUploadConfig#getCloseAction()== CloseAction#CLOSE_WITHOUT_FINALIZING, #closeWithoutFinalizing() will be called. See Also: Storage#blobAppendableUpload(BlobInfo, BlobAppendableUploadConfig, BlobWriteOption...), BlobAppendableUploadConfig#getCloseAction(), BlobAppendableUploadConfig#withCloseAction(CloseAction)

Exceptions
Type Description
IOException

closeWithoutFinalizing()

public abstract void closeWithoutFinalizing()

This method is blocking

Close 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, AppendableUploadWriteableByteChannel#finalizeAndClose() and AppendableUploadWriteableByteChannel#close() are mutually exclusive. If one of the other methods are called before this method, this method will be a no-op. See Also: BlobAppendableUploadConfig.CloseAction#CLOSE_WITHOUT_FINALIZING, Storage#blobAppendableUpload(BlobInfo, BlobAppendableUploadConfig, BlobWriteOption...), BlobAppendableUploadConfig#getCloseAction(), BlobAppendableUploadConfig#withCloseAction(CloseAction)

Exceptions
Type Description
IOException

finalizeAndClose()

public abstract void finalizeAndClose()

This method is blocking

Finalize 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. See Also: BlobAppendableUploadConfig.CloseAction#FINALIZE_WHEN_CLOSING, Storage#blobAppendableUpload(BlobInfo, BlobAppendableUploadConfig, BlobWriteOption...), BlobAppendableUploadConfig#getCloseAction(), BlobAppendableUploadConfig#withCloseAction(CloseAction)

Exceptions
Type Description
IOException

flush()

public abstract void flush()

This method is blocking

Block the invoking thread, waiting until the number of bytes written so far has been acknowledged by Google Cloud Storage.

Exceptions
Type Description
IOException

if an error happens while waiting for the flush to complete

write(ByteBuffer src)

public abstract int write(ByteBuffer src)

This method is non-blocking

Consume 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);
 }
 
Parameter
Name Description
src ByteBuffer

The buffer from which bytes are to be retrieved

Returns
Type Description
int

The number of bytes written, possibly zero

Exceptions
Type Description
IOException

If this channel is closed