public class CompositeReadableBuffer extends Object implements ReadableBuffer
ReadableBuffer.ByteBufferReader| Constructor and Description |
|---|
CompositeReadableBuffer()
Creates a default empty composite buffer
|
| Modifier and Type | Method and Description |
|---|---|
CompositeReadableBuffer |
append(byte[] array)
Adds the given array into the composite buffer at the end.
|
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 where data should be read from.
|
ByteBuffer |
byteBuffer() |
int |
capacity()
Returns the capacity of the backing buffer of this ReadableBuffer
|
CompositeReadableBuffer |
clear()
Resets the buffer position to zero and sets the limit to the buffer capacity,
the mark value is discarded if set.
|
CompositeReadableBuffer |
duplicate()
Creates a duplicate
ReadableBuffer to this instance. |
boolean |
equals(Object other) |
CompositeReadableBuffer |
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.
|
CompositeReadableBuffer |
get(byte[] data)
A bulk read method that copies bytes from this buffer into the target byte array.
|
CompositeReadableBuffer |
get(byte[] data,
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.
|
CompositeReadableBuffer |
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.
|
List<byte[]> |
getArrays() |
int |
getCurrentIndex() |
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
ReadableBuffer.array() and ReadableBuffer.arrayOffset() methods. |
int |
hashCode() |
boolean |
hasRemaining() |
int |
limit() |
CompositeReadableBuffer |
limit(int limit)
Sets the current read limit of this buffer to the given value.
|
CompositeReadableBuffer |
mark()
Mark the current position of this buffer which can be returned to after a
read operation by calling
ReadableBuffer.reset(). |
int |
position() |
CompositeReadableBuffer |
position(int position)
Sets the current position of this buffer to the given value.
|
String |
readString(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. |
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.
|
CompositeReadableBuffer |
reclaimRead()
Compact the buffer dropping arrays that have been consumed by previous
reads from this Composite buffer.
|
int |
remaining() |
CompositeReadableBuffer |
reset()
Reset the buffer's position to a previously marked value, the mark should remain
set after calling this method.
|
CompositeReadableBuffer |
rewind()
Resets the buffer position to zero and clears and previously set mark.
|
CompositeReadableBuffer |
slice()
Creates a new ReadableBuffer instance that is a view of the readable portion of
this buffer.
|
String |
toString() |
public CompositeReadableBuffer()
public List<byte[]> getArrays()
public int getCurrentIndex()
public boolean hasArray()
ReadableBufferReadableBuffer.array() and ReadableBuffer.arrayOffset() methods.hasArray in interface ReadableBufferpublic int capacity()
ReadableBuffercapacity in interface ReadableBufferpublic byte[] array()
ReadableBufferReadableBuffer.hasArray()
method before calling this method.array in interface ReadableBufferpublic int arrayOffset()
ReadableBufferReadableBuffer.hasArray() method before calling this method.arrayOffset in interface ReadableBufferpublic byte get()
ReadableBufferget in interface ReadableBufferpublic byte get(int index)
ReadableBufferget in interface ReadableBufferindex - The index in the buffer from which to read the byte.public int getInt()
ReadableBuffergetInt in interface ReadableBufferpublic long getLong()
ReadableBuffergetLong in interface ReadableBufferpublic short getShort()
ReadableBuffergetShort in interface ReadableBufferpublic float getFloat()
ReadableBuffergetFloat in interface ReadableBufferpublic double getDouble()
ReadableBuffergetDouble in interface ReadableBufferpublic CompositeReadableBuffer get(byte[] data)
ReadableBufferget in interface ReadableBufferdata - The byte array to copy bytes read from this buffer.public CompositeReadableBuffer get(byte[] data, int offset, int length)
ReadableBufferget in interface ReadableBufferdata - 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.public CompositeReadableBuffer get(WritableBuffer target)
ReadableBufferget in interface ReadableBuffertarget - The WritableBuffer to transfer this buffer's data to.public CompositeReadableBuffer position(int position)
ReadableBufferposition in interface ReadableBufferposition - The new position to set for this buffer.ReadableBuffer.public int position()
position in interface ReadableBufferpublic CompositeReadableBuffer slice()
ReadableBufferReadableBuffer.remaining() method, the mark
will be undefined.slice in interface ReadableBufferpublic CompositeReadableBuffer flip()
ReadableBufferflip in interface ReadableBufferReadableBuffer.public CompositeReadableBuffer limit(int limit)
ReadableBufferlimit in interface ReadableBufferlimit - The new read limit to set for this buffer.ReadableBuffer.public int limit()
limit in interface ReadableBufferpublic CompositeReadableBuffer mark()
ReadableBufferReadableBuffer.reset().mark in interface ReadableBufferReadableBuffer.public CompositeReadableBuffer reset()
ReadableBufferreset in interface ReadableBufferReadableBuffer.public CompositeReadableBuffer rewind()
ReadableBufferrewind in interface ReadableBufferReadableBuffer.public CompositeReadableBuffer clear()
ReadableBufferclear in interface ReadableBufferReadableBuffer.public int remaining()
remaining in interface ReadableBufferpublic boolean hasRemaining()
hasRemaining in interface ReadableBufferpublic CompositeReadableBuffer duplicate()
ReadableBufferReadableBuffer 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.
duplicate in interface ReadableBufferReadableBuffer.public ByteBuffer byteBuffer()
byteBuffer in interface ReadableBufferpublic String readUTF8() throws CharacterCodingException
ReadableBufferreadUTF8 in interface ReadableBufferCharacterCodingException - if the encoding is invalid for any reason.public String readString(CharsetDecoder decoder) throws CharacterCodingException
ReadableBufferCharsetDecoder
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.readString in interface ReadableBufferCharacterCodingException - if the encoding is invalid for any reason.public CompositeReadableBuffer reclaimRead()
reclaimRead in interface ReadableBufferpublic CompositeReadableBuffer append(byte[] array)
The appended array is not copied so changes to the source array are visible in this
buffer and vice versa. If this composite was empty than it would return true for the
hasArray() method until another array is appended.
Calling this method resets the limit to the new capacity.
array - The array to add to this composite buffer.CompositeReadableBuffer.IllegalArgumentException - if the array is null or zero size.IllegalStateException - if the buffer does not allow appends.Copyright © 2018 The Apache Software Foundation. All rights reserved.