Class Bits
java.lang.Object
org.h2.util.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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcompareNotNull(char[] data1, char[] data2) Compare the contents of two char arrays.static intcompareNotNullSigned(byte[] data1, byte[] data2) Compare the contents of two byte arrays.static intcompareNotNullUnsigned(byte[] data1, byte[] data2) Compare the contents of two byte arrays.static doublereadDouble(byte[] buff, int pos) Reads a double value from the byte array at the given position in big-endian order.static doublereadDoubleLE(byte[] buff, int pos) Reads a double value from the byte array at the given position in little-endian order.static intreadInt(byte[] buff, int pos) Reads a int value from the byte array at the given position in big-endian order.static intreadIntLE(byte[] buff, int pos) Reads a int value from the byte array at the given position in little-endian order.static longreadLong(byte[] buff, int pos) Reads a long value from the byte array at the given position in big-endian order.static longreadLongLE(byte[] buff, int pos) Reads a long value from the byte array at the given position in little-endian order.static byte[]uuidToBytes(long msb, long lsb) 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.static voidwriteDouble(byte[] buff, int pos, double x) Writes a double value to the byte array at the given position in big-endian order.static voidwriteDoubleLE(byte[] buff, int pos, double x) Writes a double value to the byte array at the given position in little-endian order.static voidwriteInt(byte[] buff, int pos, int x) Writes a int value to the byte array at the given position in big-endian order.static voidwriteIntLE(byte[] buff, int pos, int x) Writes a int value to the byte array at the given position in little-endian order.static voidwriteLong(byte[] buff, int pos, long x) Writes a long value to the byte array at the given position in big-endian order.static voidwriteLongLE(byte[] buff, int pos, long x) Writes a long value to the byte array at the given position in little-endian order.
-
Constructor Details
-
Bits
private Bits()
-
-
Method Details
-
compareNotNull
public static int compareNotNull(char[] data1, char[] data2) Compare the contents of two char 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.- Parameters:
data1- the first char array (must not be null)data2- the second char array (must not be null)- Returns:
- the result of the comparison (-1, 1 or 0)
-
compareNotNullSigned
public 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)
-
compareNotNullUnsigned
public 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)
-
readInt
public 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 arraypos- the position- Returns:
- the value
-
readIntLE
public static int readIntLE(byte[] buff, int pos) Reads a int value from the byte array at the given position in little-endian order.- Parameters:
buff- the byte arraypos- the position- Returns:
- the value
-
readLong
public 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 arraypos- the position- Returns:
- the value
-
readLongLE
public static long readLongLE(byte[] buff, int pos) Reads a long value from the byte array at the given position in little-endian order.- Parameters:
buff- the byte arraypos- the position- Returns:
- the value
-
readDouble
public static double readDouble(byte[] buff, int pos) Reads a double value from the byte array at the given position in big-endian order.- Parameters:
buff- the byte arraypos- the position- Returns:
- the value
-
readDoubleLE
public static double readDoubleLE(byte[] buff, int pos) Reads a double value from the byte array at the given position in little-endian order.- Parameters:
buff- the byte arraypos- the position- Returns:
- the value
-
uuidToBytes
public static byte[] uuidToBytes(long msb, long lsb) Converts UUID value to byte array in big-endian order.- Parameters:
msb- most significant part of UUIDlsb- least significant part of UUID- Returns:
- byte array representation
-
uuidToBytes
Converts UUID value to byte array in big-endian order.- Parameters:
uuid- UUID value- Returns:
- byte array representation
-
writeInt
public 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 arraypos- the positionx- the value to write
-
writeIntLE
public static void writeIntLE(byte[] buff, int pos, int x) Writes a int value to the byte array at the given position in little-endian order.- Parameters:
buff- the byte arraypos- the positionx- the value to write
-
writeLong
public 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 arraypos- the positionx- the value to write
-
writeLongLE
public static void writeLongLE(byte[] buff, int pos, long x) Writes a long value to the byte array at the given position in little-endian order.- Parameters:
buff- the byte arraypos- the positionx- the value to write
-
writeDouble
public static void writeDouble(byte[] buff, int pos, double x) Writes a double value to the byte array at the given position in big-endian order.- Parameters:
buff- the byte arraypos- the positionx- the value to write
-
writeDoubleLE
public static void writeDoubleLE(byte[] buff, int pos, double x) Writes a double value to the byte array at the given position in little-endian order.- Parameters:
buff- the byte arraypos- the positionx- the value to write
-