Class AbstractGoogleAsyncWriteChannel<T>
- Type Parameters:
T- The type of the result of the completed upload operation.
- All Implemented Interfaces:
Closeable,AutoCloseable,Channel,WritableByteChannel
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AsyncWriteChannelOptionsprotected final com.google.common.hash.Hasherprotected static final com.google.common.flogger.GoogleLoggerprotected final ExecutorService -
Constructor Summary
ConstructorsConstructorDescriptionAbstractGoogleAsyncWriteChannel(ExecutorService threadPool, AsyncWriteChannelOptions channelOptions) Construct a new channel using the given ExecutorService to run background uploads. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this channel.protected abstract StringvoidhandleResponse(T response) Handle the API response.voidInitialize this channel object for writing.booleanReturns true if direct media uploads are enabled.booleanisOpen()Tells whether this channel is open.abstract voidstartUpload(InputStream pipeSource) Create a new thread which handles the upload.intwrite(ByteBuffer buffer) Writes contents of the given buffer to this channel.
-
Field Details
-
logger
protected static final com.google.common.flogger.GoogleLogger logger -
threadPool
-
channelOptions
-
uploadOperation
-
cumulativeCrc32cHasher
protected final com.google.common.hash.Hasher cumulativeCrc32cHasher
-
-
Constructor Details
-
AbstractGoogleAsyncWriteChannel
public AbstractGoogleAsyncWriteChannel(ExecutorService threadPool, AsyncWriteChannelOptions channelOptions) Construct a new channel using the given ExecutorService to run background uploads.
-
-
Method Details
-
handleResponse
Handle the API response.This method is invoked after the upload has completed on the same thread that invokes close(). It can throw IOException if checksum matching is enabled and mismatched.
- Parameters:
response- The API response object.- Throws:
IOException
-
isDirectUploadEnabled
public boolean isDirectUploadEnabled()Returns true if direct media uploads are enabled. -
write
Writes contents of the given buffer to this channel.Note: The data that one writes gets written to a pipe which must not block if the pipe has sufficient buffer space. A success code returned from this method does not mean that the specific data was successfully written to the underlying storage. It simply means that there is no error at present. The data upload may encounter an error on a separate thread. Such error is not ignored; it shows up as an exception during a subsequent call to write() or close(). The only way to be sure of successful upload is when the close() method returns successfully.
- Specified by:
writein interfaceWritableByteChannel- Parameters:
buffer- buffer to write- Throws:
IOException- on IO error
-
isOpen
public boolean isOpen()Tells whether this channel is open. -
close
Closes this channel.Note: The method returns only after all data has been successfully written to GCS or if there is a non-retry-able error.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException- on IO error
-
initialize
Initialize this channel object for writing.- Throws:
IOException
-
startUpload
Create a new thread which handles the upload.- Throws:
IOException
-
getResourceString
-