Bits

Manipulations with bytes and arrays. This class can be overridden in multi-release JAR with more efficient implementation for a newer versions of Java.

Methods
static int compareNotNullSigned(byte[] data1, byte[] data2)
Compare the contents of two byte arrays.
static int compareNotNullSigned(byte[] data1, byte[] data2)
Compare the contents of two byte arrays. If the content or length of the first array is smaller than the second array, -1 is returned. If the content or length of the second array is smaller than the first array, 1 is returned. If the contents and lengths are the same, 0 is returned.

This method interprets bytes as signed.

Parameters:
data1 - the first byte array (must not be null)
data2 - the second byte array (must not be null)
Returns:
the result of the comparison (-1, 1 or 0)
static int compareNotNullUnsigned(byte[] data1, byte[] data2)
Compare the contents of two byte arrays.
static int compareNotNullUnsigned(byte[] data1, byte[] data2)
Compare the contents of two byte arrays. If the content or length of the first array is smaller than the second array, -1 is returned. If the content or length of the second array is smaller than the first array, 1 is returned. If the contents and lengths are the same, 0 is returned.

This method interprets bytes as unsigned.

Parameters:
data1 - the first byte array (must not be null)
data2 - the second byte array (must not be null)
Returns:
the result of the comparison (-1, 1 or 0)
static int readInt(byte[] buff, int pos)
Reads a int value from the byte array at the given position in big-endian order.
static int readInt(byte[] buff, int pos)
Reads a int value from the byte array at the given position in big-endian order.
Parameters:
buff - the byte array
pos - the position
Returns:
the value
static long readLong(byte[] buff, int pos)
Reads a long value from the byte array at the given position in big-endian order.
static long readLong(byte[] buff, int pos)
Reads a long value from the byte array at the given position in big-endian order.
Parameters:
buff - the byte array
pos - the position
Returns:
the value
static byte[] uuidToBytes(long msb, long lsb)
Converts UUID value to byte array in big-endian order.
static byte[] uuidToBytes(long msb, long lsb)
Converts UUID value to byte array in big-endian order.
Parameters:
msb - most significant part of UUID
lsb - least significant part of UUID
Returns:
byte array representation
static byte[] uuidToBytes(UUID uuid)
Converts UUID value to byte array in big-endian order.
static byte[] uuidToBytes(UUID uuid)
Converts UUID value to byte array in big-endian order.
Parameters:
uuid - UUID value
Returns:
byte array representation
static void writeInt(byte[] buff, int pos, int x)
Writes a int value to the byte array at the given position in big-endian order.
static void writeInt(byte[] buff, int pos, int x)
Writes a int value to the byte array at the given position in big-endian order.
Parameters:
buff - the byte array
pos - the position
x - the value to write
static void writeLong(byte[] buff, int pos, long x)
Writes a long value to the byte array at the given position in big-endian order.
static void writeLong(byte[] buff, int pos, long x)
Writes a long value to the byte array at the given position in big-endian order.
Parameters:
buff - the byte array
pos - the position
x - the value to write