T
- The type of the result of the completed upload operation.public abstract class BaseAbstractGoogleAsyncWriteChannel<T> extends Object implements WritableByteChannel
Modifier and Type | Field and Description |
---|---|
protected String |
contentType |
static int |
GCS_UPLOAD_GRANULARITY |
protected static com.google.common.flogger.GoogleLogger |
logger |
protected ExecutorService |
threadPool |
static int |
UPLOAD_CHUNK_SIZE_DEFAULT |
static int |
UPLOAD_PIPE_BUFFER_SIZE_DEFAULT
Deprecated.
|
protected int |
uploadChunkSize |
protected Future<T> |
uploadOperation |
Constructor and Description |
---|
BaseAbstractGoogleAsyncWriteChannel(ExecutorService threadPool,
AsyncWriteChannelOptions options)
Construct a new channel using the given ExecutorService to run background uploads.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this channel.
|
T |
createResponseFromException(IOException ioe)
Derived classes may optionally intercept an IOException thrown from the execute() method of a
prepared request that came from
#createRequest , and return a reconstituted "response"
object if the IOException can be handled as a success; for example, if the caller already has
an identifier for an object, and the response is used solely for obtaining the same identifier,
and the IOException is a handled "409 Already Exists" type of exception, then the derived class
may override this method to return the expected "identifier" response. |
protected abstract String |
getResourceString() |
void |
handleResponse(T response)
Handle the API response.
|
void |
initialize()
Initialize this channel object for writing.
|
boolean |
isDirectUploadEnabled()
Returns true if direct media uploads are enabled.
|
boolean |
isOpen()
Tells whether this channel is open.
|
protected void |
setContentType(String contentType)
Sets the contentType.
|
void |
setDirectUploadEnabled(boolean enableDirectUpload)
Enables or disables direct uploads.
|
void |
setUploadBufferSize(int bufferSize)
Deprecated.
|
abstract void |
setUploadChunkSize(int chunkSize)
Sets size of upload buffer used.
|
abstract void |
startUpload(PipedInputStream pipeSource)
Create a new thread which handles the upload.
|
int |
write(ByteBuffer buffer)
Writes contents of the given buffer to this channel.
|
protected static final com.google.common.flogger.GoogleLogger logger
public static final int GCS_UPLOAD_GRANULARITY
public static final int UPLOAD_CHUNK_SIZE_DEFAULT
@Deprecated public static final int UPLOAD_PIPE_BUFFER_SIZE_DEFAULT
protected String contentType
protected final ExecutorService threadPool
protected int uploadChunkSize
public BaseAbstractGoogleAsyncWriteChannel(ExecutorService threadPool, AsyncWriteChannelOptions options)
public abstract void startUpload(PipedInputStream pipeSource) throws IOException
IOException
public void handleResponse(T response) throws IOException
This method is invoked after the upload has completed on the same thread that invokes close().
response
- The API response object.IOException
public T createResponseFromException(IOException ioe)
#createRequest
, and return a reconstituted "response"
object if the IOException can be handled as a success; for example, if the caller already has
an identifier for an object, and the response is used solely for obtaining the same identifier,
and the IOException is a handled "409 Already Exists" type of exception, then the derived class
may override this method to return the expected "identifier" response. Return null to let the
exception propagate through correctly.@Deprecated public void setUploadBufferSize(int bufferSize)
public abstract void setUploadChunkSize(int chunkSize)
public void setDirectUploadEnabled(boolean enableDirectUpload)
MediaHttpUploader.setDirectUploadEnabled(boolean)
public boolean isDirectUploadEnabled()
public int write(ByteBuffer buffer) throws IOException
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.
write
in interface WritableByteChannel
buffer
- buffer to writeIOException
- on IO errorpublic boolean isOpen()
public void close() throws IOException
Note: The method returns only after all data has been successfully written to GCS or if there is a non-retry-able error.
close
in interface Closeable
close
in interface AutoCloseable
close
in interface Channel
IOException
- on IO errorpublic void initialize() throws IOException
IOException
protected void setContentType(String contentType)
initialize()
for any effect.protected abstract String getResourceString()
Copyright © 2020. All rights reserved.