public final class ReadWrite extends Object
ByteBuffer
objects and byte arrays.Constructor and Description |
---|
ReadWrite() |
Modifier and Type | Method and Description |
---|---|
static void |
appendTextDataSegmentToStringBuffer(ByteBuffer byteBuffer,
StringBuilder stringBuilder)
Appends the content of a
ProtocolDataUnit (text) data segment to a StringBuilder ; |
static String |
byteBufferToString(ByteBuffer buffer)
Returns the bytes in a
ByteBuffer as a UTF-8 encoded String . |
static byte[] |
longToBytes(long value)
Splits the passed value into bytes and returns them in an array, in big-endian format.
|
static int |
readFourByteInt(byte[] array,
int start)
Reads a (signed) 4-byte integer from four consecutive big-endian-ordered bytes of a byte array and returns the
value.
|
static int |
readFourByteInt(ByteBuffer buffer,
int start)
Reads a (signed) 4-byte integer from four consecutive big-endian-ordered bytes of a
ByteBuffer object and
returns the value. |
static int |
readOneByteInt(byte[] array,
int start)
Reads a specified byte from a byte array and returns its value as an unsigned integer.
|
static int |
readOneByteInt(ByteBuffer buffer,
int start)
Reads a specified byte from a
ByteBuffer and returns its value as an unsigned integer. |
static int |
readThreeByteInt(byte[] array,
int start)
Reads an unsigned 3-byte integer from three consecutive big-endian-ordered bytes of a byte array and returns the
value.
|
static int |
readThreeByteInt(ByteBuffer buffer,
int start)
Reads an unsigned 3-byte integer from three consecutive big-endian-ordered bytes of a
ByteBuffer object
and returns the value. |
static int |
readTwoByteInt(byte[] array,
int start)
Reads an unsigned 2-byte integer from two consecutive big-endian-ordered bytes of a byte array and returns the
value.
|
static int |
readTwoByteInt(ByteBuffer buffer,
int start)
Reads an unsigned 2-byte integer from two consecutive big-endian-ordered bytes of a
ByteBuffer object and
returns the value. |
static long |
readUnsignedInt(ByteBuffer buffer,
int start)
Reads an unsigned 4-byte integer from four consecutive big-endian-ordered bytes of a
ByteBuffer object
and returns the value. |
static ByteBuffer[] |
stringToTextDataSegments(String string,
int bufferSize)
Puts the characters in the passed String into an array of one or more ByteBuffers and returns it.
|
static void |
writeInt(int value,
ByteBuffer buffer,
int start)
Writes the given value to the buffer in big-endian format, with the index position of the most
significant byte being start.
|
static void |
writeLong(ByteBuffer buffer,
long value,
int index)
Writes the given value to the buffer in big-endian format, with the index position of the most
significant byte being index.
|
static void |
writeThreeByteInt(ByteBuffer buffer,
int value,
int index)
Writes the three least-significant big-endian-ordered bytes of an integer the a specified position in a
ByteBuffer . |
static void |
writeTwoByteInt(ByteBuffer buffer,
int value,
int index)
Writes the two least-significant big-endian-ordered bytes of an integer the a specified position in a
ByteBuffer . |
public static final int readOneByteInt(ByteBuffer buffer, int start)
ByteBuffer
and returns its value as an unsigned integer.buffer
- the ByteBuffer
containing the bytestart
- the index position of the byte in the ByteBuffer
public static final int readOneByteInt(byte[] array, int start)
array
- the array containing the bytestart
- the index position of the byte in the arraypublic static final int readTwoByteInt(ByteBuffer buffer, int start)
ByteBuffer
object and
returns the value.buffer
- the ByteBuffer
containing the bytesstart
- the index position of the most-significant bytepublic static final int readTwoByteInt(byte[] array, int start)
array
- the byte array containing the bytesstart
- the index position of the most-significant bytepublic static final int readThreeByteInt(ByteBuffer buffer, int start)
ByteBuffer
object
and returns the value.buffer
- the ByteBuffer
containing the bytesstart
- the index position of the most-significant bytepublic static final int readThreeByteInt(byte[] array, int start)
array
- the byte array containing the bytesstart
- the index position of the most-significant bytepublic static final int readFourByteInt(ByteBuffer buffer, int start)
ByteBuffer
object and
returns the value.buffer
- the ByteBuffer
containing the bytesstart
- the index position of the most-significant bytepublic static final int readFourByteInt(byte[] array, int start)
array
- the byte array containing the bytesstart
- the index position of the most-significant bytepublic static ByteBuffer[] stringToTextDataSegments(String string, int bufferSize)
If the String does not end with a null character, one will be appended. If the String's length is larger than the specified bufferSize, all but the last ByteBuffer will have capacity() = bufferSize, the last one will contain the remaining String characters.
string
- the String to be put into the ByteBufferbufferSize
- the maximum size of the returned ByteBufferspublic static final void appendTextDataSegmentToStringBuffer(ByteBuffer byteBuffer, StringBuilder stringBuilder)
ProtocolDataUnit
(text) data segment to a StringBuilder
;byteBuffer
- the PDU's data segmentstringBuilder
- the StringBuilder
that will be extendedpublic static final void writeInt(int value, ByteBuffer buffer, int start)
value
- the integer to write to the ByteBufferbuffer
- where the integer will be storedstart
- index of the most significant byte of the stored valuepublic static String byteBufferToString(ByteBuffer buffer)
ByteBuffer
as a UTF-8 encoded String
.buffer
- a ByteBuffer
containing UTF-8 encoded characters.public static byte[] longToBytes(long value)
value
- the long to splitpublic static void writeLong(ByteBuffer buffer, long value, int index)
value
- the integer to write to the ByteBufferbuffer
- where the integer will be storedindex
- index of the most significant byte of the stored valuepublic static void writeTwoByteInt(ByteBuffer buffer, int value, int index)
ByteBuffer
.buffer
- where the bytes will be writtenvalue
- the value to convert and copyindex
- the position of the most significant byte in the ByteBuffer
public static void writeThreeByteInt(ByteBuffer buffer, int value, int index)
ByteBuffer
.buffer
- where the bytes will be writtenvalue
- the value to convert and copyindex
- the position of the most significant byte in the ByteBuffer
public static long readUnsignedInt(ByteBuffer buffer, int start)
ByteBuffer
object
and returns the value.buffer
- the ByteBuffer
containing the bytesstart
- the index position of the most-significant byteCopyright © 2013 University of Konstanz, Distributed Systems Group. All Rights Reserved.