Class Buffer
- java.lang.Object
-
- org.restlet.ext.nio.internal.buffer.Buffer
-
@Deprecated public class Buffer extends java.lang.ObjectDeprecated.Will be removed to favor lower-level network extensions allowing more control at the Restlet API level.Wrapper around a byte buffer and its state.
-
-
Field Summary
Fields Modifier and Type Field Description private java.nio.ByteBufferbytesDeprecated.The byte buffer.private intfillBeginDeprecated.The index of the buffer's beginning while filling.private BufferStatestateDeprecated.The byte buffer IO state.
-
Constructor Summary
Constructors Constructor Description Buffer(int bufferSize)Deprecated.Constructor.Buffer(int bufferSize, boolean direct)Deprecated.Constructor.Buffer(java.nio.ByteBuffer byteBuffer)Deprecated.Constructor.Buffer(java.nio.ByteBuffer byteBuffer, BufferState byteBufferState)Deprecated.Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidbeforeDrain()Deprecated.Ensure that the buffer is ready to be drained, flipping it if necessary only.voidbeforeFill()Deprecated.Ensure that the buffer is ready to be filled, flipping it if necessary only.booleancanCompact()Deprecated.Indicates if a compacting operation can be beneficial.booleancanDrain()Deprecated.Indicates if more bytes can be drained.booleancanFill()Deprecated.Indicates if more bytes can be filled in.intcapacity()Deprecated.Returns the maximum capacity of this buffer.voidclear()Deprecated.Recycles the buffer so it can be reused.voidcompact()Deprecated.Compacts the bytes to be drained at the beginning of the buffer.booleancouldDrain()Deprecated.Indicates if bytes could be drained by flipping the buffer.booleancouldFill()Deprecated.Indicates if more bytes could be filled in.private static java.nio.ByteBuffercreateByteBuffer(int bufferSize, boolean direct)Deprecated.Creates a new byte buffer.intdrain()Deprecated.Drains the next byte in the buffer and returns it as an integer.voiddrain(byte[] targetArray, int offset, int length)Deprecated.Drains the buffer into a byte array.BufferStatedrain(java.lang.StringBuilder lineBuilder, BufferState builderState)Deprecated.Drains the buffer into a line builder (start line or header line).intdrain(java.nio.ByteBuffer targetBuffer)Deprecated.Drains the byte buffer by copying as many bytes as possible to the target buffer, with no modification.intdrain(java.nio.ByteBuffer targetBuffer, long maxDrained)Deprecated.Drains the byte buffer by copying as many bytes as possible to the target buffer, with no modification.intdrain(java.nio.channels.WritableByteChannel wbc)Deprecated.Drains the byte buffer by attempting to write as much as possible on the given channel.voidfill(byte[] sourceBuffer)Deprecated.Fills the byte buffer by copying as many bytes as possible from the source buffer, with no modification.voidfill(java.lang.String source)Deprecated.Fills the byte buffer by copying as many bytes as possible from the source string, using the default platform encoding.intfill(java.nio.ByteBuffer sourceBuffer)Deprecated.Fills the byte buffer by copying as many bytes as possible from the source buffer, with no modification.intfill(java.nio.ByteBuffer sourceBuffer, long maxFilled)Deprecated.Fills the byte buffer by copying as many bytes as possible from the source buffer, with no modification.intfill(java.nio.channels.ReadableByteChannel sourceChannel)Deprecated.Refills the byte buffer.voidflip()Deprecated.Flip from draining to filling or the other way around.java.nio.ByteBuffergetBytes()Deprecated.Returns the byte buffer.java.lang.ObjectgetLock()Deprecated.Returns the lock on which multiple thread can synchronize to ensure safe access to the underlying byte buffer which isn't thread safe.BufferStategetState()Deprecated.Returns the byte buffer IO state.booleanhasRemaining()Deprecated.Indicates if the buffer has remaining bytes to be read or written.booleanisDraining()Deprecated.Indicates if the buffer state has theBufferState.DRAININGvalue.booleanisEmpty()Deprecated.Indicates if the buffer is empty in either filling or draining state.booleanisFilling()Deprecated.Indicates if the buffer state has theBufferState.FILLINGvalue.intprocess(BufferProcessor processor, int maxDrained, java.lang.Object... args)Deprecated.Processes as a loop the IO event by draining or filling the IO buffer.intremaining()Deprecated.Returns the number of bytes that can be read or written in the byte buffer.voidsetState(BufferState byteBufferState)Deprecated.Sets the byte buffer IO state.java.lang.StringtoString()Deprecated.
-
-
-
Field Detail
-
bytes
private final java.nio.ByteBuffer bytes
Deprecated.The byte buffer.
-
fillBegin
private volatile int fillBegin
Deprecated.The index of the buffer's beginning while filling.
-
state
private volatile BufferState state
Deprecated.The byte buffer IO state.
-
-
Constructor Detail
-
Buffer
public Buffer(java.nio.ByteBuffer byteBuffer)
Deprecated.Constructor.- Parameters:
byteBuffer- The byte buffer wrapped.
-
Buffer
public Buffer(java.nio.ByteBuffer byteBuffer, BufferState byteBufferState)Deprecated.Constructor.- Parameters:
byteBuffer- The byte buffer wrapped.byteBufferState- The initial byte buffer state.
-
Buffer
public Buffer(int bufferSize)
Deprecated.Constructor. Allocates a new non-direct byte buffer.- Parameters:
bufferSize- The byte buffer size.
-
Buffer
public Buffer(int bufferSize, boolean direct)Deprecated.Constructor. Allocates a new byte buffer usingByteBuffer.allocate(int)orByteBuffer.allocateDirect(int)methods.- Parameters:
bufferSize- The byte buffer size.direct- Indicates if a direct NIO buffer should be created.
-
-
Method Detail
-
createByteBuffer
private static java.nio.ByteBuffer createByteBuffer(int bufferSize, boolean direct)Deprecated.Creates a new byte buffer.- Parameters:
bufferSize- The buffer size.direct- Indicates if a direct NIO buffer should be created.- Returns:
- The created byte buffer.
-
beforeDrain
public void beforeDrain()
Deprecated.Ensure that the buffer is ready to be drained, flipping it if necessary only.
-
beforeFill
public void beforeFill()
Deprecated.Ensure that the buffer is ready to be filled, flipping it if necessary only.
-
canCompact
public boolean canCompact()
Deprecated.Indicates if a compacting operation can be beneficial.- Returns:
- True if a compacting operation can be beneficial.
-
canDrain
public boolean canDrain()
Deprecated.Indicates if more bytes can be drained.- Returns:
- True if more bytes can be drained.
-
canFill
public boolean canFill()
Deprecated.Indicates if more bytes can be filled in.- Returns:
- True if more bytes can be filled in.
-
capacity
public final int capacity()
Deprecated.Returns the maximum capacity of this buffer.- Returns:
- The maximum capacity of this buffer.
-
clear
public void clear()
Deprecated.Recycles the buffer so it can be reused.
-
compact
public void compact()
Deprecated.Compacts the bytes to be drained at the beginning of the buffer.
-
couldDrain
public boolean couldDrain()
Deprecated.Indicates if bytes could be drained by flipping the buffer.- Returns:
- True if bytes could be drained.
-
couldFill
public boolean couldFill()
Deprecated.Indicates if more bytes could be filled in.- Returns:
- True if more bytes could be filled in.
-
drain
public int drain()
Deprecated.Drains the next byte in the buffer and returns it as an integer.- Returns:
- The next byte in the buffer;
-
drain
public void drain(byte[] targetArray, int offset, int length)Deprecated.Drains the buffer into a byte array.- Parameters:
targetArray- The target byte array.offset- The target offset.length- The number of bytes to drain.
-
drain
public int drain(java.nio.ByteBuffer targetBuffer)
Deprecated.Drains the byte buffer by copying as many bytes as possible to the target buffer, with no modification.- Parameters:
targetBuffer- The target buffer.- Returns:
- The number of bytes added to the target buffer.
-
drain
public int drain(java.nio.ByteBuffer targetBuffer, long maxDrained)Deprecated.Drains the byte buffer by copying as many bytes as possible to the target buffer, with no modification.- Parameters:
targetBuffer- The target buffer.maxDrained- The maximum number of bytes drained by this call or 0 for unlimited length.- Returns:
- The number of bytes added to the target buffer.
-
drain
public BufferState drain(java.lang.StringBuilder lineBuilder, BufferState builderState) throws java.io.IOException
Deprecated.Drains the buffer into a line builder (start line or header line).- Parameters:
lineBuilder- The line builder to fill.builderState- The builder state.- Returns:
- The new builder state.
- Throws:
java.io.IOException
-
drain
public int drain(java.nio.channels.WritableByteChannel wbc) throws java.io.IOExceptionDeprecated.Drains the byte buffer by attempting to write as much as possible on the given channel.- Parameters:
wbc- The byte channel to write to.- Returns:
- The number of bytes written.
- Throws:
java.io.IOException
-
fill
public void fill(byte[] sourceBuffer)
Deprecated.Fills the byte buffer by copying as many bytes as possible from the source buffer, with no modification.- Parameters:
sourceBuffer- The source buffer.
-
fill
public int fill(java.nio.ByteBuffer sourceBuffer)
Deprecated.Fills the byte buffer by copying as many bytes as possible from the source buffer, with no modification.- Parameters:
sourceBuffer- The source buffer.- Returns:
- The number of bytes added from the source buffer.
-
fill
public int fill(java.nio.ByteBuffer sourceBuffer, long maxFilled)Deprecated.Fills the byte buffer by copying as many bytes as possible from the source buffer, with no modification.- Parameters:
sourceBuffer- The source buffer.maxFilled- The maximum number of bytes filled by this call or 0 for unlimited length.- Returns:
- The number of bytes added from the source buffer.
-
fill
public int fill(java.nio.channels.ReadableByteChannel sourceChannel) throws java.io.IOExceptionDeprecated.Refills the byte buffer.- Parameters:
sourceChannel- The byte channel to read from.- Returns:
- The number of bytes read and added or -1 if end of the source channel reached.
- Throws:
java.io.IOException
-
fill
public void fill(java.lang.String source)
Deprecated.Fills the byte buffer by copying as many bytes as possible from the source string, using the default platform encoding.- Parameters:
source- The source string.
-
flip
public void flip()
Deprecated.Flip from draining to filling or the other way around.
-
getBytes
public java.nio.ByteBuffer getBytes()
Deprecated.Returns the byte buffer.- Returns:
- The byte buffer.
-
getLock
public java.lang.Object getLock()
Deprecated.Returns the lock on which multiple thread can synchronize to ensure safe access to the underlying byte buffer which isn't thread safe.- Returns:
- The lock on which multiple thread can synchronize.
-
getState
public BufferState getState()
Deprecated.Returns the byte buffer IO state.- Returns:
- The byte buffer IO state.
-
hasRemaining
public final boolean hasRemaining()
Deprecated.Indicates if the buffer has remaining bytes to be read or written.- Returns:
- True if the buffer has remaining bytes to be read or written.
-
isDraining
public boolean isDraining()
Deprecated.Indicates if the buffer state has theBufferState.DRAININGvalue.- Returns:
- True if the buffer state has the
BufferState.DRAININGvalue.
-
isEmpty
public boolean isEmpty()
Deprecated.Indicates if the buffer is empty in either filling or draining state.- Returns:
- True if the buffer is empty.
-
isFilling
public boolean isFilling()
Deprecated.Indicates if the buffer state has theBufferState.FILLINGvalue.- Returns:
- True if the buffer state has the
BufferState.FILLINGvalue.
-
process
public int process(BufferProcessor processor, int maxDrained, java.lang.Object... args) throws java.io.IOException
Deprecated.Processes as a loop the IO event by draining or filling the IO buffer. Note that synchronization of thegetLock()object is automatically made.- Parameters:
processor- The IO processor to callback.maxDrained- The maximum number of bytes drained by this call or 0 for unlimited length.args- The optional arguments to pass back to the callbacks.- Returns:
- The number of bytes drained or -1 if the filling source has ended.
- Throws:
java.io.IOException
-
remaining
public final int remaining()
Deprecated.Returns the number of bytes that can be read or written in the byte buffer.- Returns:
- The number of bytes that can be read or written.
-
setState
public void setState(BufferState byteBufferState)
Deprecated.Sets the byte buffer IO state.- Parameters:
byteBufferState- The byte buffer IO state.
-
toString
public java.lang.String toString()
Deprecated.- Overrides:
toStringin classjava.lang.Object
-
-