Package org.apache.qpid.proton.codec
Class ReadableBuffer.ByteBufferReader
java.lang.Object
org.apache.qpid.proton.codec.ReadableBuffer.ByteBufferReader
- All Implemented Interfaces:
ReadableBuffer
- Enclosing interface:
ReadableBuffer
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.qpid.proton.codec.ReadableBuffer
ReadableBuffer.ByteBufferReader
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionallocate
(int size) byte[]
array()
Returns the primitive array that backs this buffer if one exists and the buffer is not read-only.int
Returns the offset into the backing array of the first element in the buffer.int
capacity()
Returns the capacity of the backing buffer of this ReadableBufferclear()
Resets the buffer position to zero and sets the limit to the buffer capacity, the mark value is discarded if set.Creates a duplicateReadableBuffer
to this instance.boolean
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.get
(byte[] data) A bulk read method that copies bytes from this buffer into the target byte array.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.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
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 theReadableBuffer.array()
andReadableBuffer.arrayOffset()
methods.int
hashCode()
boolean
int
limit()
limit
(int limit) Sets the current read limit of this buffer to the given value.mark()
Mark the current position of this buffer which can be returned to after a read operation by callingReadableBuffer.reset()
.int
position()
position
(int position) Sets the current position of this buffer to the given value.readString
(CharsetDecoder decoder) Decodes a String from the buffer using the providedCharsetDecoder
starting the decode at the current position and reading until the limit is reached.readUTF8()
Reads a UTF-8 encoded String from the buffer starting the decode at the current position and reading until the limit is reached.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
reset()
Reset the buffer's position to a previously marked value, the mark should remain set after calling this method.rewind()
Resets the buffer position to zero and clears and previously set mark.slice()
Creates a new ReadableBuffer instance that is a view of the readable portion of this buffer.toString()
wrap
(byte[] array) wrap
(ByteBuffer buffer)
-
Constructor Details
-
ByteBufferReader
-
-
Method Details
-
allocate
-
wrap
-
wrap
-
capacity
public int capacity()Description copied from interface:ReadableBuffer
Returns the capacity of the backing buffer of this ReadableBuffer- Specified by:
capacity
in interfaceReadableBuffer
- Returns:
- the capacity of the backing buffer of this ReadableBuffer
-
get
public byte get()Description copied from interface:ReadableBuffer
Reads the byte at the current position and advances the position by 1.- Specified by:
get
in interfaceReadableBuffer
- Returns:
- the byte at the current position.
-
get
public byte get(int index) Description copied from interface:ReadableBuffer
Reads the byte at the given index, the buffer position is not affected.- Specified by:
get
in interfaceReadableBuffer
- Parameters:
index
- The index in the buffer from which to read the byte.- Returns:
- the byte value stored at the target index.
-
getInt
public int getInt()Description copied from interface:ReadableBuffer
Reads four bytes from the buffer and returns them as an integer value. The buffer position is advanced by four byes.- Specified by:
getInt
in interfaceReadableBuffer
- Returns:
- and integer value composed of bytes read from the buffer.
-
getLong
public long getLong()Description copied from interface:ReadableBuffer
Reads eight bytes from the buffer and returns them as an long value. The buffer position is advanced by eight byes.- Specified by:
getLong
in interfaceReadableBuffer
- Returns:
- and long value composed of bytes read from the buffer.
-
getShort
public short getShort()Description copied from interface:ReadableBuffer
Reads two bytes from the buffer and returns them as an short value. The buffer position is advanced by two byes.- Specified by:
getShort
in interfaceReadableBuffer
- Returns:
- and short value composed of bytes read from the buffer.
-
getFloat
public float getFloat()Description copied from interface:ReadableBuffer
Reads four bytes from the buffer and returns them as an float value. The buffer position is advanced by four byes.- Specified by:
getFloat
in interfaceReadableBuffer
- Returns:
- and float value composed of bytes read from the buffer.
-
getDouble
public double getDouble()Description copied from interface:ReadableBuffer
Reads eight bytes from the buffer and returns them as an double value. The buffer position is advanced by eight byes.- Specified by:
getDouble
in interfaceReadableBuffer
- Returns:
- and double value composed of bytes read from the buffer.
-
limit
public int limit()- Specified by:
limit
in interfaceReadableBuffer
- Returns:
- the current value of this buffer's limit.
-
get
Description copied from interface:ReadableBuffer
A bulk read method that copies bytes from this buffer into the target byte array.- Specified by:
get
in interfaceReadableBuffer
- Parameters:
data
- 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.- Returns:
- a reference to this ReadableBuffer instance.
-
get
Description copied from interface:ReadableBuffer
A bulk read method that copies bytes from this buffer into the target byte array.- Specified by:
get
in interfaceReadableBuffer
- Parameters:
data
- The byte array to copy bytes read from this buffer.- Returns:
- a reference to this ReadableBuffer instance.
-
flip
Description copied from interface:ReadableBuffer
Sets the buffer limit to the current position and the position is set to zero, the mark value reset to undefined.- Specified by:
flip
in interfaceReadableBuffer
- Returns:
- a reference to this
ReadableBuffer
.
-
position
Description copied from interface:ReadableBuffer
Sets the current position of this buffer to the given value. If the buffer mark value is defined and is larger than the newly set position is must be discarded.- Specified by:
position
in interfaceReadableBuffer
- Parameters:
position
- The new position to set for this buffer.- Returns:
- a reference to this
ReadableBuffer
.
-
slice
Description copied from interface:ReadableBuffer
Creates a new ReadableBuffer instance that is a view of the readable portion of this buffer. The position will be set to zero and the limit and the reported capacity will match the value returned by this buffer'sReadableBuffer.remaining()
method, the mark will be undefined.- Specified by:
slice
in interfaceReadableBuffer
- Returns:
- a new ReadableBuffer that is a view of the readable portion of this buffer.
-
limit
Description copied from interface:ReadableBuffer
Sets the current read limit of this buffer to the given value. If the buffer mark value is defined and is larger than the limit the mark will be discarded. If the position is larger than the new limit it will be reset to the new limit.- Specified by:
limit
in interfaceReadableBuffer
- Parameters:
limit
- The new read limit to set for this buffer.- Returns:
- a reference to this
ReadableBuffer
.
-
remaining
public int remaining()- Specified by:
remaining
in interfaceReadableBuffer
- Returns:
- the remaining number of readable bytes in this buffer.
-
position
public int position()- Specified by:
position
in interfaceReadableBuffer
- Returns:
- the current position from which the next read operation will start.
-
hasRemaining
public boolean hasRemaining()- Specified by:
hasRemaining
in interfaceReadableBuffer
- Returns:
- true if there are readable bytes still remaining in this buffer.
-
duplicate
Description copied from interface:ReadableBuffer
Creates a duplicateReadableBuffer
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.
- Specified by:
duplicate
in interfaceReadableBuffer
- Returns:
- a duplicate of this
ReadableBuffer
.
-
byteBuffer
- Specified by:
byteBuffer
in interfaceReadableBuffer
- Returns:
- a ByteBuffer view of the current readable portion of this buffer.
-
readUTF8
Description copied from interface:ReadableBuffer
Reads a UTF-8 encoded String from the buffer 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.- Specified by:
readUTF8
in interfaceReadableBuffer
- Returns:
- a string decoded from the remaining bytes in this buffer.
-
readString
Description copied from interface:ReadableBuffer
Decodes a String from the buffer using the providedCharsetDecoder
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.- Specified by:
readString
in interfaceReadableBuffer
- Returns:
- a string decoded from the remaining bytes in this buffer.
- Throws:
CharacterCodingException
- if the encoding is invalid for any reason.
-
hasArray
public boolean hasArray()Description copied from interface:ReadableBuffer
Returns true if this ReadableBuffer is backed by an array which can be accessed by theReadableBuffer.array()
andReadableBuffer.arrayOffset()
methods.- Specified by:
hasArray
in interfaceReadableBuffer
- Returns:
- true if the buffer is backed by a primitive array.
-
array
public byte[] array()Description copied from interface:ReadableBuffer
Returns the primitive array that backs this buffer if one exists and the buffer is not read-only. The caller should have checked theReadableBuffer.hasArray()
method before calling this method.- Specified by:
array
in interfaceReadableBuffer
- Returns:
- the array that backs this buffer is available.
-
arrayOffset
public int arrayOffset()Description copied from interface:ReadableBuffer
Returns the offset into the backing array of the first element in the buffer. The caller should have checked theReadableBuffer.hasArray()
method before calling this method.- Specified by:
arrayOffset
in interfaceReadableBuffer
- Returns:
- the offset into the backing array of the first element in the buffer.
-
reclaimRead
Description copied from interface:ReadableBuffer
Compact the backing storage of this ReadableBuffer, possibly freeing previously-read portions of pooled data or reducing the number of backing arrays if present.This is an optional operation and care should be taken in its implementation.
- Specified by:
reclaimRead
in interfaceReadableBuffer
- Returns:
- a reference to this buffer
-
mark
Description copied from interface:ReadableBuffer
Mark the current position of this buffer which can be returned to after a read operation by callingReadableBuffer.reset()
.- Specified by:
mark
in interfaceReadableBuffer
- Returns:
- a reference to this
ReadableBuffer
.
-
reset
Description copied from interface:ReadableBuffer
Reset the buffer's position to a previously marked value, the mark should remain set after calling this method.- Specified by:
reset
in interfaceReadableBuffer
- Returns:
- a reference to this
ReadableBuffer
.
-
rewind
Description copied from interface:ReadableBuffer
Resets the buffer position to zero and clears and previously set mark.- Specified by:
rewind
in interfaceReadableBuffer
- Returns:
- a reference to this
ReadableBuffer
.
-
clear
Description copied from interface:ReadableBuffer
Resets the buffer position to zero and sets the limit to the buffer capacity, the mark value is discarded if set.- Specified by:
clear
in interfaceReadableBuffer
- Returns:
- a reference to this
ReadableBuffer
.
-
get
Description copied from interface:ReadableBuffer
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.- Specified by:
get
in interfaceReadableBuffer
- Parameters:
target
- The WritableBuffer to transfer this buffer's data to.- Returns:
- a reference to this ReadableBuffer instance.
-
toString
-
hashCode
public int hashCode() -
equals
-