public abstract class AbstractGoogleAsyncWriteChannel<T extends com.google.api.client.googleapis.services.AbstractGoogleClientRequest<S>,S>
extends java.lang.Object
implements java.nio.channels.WritableByteChannel
Modifier and Type | Field and Description |
---|---|
static int |
GCS_UPLOAD_GRANULARITY |
static int |
UPLOAD_CHUNK_SIZE_DEFAULT |
Constructor and Description |
---|
AbstractGoogleAsyncWriteChannel(java.util.concurrent.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(java.io.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 |
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(java.lang.String contentType)
Sets the contentType.
|
void |
setDirectUploadEnabled(boolean enableDirectUpload)
Enables or disables direct uploads.
|
void |
setUploadBufferSize(int bufferSize)
Deprecated.
|
void |
setUploadChunkSize(int chunkSize)
Sets size of upload buffer used.
|
int |
write(java.nio.ByteBuffer buffer)
Writes contents of the given buffer to this channel.
|
public static final int GCS_UPLOAD_GRANULARITY
public static final int UPLOAD_CHUNK_SIZE_DEFAULT
public AbstractGoogleAsyncWriteChannel(java.util.concurrent.ExecutorService threadPool, AsyncWriteChannelOptions options)
public void setClientRequestHelper(ClientRequestHelper<S> helper)
public abstract T createRequest(com.google.api.client.http.InputStreamContent inputStream) throws java.io.IOException
java.io.IOException
public void handleResponse(S response) throws java.io.IOException
This method is invoked after the upload has completed on the same thread that invokes close().
response
- The API response object.java.io.IOException
public S createResponseFromException(java.io.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.@Deprecated public void setUploadBufferSize(int bufferSize)
public void setUploadChunkSize(int chunkSize)
public void setDirectUploadEnabled(boolean enableDirectUpload)
MediaHttpUploader.setDirectUploadEnabled(boolean)
public boolean isDirectUploadEnabled()
public int write(java.nio.ByteBuffer buffer) throws java.io.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 java.nio.channels.WritableByteChannel
buffer
- buffer to writejava.io.IOException
- on IO errorpublic boolean isOpen()
isOpen
in interface java.nio.channels.Channel
public void close() throws java.io.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 java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface java.nio.channels.Channel
java.io.IOException
- on IO errorpublic void initialize() throws java.io.IOException
java.io.IOException
protected void setContentType(java.lang.String contentType)
initialize()
for any effect.Copyright © 2019. All rights reserved.