java.lang.Object
cl.netswitch.lib.util.Buffers
Provides static utility methods that operate on
ByteBuffers
.-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
read7bitBytes
(ByteBuffer buffer) Reads a 7bit byte array from the supplied ByteBuffer.static int
read7bitInt
(ByteBuffer buffer) Reads a 7bit integer from the supplied ByteBuffer.static long
read7bitLong
(ByteBuffer buffer) Reads a 7bit long from the supplied ByteBuffer.static String
read7bitString
(ByteBuffer buffer) Reads a 7bit string from the supplied ByteBuffer.static int
readByte
(ByteBuffer buffer) Reads a byte from the supplied ByteBuffer.static byte[]
readBytes
(ByteBuffer buffer, int length) Reads a byte array from the supplied ByteBuffer.static double
readDouble
(ByteBuffer buffer) Reads a double from the supplied ByteBuffer.static float
readFloat
(ByteBuffer buffer) Reads a float from the supplied ByteBuffer.static int
readInt
(ByteBuffer buffer) Reads an integer from the supplied ByteBuffer.static long
readLong
(ByteBuffer buffer) Reads a long from the supplied ByteBuffer.static short
readShort
(ByteBuffer buffer) Reads a short from the supplied ByteBuffer.static String
toTrace
(byte[] bytes, int offset, int length, boolean inbound) Returns a trace representation of the supplied array of bytes.static String
toTrace
(ByteBuffer buffer, boolean inbound) Returns a trace representation of the suppliedByteBuffer
.
-
Field Details
-
EMPTY_BUFFER
ByteBuffer
with zero bytes (empty).
-
-
Method Details
-
readByte
Reads a byte from the supplied ByteBuffer. The position of the buffer is incremented by 1.- Parameters:
buffer
- the byte buffer that will be read.- Returns:
- the next available byte in supplied ByteBuffer.
- Throws:
NullPointerException
- ifbuffer
isnull
.BufferUnderflowException
- ifbuffer
is missing bytes.
-
readShort
Reads a short from the supplied ByteBuffer. The position of the buffer is incremented by 2. The bytes of the buffer are always composed in big endian order (most significant to least significant).- Parameters:
buffer
- the ByteBuffer containing the input bytes.- Returns:
- the short value read from the supplied ByteBuffer.
- Throws:
NullPointerException
- ifbuffer
isnull
.BufferUnderflowException
- ifbuffer
is missing bytes.
-
readInt
Reads an integer from the supplied ByteBuffer. The position of the buffer is incremented by 4. The bytes of the buffer are always composed in big endian order (most significant to least significant).- Parameters:
buffer
- the ByteBuffer containing the input bytes.- Returns:
- the integer value read from the supplied ByteBuffer.
- Throws:
NullPointerException
- ifbuffer
isnull
.BufferUnderflowException
- ifbuffer
is missing bytes.
-
readLong
Reads a long from the supplied ByteBuffer. The position of the buffer is incremented by 8. The bytes of the buffer are always composed in big endian order (most significant to least significant).- Parameters:
buffer
- the ByteBuffer containing the input bytes.- Returns:
- the long value read from the supplied ByteBuffer.
- Throws:
NullPointerException
- ifbuffer
isnull
.BufferUnderflowException
- ifbuffer
is missing bytes.
-
readDouble
Reads a double from the supplied ByteBuffer. The position of the buffer is incremented by 8. The bytes of the buffer are always composed in big endian order (most significant to least significant).- Parameters:
buffer
- the ByteBuffer containing the input bytes.- Returns:
- the double value read from the supplied ByteBuffer.
- Throws:
NullPointerException
- ifbuffer
isnull
.BufferUnderflowException
- ifbuffer
is missing bytes.
-
readFloat
Reads a float from the supplied ByteBuffer. The position of the buffer is incremented by 4. The bytes of the buffer are always composed in big endian order (most significant to least significant).- Parameters:
buffer
- the ByteBuffer containing the input bytes.- Returns:
- the float value read from the supplied ByteBuffer.
- Throws:
NullPointerException
- ifbuffer
isnull
.BufferUnderflowException
- ifbuffer
is missing bytes.
-
readBytes
Reads a byte array from the supplied ByteBuffer. The position of the buffer is incremented bylength
.- Parameters:
buffer
- the byte buffer that will be read.length
- the number of bytes to read.- Returns:
- the byte array read from the ByteBuffer.
- Throws:
NullPointerException
- ifbuffer
isnull
.IllegalArgumentException
- iflength
is negative.BufferUnderflowException
- ifbuffer
is missing bytes.
-
read7bitInt
Reads a 7bit integer from the supplied ByteBuffer.- Parameters:
buffer
- the byte buffer that will be read.- Returns:
- the integer value read from the ByteBuffer.
- Throws:
NullPointerException
- ifbuffer
isnull
.BufferUnderflowException
- ifbuffer
is missing bytes.
-
read7bitLong
Reads a 7bit long from the supplied ByteBuffer.- Parameters:
buffer
- the byte buffer that will be read.- Returns:
- the long value read from the ByteBuffer.
- Throws:
NullPointerException
- ifbuffer
isnull
.BufferUnderflowException
- ifbuffer
is missing bytes.
-
read7bitBytes
Reads a 7bit byte array from the supplied ByteBuffer.- Parameters:
buffer
- the byte buffer that will be read.- Returns:
- the byte array read from the ByteBuffer.
- Throws:
NullPointerException
- ifbuffer
isnull
.BufferUnderflowException
- ifbuffer
is missing bytes.
-
read7bitString
Reads a 7bit string from the supplied ByteBuffer.- Parameters:
buffer
- the byte buffer that will be read.- Returns:
- the string read from the ByteBuffer.
- Throws:
NullPointerException
- ifbuffer
isnull
.BufferUnderflowException
- ifbuffer
is missing bytes.
-
toTrace
Returns a trace representation of the supplied array of bytes.- Parameters:
bytes
- the array of bytes to be converted to a string.offset
- the offset of the subarray to be used.length
- the length of the subarray to be used.inbound
-true
if inbound message; otherwise outbound.- Returns:
- a trace representation of the supplied array of bytes.
- Throws:
NullPointerException
- ifbytes
isnull
.
-
toTrace
Returns a trace representation of the suppliedByteBuffer
.- Parameters:
buffer
- theByteBuffer
to be converted to a string.inbound
-true
if inbound message; otherwise outbound.- Returns:
- a trace representation of the supplied
ByteBuffer
. - Throws:
NullPointerException
- ifbuffer
isnull
.
-