public interface ReadableBuffer
WritableBuffer
Modifier and Type | Interface and Description |
---|---|
static class |
ReadableBuffer.ByteBufferReader |
Modifier and Type | Method and Description |
---|---|
byte[] |
array()
Returns the primitive array that backs this buffer if one exists and the
buffer is not read-only.
|
int |
arrayOffset()
Returns the offset into the backing array of the first element in the buffer.
|
java.nio.ByteBuffer |
byteBuffer() |
int |
capacity()
Returns the capacity of the backing buffer of this ReadableBuffer
|
ReadableBuffer |
clear()
Resets the buffer position to zero and sets the limit to the buffer capacity,
the mark value is discarded if set.
|
ReadableBuffer |
duplicate()
Creates a duplicate
ReadableBuffer to this instance. |
ReadableBuffer |
flip()
Sets the buffer limit to the current position and the position is set to zero, the
mark value reset to undefined.
|
byte |
get()
Reads the byte at the current position and advances the position by 1.
|
ReadableBuffer |
get(byte[] target)
A bulk read method that copies bytes from this buffer into the target byte array.
|
ReadableBuffer |
get(byte[] target,
int offset,
int length)
A bulk read method that copies bytes from this buffer into the target byte array.
|
byte |
get(int index)
Reads the byte at the given index, the buffer position is not affected.
|
ReadableBuffer |
get(WritableBuffer target)
Copy data from this buffer to the target buffer starting from the current
position and continuing until either this buffer's remaining bytes are
consumed or the target is full.
|
double |
getDouble()
Reads eight bytes from the buffer and returns them as an double value.
|
float |
getFloat()
Reads four bytes from the buffer and returns them as an float value.
|
int |
getInt()
Reads four bytes from the buffer and returns them as an integer value.
|
long |
getLong()
Reads eight bytes from the buffer and returns them as an long value.
|
short |
getShort()
Reads two bytes from the buffer and returns them as an short value.
|
boolean |
hasArray()
Returns true if this ReadableBuffer is backed by an array which can be
accessed by the
array() and arrayOffset() methods. |
boolean |
hasRemaining() |
int |
limit() |
ReadableBuffer |
limit(int limit)
Sets the current read limit of this buffer to the given value.
|
ReadableBuffer |
mark()
Mark the current position of this buffer which can be returned to after a
read operation by calling
reset() . |
int |
position() |
ReadableBuffer |
position(int position)
Sets the current position of this buffer to the given value.
|
java.lang.String |
readString(java.nio.charset.CharsetDecoder decoder)
Decodes a String from the buffer using the provided
CharsetDecoder
starting the decode at the current position and reading until the limit is
reached. |
java.lang.String |
readUTF8()
Reads a UTF-8 encoded String from the buffer starting the decode at the
current position and reading until the limit is reached.
|
ReadableBuffer |
reclaimRead()
Compact the backing storage of this ReadableBuffer, possibly freeing previously-read
portions of pooled data or reducing the number of backing arrays if present.
|
int |
remaining() |
ReadableBuffer |
reset()
Reset the buffer's position to a previously marked value, the mark should remain
set after calling this method.
|
ReadableBuffer |
rewind()
Resets the buffer position to zero and clears and previously set mark.
|
ReadableBuffer |
slice()
Creates a new ReadableBuffer instance that is a view of the readable portion of
this buffer.
|
int capacity()
boolean hasArray()
array()
and arrayOffset()
methods.byte[] array()
hasArray()
method before calling this method.java.lang.UnsupportedOperationException
- if this ReadableBuffer
doesn't support array access.java.nio.ReadOnlyBufferException
- if the ReadableBuffer is read-only.int arrayOffset()
hasArray()
method before calling this method.java.lang.UnsupportedOperationException
- if this ReadableBuffer
doesn't support array access.java.nio.ReadOnlyBufferException
- if the ReadableBuffer is read-only.ReadableBuffer reclaimRead()
This is an optional operation and care should be taken in its implementation.
byte get()
java.nio.BufferUnderflowException
- if the buffer position has reached the limit.byte get(int index)
index
- The index in the buffer from which to read the byte.java.lang.IndexOutOfBoundsException
- if the index is not in range for this buffer.int getInt()
java.nio.BufferUnderflowException
- if the buffer position has reached the limit.long getLong()
java.nio.BufferUnderflowException
- if the buffer position has reached the limit.short getShort()
java.nio.BufferUnderflowException
- if the buffer position has reached the limit.float getFloat()
java.nio.BufferUnderflowException
- if the buffer position has reached the limit.double getDouble()
java.nio.BufferUnderflowException
- if the buffer position has reached the limit.ReadableBuffer get(byte[] target, int offset, int length)
target
- The byte array to copy bytes read from this buffer.offset
- The offset into the given array where the copy starts.length
- The number of bytes to copy into the target array.java.nio.BufferUnderflowException
- if the are less readable bytes than the array length.java.lang.IndexOutOfBoundsException
- if the offset or length values are invalid.ReadableBuffer get(byte[] target)
target
- The byte array to copy bytes read from this buffer.java.nio.BufferUnderflowException
- if the are less readable bytes than the array length.ReadableBuffer get(WritableBuffer target)
target
- The WritableBuffer to transfer this buffer's data to.ReadableBuffer slice()
remaining()
method, the mark
will be undefined.ReadableBuffer flip()
ReadableBuffer
.ReadableBuffer limit(int limit)
limit
- The new read limit to set for this buffer.ReadableBuffer
.java.lang.IllegalArgumentException
- if the limit value is negative or greater than the capacity.int limit()
ReadableBuffer position(int position)
position
- The new position to set for this buffer.ReadableBuffer
.java.lang.IllegalArgumentException
- if the position value is negative or greater than the limit.int position()
ReadableBuffer mark()
reset()
.ReadableBuffer
.ReadableBuffer reset()
ReadableBuffer
.java.nio.InvalidMarkException
- if the mark value is undefined.ReadableBuffer rewind()
ReadableBuffer
.ReadableBuffer clear()
ReadableBuffer
.int remaining()
boolean hasRemaining()
ReadableBuffer duplicate()
ReadableBuffer
to this instance.
The duplicated buffer will have the same position, limit and mark as this buffer. The two buffers share the same backing data.
ReadableBuffer
.java.nio.ByteBuffer byteBuffer()
java.lang.String readUTF8() throws java.nio.charset.CharacterCodingException
java.nio.charset.CharacterCodingException
- if the encoding is invalid for any reason.java.lang.String readString(java.nio.charset.CharsetDecoder decoder) throws java.nio.charset.CharacterCodingException
CharsetDecoder
starting the decode at the current position and reading until the limit is
reached. The position is advanced to the limit once this method returns.
If there is no bytes remaining in the buffer when this method is called a
null is returned.java.nio.charset.CharacterCodingException
- if the encoding is invalid for any reason.