public class TByteBuffer extends Object
Modifier and Type | Field and Description |
---|---|
static int |
SIZE_OF_BOOLEAN
uncompressed size of boolean within IMB framework
|
static int |
SIZE_OF_BYTE
uncompressed size of byte within IMB framework
|
static int |
SIZE_OF_DOUBLE
uncompressed size of double within IMB framework
|
static int |
SIZE_OF_INT32
uncompressed size of 32 bit integer within IMB framework
|
static int |
SIZE_OF_INT64
uncompressed size of 64 bit integer within IMB framework
|
static int |
SIZE_OF_SINGLE
uncompressed size of single within IMB framework
|
Constructor and Description |
---|
TByteBuffer()
Constructor: create empty byte buffer
|
TByteBuffer(byte[] aBuffer)
Constructor: create byte buffer as copy of the specified byte array
|
TByteBuffer(int aLength)
Constructor: create byte buffer of the specified length
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear the byte buffer to zero length and reset all cursors
|
void |
clear(int aLength)
Clear the byte buffer to the specified length and reset all cursors.
|
boolean |
compare(byte[] aValue,
int aOffset)
Compare the contents of this byte buffer at the read cursor to a given byte array
|
byte[] |
getBuffer()
Retrieve reference to internal byte buffer
|
int |
getLength()
length of the byte buffer in bytes
|
int |
getReadAvailable()
Retrieve the bytes that still can be read from the byte buffer
|
int |
getReadCursor()
Retrieve the current reading (cursor) position
|
int |
getwriteAvailable()
Returns the room still available in the byte buffer to write data to without reallocating memory.
|
int |
getWriteCursor()
Retrieve the current writing (cursor) position
|
boolean |
isEmpty()
Check if the byte buffer is empty
|
boolean |
peekBoolean(int aOffset)
Read a boolean from the byte buffer at an offset to the read cursor without advancing the read cursor.
|
boolean |
peekBoolean(int aOffset,
boolean aDefaultValue)
Read a boolean from the byte buffer at an offset to the read cursor without advancing the read cursor.
|
byte |
peekByte(int aOffset)
Read a byte from the byte buffer at an offset to the read cursor without advancing the read cursor.
|
byte |
peekByte(int aOffset,
byte aDefaultValue)
Read a byte from the byte buffer at an offset to the read cursor without advancing the read cursor.
|
double |
peekDouble(int aOffset)
Read a double from the byte buffer at an offset to the read cursor without advancing the read cursor.
|
double |
peekDouble(int aOffset,
double aDefaultValue)
Read a double from the byte buffer at an offset to the read cursor without advancing the read cursor.
|
int |
peekInt32(int aOffset)
Read an 32 bit integer from the byte buffer at an offset to the read cursor without advancing the read cursor.
|
int |
peekInt32(int aOffset,
int aDefaultValue)
Read an 32 bit integer from the byte buffer at an offset to the read cursor without advancing the read cursor.
|
long |
peekInt64(int aOffset)
Read an 64 bit integer (long) from the byte buffer at an offset to the read cursor without advancing the read cursor.
|
long |
peekInt64(int aOffset,
long aDefaultValue)
Read an 64 bit integer (long) from the byte buffer at an offset to the read cursor without advancing the read cursor.
|
float |
peekSingle(int aOffset)
Read a single (32 bit float) from the byte buffer at an offset to the read cursor without advancing the read cursor.
|
float |
peekSingle(int aOffset,
float aDefaultValue)
Read a single (32 bit float) from the byte buffer at an offset to the read cursor without advancing the read cursor.
|
String |
peekString(int aOffset)
Read a string from the byte buffer at an offset to the read cursor without advancing the read cursor.
|
String |
peekString(int aOffset,
String aDefaultValue)
Read a string from the byte buffer at an offset to the read cursor without advancing the read cursor.
|
void |
prepare(boolean aValue)
Prepares the byte buffer for later writing of a boolean.
|
void |
prepare(byte aValue)
Prepares the byte buffer for later writing of a byte.
|
void |
prepare(byte[] aValue)
Prepares the byte buffer for later writing of a byte array (without size).
|
void |
prepare(double aValue)
Prepares the byte buffer for later writing of a double.
|
void |
prepare(float aValue)
Prepares the byte buffer for later writing of a 32 bit single (float).
|
void |
prepare(int aValue)
Prepares the byte buffer for later writing of an 32 bit integer.
|
void |
prepare(long aValue)
Prepares the byte buffer for later writing of an 64 bit integer (long).
|
void |
prepare(String aValue)
Prepares the byte buffer for later writing of a string.
|
void |
prepare(TByteBuffer aValue)
Prepares the byte buffer for later writing of an other byte buffers readable data.
|
void |
prepareApply()
Adjusts the length of the byte buffer to accommodate at a minimum all prepared data
|
void |
prepareApplyAndTrim()
Adjusts the length of the byte buffer to accommodate exactly all prepared data
|
int |
prepareSize(int aValueSize)
Prepares the byte buffer for later writing of the specified number of bytes.
|
int |
prepareStart()
Start prepare sequence.
|
boolean |
qReadBoolean()
Read a boolean from the byte buffer without any checks
|
byte |
qReadByte()
Read a byte from the byte buffer without any checks
|
TByteBuffer |
qReadByteBuffer()
Read a byte buffer this byte buffer without any checks
Read size and data and store as a whole WITHOUT size (size=length buffer)
|
double |
qReadDouble(double aDefaultValue)
Read a double from the byte buffer without any checks
|
int |
qReadInt32()
Read an 32 bit integer from the byte buffer without any checks
|
long |
qReadInt64()
Read an 64 bit integer from the byte buffer without any checks
|
float |
qReadSingle()
Read a single (32 bit float) from the byte buffer without any checks
|
String |
qReadString(String aDefaultValue)
Read a string from the byte buffer without any checks
|
void |
qWrite(boolean aValue)
write a boolean to the buffer; the QWrite methods do not check for room in the buffer
|
void |
qWrite(byte aValue)
write a single byte to the buffer; the QWrite methods do not check for room in the buffer
|
void |
qWrite(byte[] aValue)
write array of byte WITHOUT size; the QWrite methods do not check for room in the buffer
|
void |
qWrite(double aValue)
write a single double (64 bit) to the buffer; the QWrite methods do not check for room in the buffer
|
void |
qWrite(float aValue)
write a single float (32 bit) to the buffer; the QWrite methods do not check for room in the buffer
|
void |
qWrite(int aValue)
write a single integer (32 bit) to the buffer; the QWrite methods do not check for room in the buffer
|
void |
qWrite(long aValue)
write a single integer (64 bit) to the buffer; the QWrite methods do not check for room in the buffer
|
void |
qWrite(String aValue)
Write a string to the buffer, prefixed with the size as a 32 bit integer.
|
void |
qWrite(TByteBuffer aValue)
write, with no checking, all readable data from the given byte buffer to this prefixed WITH size
|
boolean |
readBoolean()
Read a boolean from the byte buffer
|
boolean |
readBoolean(boolean aDefaultValue)
Read a boolean from the byte buffer
|
byte |
readByte()
Read a byte from the byte buffer
|
byte |
readByte(byte aDefaultValue)
Read a byte from the byte buffer
|
TByteBuffer |
readByteBuffer()
Read new byte buffer contents from this byte buffer.
|
void |
readByteBuffer(TByteBuffer aValue)
Read size and data and store as a whole WITHOUT size (size=length buffer)
|
double |
readDouble()
Read a double float from the byte buffer
|
double |
readDouble(double aDefaultValue)
Read a double float from the byte buffer
|
int |
readInt32()
Read an integer (32 bit) from the byte buffer
|
int |
readInt32(int aDefaultValue)
Read an integer (32 bit) from the byte buffer
|
long |
readInt64()
Read an integer (64 bit) from the byte buffer
|
long |
readInt64(long aDefaultValue)
Read an integer (64 bit) from the byte buffer
|
byte[] |
readRest()
Read all data available from the read cursor
|
TByteBuffer |
readRestToByteBuffer()
Read all data available from the read cursor in this byte buffer to a newly created byte buffer
|
float |
readSingle()
Read a single float from the byte buffer
|
float |
readSingle(float aDefaultValue)
Read a single float from the byte buffer
|
void |
ReadStart()
Reset the reading cursor
|
String |
readString()
Read a string from the byte buffer.
|
String |
readString(String aDefaultValue)
Read a string from the byte buffer.
|
void |
shiftLeftOneByte(byte aRightByte)
Shift all bytes in the byte buffer to the left and insert a new byte to the right (end of byte buffer)
|
void |
skipReading(int aValueSize)
Skip the specified amount of bytes for reading
Advances the read cursor the specified amount of bytes
|
void |
write(boolean aValue)
Write the specified boolean to the byte buffer.
|
void |
write(byte aValue)
Write the specified byte to the byte buffer.
|
void |
write(byte[] aValue)
Write the specified byte array WITHOUT the size to the byte buffer.
|
void |
write(double aValue)
Write the specified double to the byte buffer.
|
void |
write(float aValue)
Write the specified single (float) to the byte buffer.
|
void |
write(int aValue)
Write the specified 32 bit integer to the byte buffer.
|
void |
write(long aValue)
Write the specified 64 bit integer (long) to the byte buffer.
|
void |
write(String aValue)
Write the specified string to the byte buffer in UTF-8 format.
|
void |
write(TByteBuffer aValue)
Write the readable data in the specified byte buffer to this byte buffer.
|
void |
writeApply()
apply written data (trim extra buffer space)
|
void |
writeStart(int aIndex)
Start writing at the specified 0-based index.
|
boolean |
written(int aValueSize)
signal number of bytes directly written to buffer without using class methods
update write cursor and return if it fitted into buffer (should trigger exception ?)
|
public static final int SIZE_OF_BOOLEAN
public static final int SIZE_OF_BYTE
public static final int SIZE_OF_INT32
public static final int SIZE_OF_INT64
public static final int SIZE_OF_SINGLE
public static final int SIZE_OF_DOUBLE
public TByteBuffer(int aLength)
aLength
- length in bytes of the buffer to createpublic TByteBuffer()
public TByteBuffer(byte[] aBuffer)
aBuffer
- public int getLength()
public byte[] getBuffer()
public void clear()
public void clear(int aLength)
public boolean isEmpty()
public int getReadCursor()
public int getWriteCursor()
public void ReadStart()
public int getReadAvailable()
public boolean readBoolean()
public boolean readBoolean(boolean aDefaultValue)
aDefaultValue
- in case of a read error this value is returnedpublic byte readByte()
public byte readByte(byte aDefaultValue)
aDefaultValue
- in case of a read error this value is returnedpublic int readInt32()
public int readInt32(int aDefaultValue)
aDefaultValue
- in case of a read error this value is returnedpublic long readInt64()
public long readInt64(long aDefaultValue)
aDefaultValue
- in case of a read error this value is returnedpublic float readSingle()
public float readSingle(float aDefaultValue)
aDefaultValue
- in case of a read error this value is returnedpublic double readDouble()
public double readDouble(double aDefaultValue)
aDefaultValue
- in case of a read error this value is returnedpublic String readString()
public String readString(String aDefaultValue)
aDefaultValue
- in case of a read error this value is returnedpublic TByteBuffer readByteBuffer()
public void readByteBuffer(TByteBuffer aValue)
aValue
- byte buffer to store the read data inpublic boolean qReadBoolean()
public byte qReadByte()
public int qReadInt32()
public long qReadInt64()
public float qReadSingle()
public double qReadDouble(double aDefaultValue)
public String qReadString(String aDefaultValue)
public TByteBuffer qReadByteBuffer()
public TByteBuffer readRestToByteBuffer()
public byte[] readRest()
public void skipReading(int aValueSize)
aValueSize
- number of bytes to skip for readingpublic boolean peekBoolean(int aOffset)
aOffset
- 0-based offset to the read cursor to peek at for the booleanpublic boolean peekBoolean(int aOffset, boolean aDefaultValue)
aOffset
- 0-based offset to the read cursor to peek at for the booleanaDefaultValue
- if the value could not be read this default is returnedpublic byte peekByte(int aOffset)
aOffset
- 0-based offset to the read cursor to peek at for the bytepublic byte peekByte(int aOffset, byte aDefaultValue)
aOffset
- 0-based offset to the read cursor to peek at for the byteaDefaultValue
- if the value could not be read this default is returnedpublic int peekInt32(int aOffset)
aOffset
- 0-based offset to the read cursor to peek at for the integerpublic int peekInt32(int aOffset, int aDefaultValue)
aOffset
- 0-based offset to the read cursor to peek at for the integeraDefaultValue
- if the value could not be read this default is returnedpublic long peekInt64(int aOffset)
aOffset
- 0-based offset to the read cursor to peek at for the longpublic long peekInt64(int aOffset, long aDefaultValue)
aOffset
- 0-based offset to the read cursor to peek at for the longaDefaultValue
- if the value could not be read this default is returnedpublic float peekSingle(int aOffset)
aOffset
- 0-based offset to the read cursor to peek at for the floatpublic float peekSingle(int aOffset, float aDefaultValue)
aOffset
- 0-based offset to the read cursor to peek at for the floataDefaultValue
- if the value could not be read this default is returnedpublic double peekDouble(int aOffset)
aOffset
- 0-based offset to the read cursor to peek at for the doublepublic double peekDouble(int aOffset, double aDefaultValue)
aOffset
- 0-based offset to the read cursor to peek at for the doubleaDefaultValue
- if the value could not be read this default is returnedpublic String peekString(int aOffset)
aOffset
- 0-based offset to the read cursor to peek at for the stringpublic String peekString(int aOffset, String aDefaultValue)
aOffset
- 0-based offset to the read cursor to peek at for the stringaDefaultValue
- if the value could not be read this default is returnedpublic boolean compare(byte[] aValue, int aOffset)
aValue
- byte array to compare with this byte bufferaOffset
- offset to the read cursor to start comparingpublic void shiftLeftOneByte(byte aRightByte)
aRightByte
- the byte to insert at the right side of the byte buffer after the shiftpublic int prepareStart()
public void prepare(boolean aValue)
aValue
- the boolean to be written later in a call to qWritepublic void prepare(byte aValue)
aValue
- the byte to be written later in a call to qWritepublic void prepare(int aValue)
aValue
- the 32 bit integer to be written later in a call to qWritepublic void prepare(long aValue)
aValue
- the 64 bit integer (long) to be written later in a call to qWritepublic void prepare(float aValue)
aValue
- the 32 bit single (float) to be written later in a call to qWritepublic void prepare(double aValue)
aValue
- the double to be written later in a call to qWritepublic void prepare(String aValue)
aValue
- the string to be written later in a call to qWritepublic void prepare(byte[] aValue)
aValue
- the byte array to be written later in a call to qWritepublic void prepare(TByteBuffer aValue)
aValue
- the byte buffers readable data to be written later in a call to qWritepublic int prepareSize(int aValueSize)
aValueSize
- the number of bytes to be written later in a call to qWritepublic void prepareApply()
public void prepareApplyAndTrim()
public void writeStart(int aIndex)
aIndex
- the new value for the write cursorpublic int getwriteAvailable()
public void write(boolean aValue)
aValue
- the boolean to be written to the byte bufferpublic void write(byte aValue)
aValue
- the byte to be written to the byte bufferpublic void write(int aValue)
aValue
- the 32 bit integer to be written to the byte bufferpublic void write(long aValue)
aValue
- the 64 bit integer (long) to be written to the byte bufferpublic void write(float aValue)
aValue
- the single (float) to be written to the byte bufferpublic void write(double aValue)
aValue
- the double to be written to the byte bufferpublic void write(String aValue)
aValue
- the string to be written to the byte bufferpublic void write(byte[] aValue)
aValue
- the byte buffer to be written to the byte bufferpublic void write(TByteBuffer aValue)
aValue
- the byte buffer who's readable data is to be written to this byte bufferpublic void qWrite(boolean aValue)
aValue
- the boolean value to be written to the bufferpublic void qWrite(byte aValue)
aValue
- the byte value to be written to the bufferpublic void qWrite(int aValue)
aValue
- the integer (32 bit) value to be written to the bufferpublic void qWrite(long aValue)
aValue
- the integer (64 bit) value to be written to the bufferpublic void qWrite(float aValue)
aValue
- the float (32 bit) value to be written to the bufferpublic void qWrite(double aValue)
aValue
- the float (64 bit) value to be written to the bufferpublic void qWrite(String aValue)
aValue
- the float (32 bit) value to be written to the bufferpublic void qWrite(byte[] aValue)
aValue
- the byte array written to the buffer (without prefixed size)public void qWrite(TByteBuffer aValue)
aValue
- readable data in byte buffer to be written to the bufferpublic boolean written(int aValueSize)
aValueSize
- number of bytes directly written into bufferpublic void writeApply()
Copyright © 2014–2016 Delft University of Technology. All rights reserved.