Class LittleEndianByteArray

java.lang.Object
com.google.common.hash.LittleEndianByteArray

final class LittleEndianByteArray extends Object
Utility functions for loading and storing values from a byte array.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static enum 
    Fallback implementation for when Unsafe is not available in our current environment.
    private static interface 
    Common interface for retrieving a 64-bit long from a little-endian byte array.
    private static enum 
    The only reference to Unsafe is in this nested class.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    The instance that actually does the work; delegates to Unsafe or a pure-Java fallback.
  • Constructor Summary

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

    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
    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
  • Field Details

  • Constructor Details

    • LittleEndianByteArray

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

    • 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:
      source - 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.