|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.sgs.impl.sharedutil.MessageBuffer
public class MessageBuffer
A buffer for composing/decomposing messages.
Strings are encoded in modified UTF-8 format as described in
DataInput.
| Constructor Summary | |
|---|---|
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. |
|
| Method Summary | |
|---|---|
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MessageBuffer(int capacity)
capacity - the buffer's capacitypublic MessageBuffer(byte[] buf)
buf - the byte array to back this buffer| Method Detail |
|---|
public static int getSize(String str)
str - a string
public int capacity()
public int limit()
public int position()
public void rewind()
public MessageBuffer putByte(int b)
b - a byte
IndexOutOfBoundsException - if adding the byte to the
buffer would overflow the bufferpublic MessageBuffer putByteArray(byte[] bytes)
bytes - a byte array
IndexOutOfBoundsException - if adding the bytes to this
buffer would overflow the bufferpublic MessageBuffer putBytes(byte[] bytes)
bytes - a byte array
IndexOutOfBoundsException - if adding the bytes to this
buffer would overflow the bufferpublic MessageBuffer putChar(int v)
v - a char value
IndexOutOfBoundsException - if adding the char to this
buffer would overflow the bufferpublic MessageBuffer putShort(int v)
v - a short value
IndexOutOfBoundsException - if adding the short to this
buffer would overflow the bufferpublic MessageBuffer putInt(int v)
v - an int value
IndexOutOfBoundsException - if adding the int to this
buffer would overflow the bufferpublic MessageBuffer putLong(long v)
v - a long value
IndexOutOfBoundsException - if adding the long to this
buffer would overflow the bufferpublic MessageBuffer putString(String str)
str - a string
IndexOutOfBoundsException - 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 buffer
IndexOutOfBoundsException - 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()
|
Project Darkstar, Version 0.9.8.6 2013-07-29 20:32:23 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||