Class LittleEndianByteArray


  • final class LittleEndianByteArray
    extends java.lang.Object
    Utility functions for loading and storing values from a byte array.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private LittleEndianByteArray()
      Deter instantiation of this class.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static int load32​(byte[] source, int offset)
      Load 4 bytes from the provided array at the indicated offset.
      (package private) static long load64​(byte[] input, int offset)
      Load 8 bytes into long in a little endian manner, from the substring between position and position + 8.
      (package private) static long load64Safely​(byte[] input, int offset, int length)
      Similar to load64, but allows offset + 8 > input.length, padding the result with zeroes.
      (package private) static void store64​(byte[] sink, int offset, long value)
      Store 8 bytes into the provided array at the indicated offset, using the value provided.
      (package private) static boolean usingUnsafe()
      Indicates that the loading of Unsafe was successful and the load and store operations will be very efficient.
      • Methods inherited from class java.lang.Object

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

      • LittleEndianByteArray

        private LittleEndianByteArray()
        Deter instantiation of this class.
    • Method Detail

      • load64

        static long load64​(byte[] input,
                           int offset)
        Load 8 bytes into long in a little endian manner, from the substring between position and position + 8. The array must have at least 8 bytes from offset (inclusive).
        Parameters:
        input - the input bytes
        offset - the offset into the array at which to start
        Returns:
        a long of a concatenated 8 bytes
      • load64Safely

        static long load64Safely​(byte[] input,
                                 int offset,
                                 int length)
        Similar to load64, but allows offset + 8 > input.length, padding the result with zeroes. This has to explicitly reverse the order of the bytes as it packs them into the result which makes it slower than the native version.
        Parameters:
        input - the input bytes
        offset - the offset into the array at which to start reading
        length - the number of bytes from the input to read
        Returns:
        a long of a concatenated 8 bytes
      • store64

        static void store64​(byte[] sink,
                            int offset,
                            long value)
        Store 8 bytes into the provided array at the indicated offset, using the value provided.
        Parameters:
        sink - the output byte array
        offset - the offset into the array at which to start writing
        value - the value to write
      • load32

        static int load32​(byte[] source,
                          int offset)
        Load 4 bytes from the provided array at the indicated offset.
        Parameters:
        input - the input bytes
        offset - the offset into the array at which to start
        Returns:
        the value found in the array in the form of a long
      • usingUnsafe

        static boolean usingUnsafe()
        Indicates that the loading of Unsafe was successful and the load and store operations will be very efficient. May be useful for calling code to fall back on an alternative implementation that is slower than Unsafe.get/store but faster than the pure-Java mask-and-shift.