Package org.h2.util

Class Bits


  • public final class Bits
    extends java.lang.Object
    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 
      Modifier Constructor Description
      private Bits()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int compareNotNull​(char[] data1, char[] data2)
      Compare the contents of two char arrays.
      static int compareNotNullSigned​(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.
      static double readDouble​(byte[] buff, int pos)
      Reads a double value from the byte array at the given position in big-endian order.
      static double readDoubleLE​(byte[] buff, int pos)
      Reads a double value from the byte array at the given position in little-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.
      static int readIntLE​(byte[] buff, int pos)
      Reads a int value from the byte array at the given position in little-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.
      static long readLongLE​(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​(java.util.UUID uuid)
      Converts UUID value to byte array in big-endian order.
      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.
      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.
      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 writeIntLE​(byte[] buff, int pos, int x)
      Writes a int value to the byte array at the given position in little-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.
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Bits

        private Bits()
    • Method Detail

      • 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 array
        pos - 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 array
        pos - 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 array
        pos - 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 array
        pos - 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 array
        pos - 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 array
        pos - 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 UUID
        lsb - least significant part of UUID
        Returns:
        byte array representation
      • uuidToBytes

        public static byte[] uuidToBytes​(java.util.UUID uuid)
        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 array
        pos - the position
        x - 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 array
        pos - the position
        x - 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 array
        pos - the position
        x - 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 array
        pos - the position
        x - 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 array
        pos - the position
        x - 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 array
        pos - the position
        x - the value to write