T
- API request type that we will be uploading.S
- API response type that will be the result of the upload.public abstract class AbstractGoogleAsyncWriteChannel<T extends com.google.api.client.googleapis.services.AbstractGoogleClientRequest<S>,S> extends Object implements WritableByteChannel
As per WriteableByteChannel semantics, only a single writer may be in write() at a time. Close(), initalize(), etc have no thread-safety guarantees and their use should be coordinated by callers to be not called concurrent to any write operation.
Modifier and Type | Field and Description |
---|---|
static int |
GCS_UPLOAD_GRANULARITY |
static int |
UPLOAD_CHUNK_SIZE_DEFAULT |
static int |
UPLOAD_PIPE_BUFFER_SIZE_DEFAULT |
Constructor and Description |
---|
AbstractGoogleAsyncWriteChannel(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.
|
abstract T |
createRequest(com.google.api.client.http.InputStreamContent inputStream)
Create an API request to upload the given InputStreamContent.
|
S |
createResponseFromException(IOException ioe)
Derived classes may optionally intercept an IOException thrown from the execute() method of
a prepared request that came from
createRequest(com.google.api.client.http.InputStreamContent) , 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. |
void |
enableFileSizeLimit250Gb(boolean enableLimit)
Enables or disables hard limit of 250GB on size of uploaded files.
|
void |
handleResponse(S 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.
|
void |
setClientRequestHelper(ClientRequestHelper<S> helper)
Sets the ClientRequestHelper to be used instead of calling final methods in client requests.
|
protected void |
setContentType(String contentType)
Sets the contentType.
|
void |
setDirectUploadEnabled(boolean enableDirectUpload)
Enables or disables direct uploads.
|
void |
setUploadBufferSize(int bufferSize)
Sets size of upload buffer used.
|
int |
write(ByteBuffer buffer)
Writes contents of the given buffer to this channel.
|
public static final int UPLOAD_PIPE_BUFFER_SIZE_DEFAULT
public static final int GCS_UPLOAD_GRANULARITY
public static final int UPLOAD_CHUNK_SIZE_DEFAULT
public AbstractGoogleAsyncWriteChannel(ExecutorService threadPool, AsyncWriteChannelOptions options)
threadPool
- options
- public void setClientRequestHelper(ClientRequestHelper<S> helper)
public abstract T createRequest(com.google.api.client.http.InputStreamContent inputStream) throws IOException
inputStream
- IOException
public void handleResponse(S 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 S createResponseFromException(IOException ioe)
createRequest(com.google.api.client.http.InputStreamContent)
, 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.public void setUploadBufferSize(int bufferSize)
public void enableFileSizeLimit250Gb(boolean enableLimit)
public void setDirectUploadEnabled(boolean enableDirectUpload)
MediaHttpUploader.setDirectUploadEnabled(boolean)
public boolean isDirectUploadEnabled()
public int write(ByteBuffer buffer) throws IOException
write
in interface WritableByteChannel
buffer
- buffer to writeIOException
- on IO errorpublic boolean isOpen()
public void close() throws IOException
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)
Copyright © 2018. All rights reserved.