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 classBaseWriteChannel.BaseState<ServiceOptionsT extends ServiceOptions<?,ServiceOptionsT>,EntityT extends Serializable>
-
Constructor Summary
Constructors Modifier Constructor Description protectedBaseWriteChannel(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.voidclose()protected abstract voidflushBuffer(int length, boolean last)protected byte[]getBuffer()protected intgetChunkSize()protected intgetDefaultChunkSize()protected EntityTgetEntity()protected intgetLimit()protected intgetMinChunkSize()protected ServiceOptionsTgetOptions()protected longgetPosition()protected StringgetUploadId()booleanisOpen()protected voidrestore(BaseWriteChannel.BaseState state)Restores the state of the current write channel given aBaseWriteChannel.BaseStateobject.voidsetChunkSize(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.Builderfor the current write channel.intwrite(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- iftruethe 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:WriteChannelSets 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:
setChunkSizein interfaceWriteChannel
-
write
public final int write(ByteBuffer byteBuffer) throws IOException
- Specified by:
writein interfaceWritableByteChannel- Throws:
IOException
-
close
public final void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException
-
stateBuilder
protected abstract BaseWriteChannel.BaseState.Builder<ServiceOptionsT,EntityT> stateBuilder()
Creates aBaseWriteChannel.BaseState.Builderfor the current write channel.
-
capture
public RestorableState<WriteChannel> capture()
Description copied from interface:WriteChannelCaptures the write channel state so that it can be saved and restored afterwards. The originalWriteChanneland the restored one should not both be used. Closing one channel causes the other channel to close; subsequent writes will fail.- Specified by:
capturein interfaceRestorable<ServiceOptionsT extends ServiceOptions<?,ServiceOptionsT>>- Specified by:
capturein interfaceWriteChannel- Returns:
- a
RestorableStateobject 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.BaseStateobject.
-
-