Package com.google.cloud
Class BaseWriteChannel<ServiceOptionsT extends ServiceOptions<?,ServiceOptionsT>,EntityT extends Serializable>
- java.lang.Object
-
- com.google.cloud.BaseWriteChannel<ServiceOptionsT,EntityT>
-
- Type Parameters:
ServiceOptionsT
- the service options used by the channel to issue RPC requestsEntityT
- the entity this channel writes data to. Possibly with additional configuration
- All Implemented Interfaces:
Restorable<WriteChannel>
,WriteChannel
,Closeable
,AutoCloseable
,Channel
,WritableByteChannel
public abstract class BaseWriteChannel<ServiceOptionsT extends ServiceOptions<?,ServiceOptionsT>,EntityT extends Serializable> extends Object implements WriteChannel
Base implementation for aWriteChannel
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
BaseWriteChannel.BaseState<ServiceOptionsT extends ServiceOptions<?,ServiceOptionsT>,EntityT extends Serializable>
-
Constructor Summary
Constructors Modifier Constructor Description protected
BaseWriteChannel(ServiceOptionsT options, EntityT entity, String uploadId)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description RestorableState<WriteChannel>
capture()
Captures the write channel state so that it can be saved and restored afterwards.void
close()
protected abstract void
flushBuffer(int length, boolean last)
protected byte[]
getBuffer()
protected int
getChunkSize()
protected int
getDefaultChunkSize()
protected EntityT
getEntity()
protected int
getLimit()
protected int
getMinChunkSize()
protected ServiceOptionsT
getOptions()
protected long
getPosition()
protected String
getUploadId()
boolean
isOpen()
protected void
restore(BaseWriteChannel.BaseState state)
Restores the state of the current write channel given aBaseWriteChannel.BaseState
object.void
setChunkSize(int chunkSize)
Sets the minimum size that will be written by a single RPC.protected abstract BaseWriteChannel.BaseState.Builder<ServiceOptionsT,EntityT>
stateBuilder()
Creates aBaseWriteChannel.BaseState.Builder
for the current write channel.int
write(ByteBuffer byteBuffer)
-
-
-
Constructor Detail
-
BaseWriteChannel
@InternalApi("This class should only be extended within google-cloud-java") protected BaseWriteChannel(ServiceOptionsT options, EntityT entity, String uploadId)
-
-
Method Detail
-
getMinChunkSize
protected int getMinChunkSize()
-
getDefaultChunkSize
protected int getDefaultChunkSize()
-
flushBuffer
protected abstract void flushBuffer(int length, boolean last)
- Parameters:
length
- the number of bytes to write fromgetBuffer()
last
- iftrue
the resumable session is closed
-
getOptions
protected ServiceOptionsT getOptions()
-
getEntity
protected EntityT getEntity()
-
getUploadId
protected String getUploadId()
-
getPosition
protected long getPosition()
-
getBuffer
protected byte[] getBuffer()
-
getLimit
protected int getLimit()
-
getChunkSize
protected int getChunkSize()
-
setChunkSize
public final void setChunkSize(int chunkSize)
Description copied from interface:WriteChannel
Sets the minimum size that will be written by a single RPC. Written data will be buffered and only flushed upon reaching this size or closing the channel.- Specified by:
setChunkSize
in interfaceWriteChannel
-
write
public final int write(ByteBuffer byteBuffer) throws IOException
- Specified by:
write
in interfaceWritableByteChannel
- Throws:
IOException
-
close
public final void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceChannel
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
stateBuilder
protected abstract BaseWriteChannel.BaseState.Builder<ServiceOptionsT,EntityT> stateBuilder()
Creates aBaseWriteChannel.BaseState.Builder
for the current write channel.
-
capture
public RestorableState<WriteChannel> capture()
Description copied from interface:WriteChannel
Captures the write channel state so that it can be saved and restored afterwards. The originalWriteChannel
and the restored one should not both be used. Closing one channel causes the other channel to close; subsequent writes will fail.- Specified by:
capture
in interfaceRestorable<ServiceOptionsT extends ServiceOptions<?,ServiceOptionsT>>
- Specified by:
capture
in interfaceWriteChannel
- Returns:
- a
RestorableState
object that contains the write channel state and can restore it afterwards.
-
restore
protected void restore(BaseWriteChannel.BaseState state)
Restores the state of the current write channel given aBaseWriteChannel.BaseState
object.
-
-