Interface BlobAppendableUpload.AppendableUploadWriteableByteChannel (2.71.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

close(@Nullable String expectedCrc32c)

public abstract void close(@Nullable String expectedCrc32c)

This method is blocking

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

This method behaves like #close(), but allows passing an optional expected CRC32c checksum. If expectedCrc32c is null, it behaves identically to #close(). See Also: Storage#blobAppendableUpload(BlobInfo, BlobAppendableUploadConfig, BlobWriteOption...), BlobAppendableUploadConfig#getCloseAction(), BlobAppendableUploadConfig#withCloseAction(CloseAction)

Parameter
Name Description
expectedCrc32c @org.checkerframework.checker.nullness.qual.Nullable java.lang.String

A Base64 encoded string representing the expected CRC32c value for the entire object. If provided, the server will validate the final object's CRC32c against this value. If there's a mismatch, the server will return an error (such as InvalidArgument), and this method will throw a StorageException or equivalent exception, failing the upload. May be null.

Exceptions
Type Description
IOException

if the stream was not configured with CloseAction#FINALIZE_WHEN_CLOSING and expectedCrc32c is not null.

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

finalizeAndClose(@Nullable String expectedCrc32c)

public abstract void finalizeAndClose(@Nullable String expectedCrc32c)

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)

Parameter
Name Description
expectedCrc32c @org.checkerframework.checker.nullness.qual.Nullable java.lang.String

A Base64 encoded string representing the expected CRC32c value for the entire object. If provided, the server will validate the final object's CRC32c against this value. If there's a mismatch, the server will return an error (such as InvalidArgument), and this method will throw a StorageException or equivalent exception, failing the upload.

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