|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jarol.messages.Buffer
public class Buffer
Buffer class for serialization.
This class defines the basic methods for interfacing with a buffer encoded in big endian or small endian byte order.
It is essentially an extension wrapper for java.nio.ByteBuffer which cannot be subclassed due to the particular mechanism of creating ByteBuffer objects (ie factory methods), thus the wrapper functionality (instead of subclassing)
.Note: The buf field is protected for fast access through eventual subclasses.
Field Summary | |
---|---|
protected java.nio.ByteBuffer |
buf
Internal ByteBuffer instance, can be accessed by subclasses. |
Constructor Summary | |
---|---|
Buffer(byte[] data)
Constructor from a data byte array. |
|
Buffer(byte[] data,
java.nio.ByteOrder order)
Constructor from a data byte array and specified byte order. |
|
Buffer(byte[] data,
int off,
int len)
Constructor from a data byte array, plus specified offset and usable length. |
|
Buffer(byte[] data,
int off,
int len,
java.nio.ByteOrder order)
Constructor from a data byte array, plus specified offset, usable length and byte order to use. |
Method Summary | |
---|---|
java.nio.ByteOrder |
getByteOrder()
Get byte order in use (big endian or little endian). |
byte[] |
getData()
Get data array. |
int |
position()
Get buffer position. |
float |
readFP32()
Read a 32-bit floating point value from the buffer. |
double |
readFP64()
Read a 64-bit floating point value from the buffer. |
short |
readINT16()
Read a signed 16 bit integer from the buffer. |
int |
readINT32()
Read a signed 32 bit integer from the buffer. |
long |
readINT64()
Read a signed 64 bit integer from the buffer. |
byte |
readINT8()
Read a signed 8 bit integer from the buffer. |
java.lang.String |
readPlainText(boolean encodedLength)
Read plain text (string) data with optional length prefix specifier. |
byte[] |
readRawData()
Read raw data. |
int |
readUINT16()
Read an unsigned 16 bit integer from the buffer. |
long |
readUINT32()
Read an unsigned 32 bit integer from the buffer. |
long |
readUINT64()
Read an unsigned 64 bit integer from the buffer (fake). |
short |
readUINT8()
Read an unsigned 8 bit integer from the buffer. |
void |
reset(byte[] data,
int off,
int len,
java.nio.ByteOrder order)
Reset buffer. |
void |
rewind()
Rewind buffer to starting position. |
void |
setByteOrder(java.nio.ByteOrder order)
Change byte order in use. |
void |
writeFP32(float f32)
Write 32-bit floating point value onto buffer. |
void |
writeFP64(double f64)
Write 64-bit floating point value onto buffer. |
void |
writeINT16(short i16)
Write 16-bit signed integer value onto buffer. |
void |
writeINT32(int i32)
Write 32-bit signed integer value onto buffer. |
void |
writeINT64(long i64)
Write 64-bit signed integer value onto buffer. |
void |
writeINT8(byte i8)
Write 8-bit signed integer value onto buffer. |
void |
writePlainText(java.lang.String text,
boolean encodeLength)
Write plain text with optional 2-byte length prefix specifier. |
void |
writeRawData(byte[] data)
Write raw data with 2-byte length prefix specifier. |
void |
writeUINT16(int u16)
Write 16-bit unsigned integer value onto buffer. |
void |
writeUINT32(long u32)
Write 32-bit unsigned integer value onto buffer. |
void |
writeUINT64(long u64)
Write 64-bit unsigned integer value onto buffer. |
void |
writeUINT8(short u8)
Write 8-bit unsigned integer value onto buffer. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.nio.ByteBuffer buf
Constructor Detail |
---|
public Buffer(byte[] data)
data
- the source datapublic Buffer(byte[] data, int off, int len)
data
- the source dataoff
- the source data offsetlen
- the source data lengthpublic Buffer(byte[] data, java.nio.ByteOrder order)
data
- the source dataorder
- byte order to usepublic Buffer(byte[] data, int off, int len, java.nio.ByteOrder order)
data
- the source dataoff
- the source data offsetlen
- the source data lengthorder
- the byte order to useMethod Detail |
---|
public void reset(byte[] data, int off, int len, java.nio.ByteOrder order)
data
- the source dataoff
- the source data offsetlen
- the source data lengthorder
- the byte order to usepublic byte[] getData()
public void rewind()
public void setByteOrder(java.nio.ByteOrder order)
order
- the byte order to use (little endian or big endian)public java.nio.ByteOrder getByteOrder()
public final int position()
public final byte readINT8()
public final short readUINT8()
public final short readINT16()
public final int readUINT16()
public final int readINT32()
public final long readUINT32()
public final long readINT64()
public final long readUINT64()
public final float readFP32()
public final double readFP64()
public final byte[] readRawData()
public final java.lang.String readPlainText(boolean encodedLength)
encodedLength
- encoded length flag
public final void writeINT8(byte i8)
i8
- 8-bit signed integer valuepublic final void writeUINT8(short u8)
u8
- 8-bit unsigned integer value (8-bit truncation will be made)public final void writeINT16(short i16)
i16
- 16-bit signed integer valuepublic final void writeUINT16(int u16)
u16
- 16-bit signed integer value (truncation to 16 bits will be made)public final void writeINT32(int i32)
i32
- 32-bit signed integer valuepublic final void writeUINT32(long u32)
u32
- 32-bit signed integer value (truncation to 32 bits will be made)public final void writeINT64(long i64)
i64
- 64-bit signed integer valuepublic final void writeUINT64(long u64)
u64
- 64-bit signed integer valuepublic final void writeFP32(float f32)
f32
- 32-bit floating point valuepublic final void writeFP64(double f64)
f64
- 64-bit floating point valuepublic final void writeRawData(byte[] data)
data
- to writepublic final void writePlainText(java.lang.String text, boolean encodeLength)
text
- text to writeencodeLength
- indicate that length should be encoded as a 2-byte prefix
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |