| Constructor and Description |
|---|
MessageBuffer(byte[] buf)
Constructs a message buffer using the specified byte array as
the byte array that backs this buffer.
|
MessageBuffer(int capacity)
Constructs an empty message buffer with the specified capacity.
|
| Modifier and Type | Method and Description |
|---|---|
int |
capacity()
Returns the capacity of this buffer.
|
byte[] |
getBuffer()
Returns the byte array that backs this buffer.
|
byte |
getByte()
Returns the byte in this buffer's current position, and
advances the buffer's position by one.
|
byte[] |
getByteArray()
Returns a byte array encoded as a 2-byte length followed by the
bytes, starting at this buffer's current position, and advances
the buffer's position by the number of bytes obtained.
|
byte[] |
getBytes(int size)
Returns a byte array containing the specified number of bytes,
starting at this buffer's current position, and advances the
buffer's position by the number of bytes obtained.
|
char |
getChar()
Returns a char, composed of the next two bytes (high
byte first) in this buffer, and advances the buffer's position
by two.
|
int |
getInt()
Returns an int value, composed of the next four bytes (high
byte first) in this buffer, and advances the buffer's position
by 4.
|
long |
getLong()
Returns a long value, composed of the next eight bytes (high
byte first) in this buffer, and advances the buffer's position
by 8.
|
short |
getShort()
Returns a short value, composed of the next two bytes (high
byte first) in this buffer, and advances the buffer's position
by two.
|
static int |
getSize(String str)
Returns the size of the specified string, encoded in modified
UTF-8 format.
|
String |
getString()
Returns a string that has been encoded in modified UTF-8
format, starting at the buffer's current position, and advances
the buffer's position by the length of the encoded string.
|
int |
getUnsignedShort()
Returns an unsigned short value (as an int), composed of the
next two bytes (high byte first) in this buffer, and advances
the buffer's position by two.
|
int |
limit()
Returns the limit of this buffer.
|
int |
position()
Returns the position of this buffer.
|
MessageBuffer |
putByte(int b)
Puts the specified byte in this buffer's current position,
and advances the buffer's position and limit by one.
|
MessageBuffer |
putByteArray(byte[] bytes)
Puts into this buffer a short representing the length of the specified
byte array followed by the bytes from the specified byte array,
starting at the buffer's current position.
|
MessageBuffer |
putBytes(byte[] bytes)
Puts the bytes from the specified byte array in this buffer,
starting at the buffer's current position.
|
MessageBuffer |
putChar(int v)
Puts the specified char as a two-byte value (high byte first)
starting in the buffer's current position, and advances the
buffer's position and limit by two.
|
MessageBuffer |
putInt(int v)
Puts the specified int as four bytes (high byte first)
starting in the buffer's current position, and advances the
buffer's position and limit by 4.
|
MessageBuffer |
putLong(long v)
Puts the specified long as eight bytes (high byte first)
starting in the buffer's current position, and advances the
buffer's position and limit by 8.
|
MessageBuffer |
putShort(int v)
Puts the specified short as a two-byte value (high byte first)
starting in the buffer's current position, and advances the
buffer's position and limit by two.
|
MessageBuffer |
putString(String str)
Puts the specified string, encoded in modified UTF-8 format,
in the buffer starting in the buffer's the current position, and
advances the buffer's position and limit by the size of the
encoded string.
|
void |
rewind()
Sets the position of this buffer to zero, making this buffer
ready for re-reading of its elements.
|
public MessageBuffer(int capacity)
capacity - the buffer's capacitypublic MessageBuffer(byte[] buf)
buf - the byte array to back this bufferpublic static int getSize(String str)
str - a stringpublic int capacity()
public int limit()
public int position()
public void rewind()
public MessageBuffer putByte(int b)
b - a byteIndexOutOfBoundsException - if adding the byte to the
buffer would overflow the bufferpublic MessageBuffer putByteArray(byte[] bytes)
bytes - a byte arrayIndexOutOfBoundsException - if adding the bytes to this
buffer would overflow the bufferpublic MessageBuffer putBytes(byte[] bytes)
bytes - a byte arrayIndexOutOfBoundsException - if adding the bytes to this
buffer would overflow the bufferpublic MessageBuffer putChar(int v)
v - a char valueIndexOutOfBoundsException - if adding the char to this
buffer would overflow the bufferpublic MessageBuffer putShort(int v)
v - a short valueIndexOutOfBoundsException - if adding the short to this
buffer would overflow the bufferpublic MessageBuffer putInt(int v)
v - an int valueIndexOutOfBoundsException - if adding the int to this
buffer would overflow the bufferpublic MessageBuffer putLong(long v)
v - a long valueIndexOutOfBoundsException - if adding the long to this
buffer would overflow the bufferpublic MessageBuffer putString(String str)
str - a stringIndexOutOfBoundsException - if adding the encoded string
to this buffer would overflow the bufferpublic byte getByte()
IndexOutOfBoundsException - if this buffer's limit has
been reachedpublic byte[] getByteArray()
IndexOutOfBoundsException - if this buffer's limit would
be reached as a result of getting the encoded bytespublic byte[] getBytes(int size)
size - the number of bytes to get from this bufferIndexOutOfBoundsException - if this buffer's limit would
be reached as a result of getting the specified number of bytespublic short getShort()
IndexOutOfBoundsException - if this buffer's limit would
be reached as a result of getting the next two bytespublic int getUnsignedShort()
IndexOutOfBoundsException - if this buffer's limit would
be reached as a result of getting the next two bytespublic int getInt()
IndexOutOfBoundsException - if this buffer's limit would
be reached as a result of getting the next four bytespublic long getLong()
IndexOutOfBoundsException - if this buffer's limit would
be reached as a result of getting the next eight bytespublic char getChar()
IndexOutOfBoundsException - if this buffer's limit would
be reached as a result of getting the next two bytespublic String getString()
IndexOutOfBoundsException - if this buffer's limit would
be reached as a result of getting the encoded stringpublic byte[] getBuffer()
Copyright © 2007-2013. All Rights Reserved.