Class UnsafeAccess

java.lang.Object
org.apache.hadoop.hbase.util.UnsafeAccess

@Private @Evolving public final class UnsafeAccess extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    The offset to the first element in a byte array.
    static final boolean
     
    (package private) static final long
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    copy(byte[] src, int srcOffset, ByteBuffer dest, int destOffset, int length)
    Copies the bytes from given array's offset to length part into the given buffer.
    static void
    copy(ByteBuffer src, int srcOffset, byte[] dest, int destOffset, int length)
    Copies specified number of bytes from given offset of src ByteBuffer to the dest array.
    static void
    copy(ByteBuffer src, int srcOffset, ByteBuffer dest, int destOffset, int length)
    Copies specified number of bytes from given offset of src buffer into the dest buffer.
    static long
     
    static void
     
    private static int
    getAsInt(ByteBuffer buf, int offset)
    Reads bytes at the given offset as an int value.
    private static long
    getAsLong(ByteBuffer buf, int offset)
    Reads bytes at the given offset as a long value.
    private static short
    getAsShort(ByteBuffer buf, int offset)
    Reads bytes at the given offset as a short value.
    static int
    putByte(ByteBuffer buf, int offset, byte b)
    Put a byte value out to the specified BB position in big-endian format.
    static int
    putInt(byte[] bytes, int offset, int val)
    Put an int value out to the specified byte array position in big-endian format.
    static int
    putInt(ByteBuffer buf, int offset, int val)
    Put an int value out to the specified ByteBuffer offset in big-endian format.
    static int
    putLong(byte[] bytes, int offset, long val)
    Put a long value out to the specified byte array position in big-endian format.
    static int
    putLong(ByteBuffer buf, int offset, long val)
    Put a long value out to the specified BB position in big-endian format.
    static int
    putShort(byte[] bytes, int offset, short val)
    Put a short value out to the specified byte array position in big-endian format.
    static int
    putShort(ByteBuffer buf, int offset, short val)
    Put a short value out to the specified BB position in big-endian format.
    static byte
    toByte(Object ref, long offset)
    Returns the byte at the given offset of the object
    static byte
    toByte(ByteBuffer buf, int offset)
    Returns the byte at the given offset
    static int
    toInt(byte[] bytes, int offset)
    Converts a byte array to an int value considering it was written in big-endian format.
    static int
    toInt(Object ref, long offset)
    Reads a int value at the given Object's offset considering it was written in big-endian format.
    static int
    toInt(ByteBuffer buf, int offset)
    Reads an int value at the given buffer's offset considering it was written in big-endian format.
    static long
    toLong(byte[] bytes, int offset)
    Converts a byte array to a long value considering it was written in big-endian format.
    static long
    toLong(Object ref, long offset)
    Reads a long value at the given Object's offset considering it was written in big-endian format.
    static long
    toLong(ByteBuffer buf, int offset)
    Reads a long value at the given buffer's offset considering it was written in big-endian format.
    static short
    toShort(byte[] bytes, int offset)
    Converts a byte array to a short value considering it was written in big-endian format.
    static short
    toShort(Object ref, long offset)
    Reads a short value at the given Object's offset considering it was written in big-endian format.
    static short
    toShort(ByteBuffer buf, int offset)
    Reads a short value at the given buffer's offset considering it was written in big-endian format.
    private static void
    unsafeCopy(Object src, long srcAddr, Object dst, long destAddr, long len)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • toShort

      public static short toShort(byte[] bytes, int offset)
      Converts a byte array to a short value considering it was written in big-endian format.
      Parameters:
      bytes - byte array
      offset - offset into array
      Returns:
      the short value
    • toInt

      public static int toInt(byte[] bytes, int offset)
      Converts a byte array to an int value considering it was written in big-endian format.
      Parameters:
      bytes - byte array
      offset - offset into array
      Returns:
      the int value
    • toLong

      public static long toLong(byte[] bytes, int offset)
      Converts a byte array to a long value considering it was written in big-endian format.
      Parameters:
      bytes - byte array
      offset - offset into array
      Returns:
      the long value
    • putShort

      public static int putShort(byte[] bytes, int offset, short val)
      Put a short value out to the specified byte array position in big-endian format.
      Parameters:
      bytes - the byte array
      offset - position in the array
      val - short to write out
      Returns:
      incremented offset
    • putInt

      public static int putInt(byte[] bytes, int offset, int val)
      Put an int value out to the specified byte array position in big-endian format.
      Parameters:
      bytes - the byte array
      offset - position in the array
      val - int to write out
      Returns:
      incremented offset
    • putLong

      public static int putLong(byte[] bytes, int offset, long val)
      Put a long value out to the specified byte array position in big-endian format.
      Parameters:
      bytes - the byte array
      offset - position in the array
      val - long to write out
      Returns:
      incremented offset
    • toShort

      public static short toShort(ByteBuffer buf, int offset)
      Reads a short value at the given buffer's offset considering it was written in big-endian format.
      Returns:
      short value at offset
    • toShort

      public static short toShort(Object ref, long offset)
      Reads a short value at the given Object's offset considering it was written in big-endian format.
      Returns:
      short value at offset
    • getAsShort

      private static short getAsShort(ByteBuffer buf, int offset)
      Reads bytes at the given offset as a short value.
      Returns:
      short value at offset
    • toInt

      public static int toInt(ByteBuffer buf, int offset)
      Reads an int value at the given buffer's offset considering it was written in big-endian format.
      Returns:
      int value at offset
    • toInt

      public static int toInt(Object ref, long offset)
      Reads a int value at the given Object's offset considering it was written in big-endian format.
      Returns:
      int value at offset
    • getAsInt

      private static int getAsInt(ByteBuffer buf, int offset)
      Reads bytes at the given offset as an int value.
      Returns:
      int value at offset
    • toLong

      public static long toLong(ByteBuffer buf, int offset)
      Reads a long value at the given buffer's offset considering it was written in big-endian format.
      Returns:
      long value at offset
    • toLong

      public static long toLong(Object ref, long offset)
      Reads a long value at the given Object's offset considering it was written in big-endian format.
      Returns:
      long value at offset
    • getAsLong

      private static long getAsLong(ByteBuffer buf, int offset)
      Reads bytes at the given offset as a long value.
      Returns:
      long value at offset
    • toByte

      public static byte toByte(ByteBuffer buf, int offset)
      Returns the byte at the given offset
      Parameters:
      buf - the buffer to read
      offset - the offset at which the byte has to be read
      Returns:
      the byte at the given offset
    • toByte

      public static byte toByte(Object ref, long offset)
      Returns the byte at the given offset of the object
      Returns:
      the byte at the given offset
    • putInt

      public static int putInt(ByteBuffer buf, int offset, int val)
      Put an int value out to the specified ByteBuffer offset in big-endian format.
      Parameters:
      buf - the ByteBuffer to write to
      offset - offset in the ByteBuffer
      val - int to write out
      Returns:
      incremented offset
    • copy

      public static void copy(byte[] src, int srcOffset, ByteBuffer dest, int destOffset, int length)
      Copies the bytes from given array's offset to length part into the given buffer.
      Parameters:
      src - source array
      srcOffset - offset into source buffer
      dest - destination buffer
      destOffset - offset into destination buffer
      length - length of data to copy
    • unsafeCopy

      private static void unsafeCopy(Object src, long srcAddr, Object dst, long destAddr, long len)
    • copy

      public static void copy(ByteBuffer src, int srcOffset, byte[] dest, int destOffset, int length)
      Copies specified number of bytes from given offset of src ByteBuffer to the dest array.
      Parameters:
      src - source buffer
      srcOffset - offset into source buffer
      dest - destination array
      destOffset - offset into destination buffer
      length - length of data to copy
    • copy

      public static void copy(ByteBuffer src, int srcOffset, ByteBuffer dest, int destOffset, int length)
      Copies specified number of bytes from given offset of src buffer into the dest buffer.
      Parameters:
      src - source buffer
      srcOffset - offset into source buffer
      dest - destination buffer
      destOffset - offset into destination buffer
      length - length of data to copy
    • putShort

      public static int putShort(ByteBuffer buf, int offset, short val)
      Put a short value out to the specified BB position in big-endian format.
      Parameters:
      buf - the byte buffer
      offset - position in the buffer
      val - short to write out
      Returns:
      incremented offset
    • putLong

      public static int putLong(ByteBuffer buf, int offset, long val)
      Put a long value out to the specified BB position in big-endian format.
      Parameters:
      buf - the byte buffer
      offset - position in the buffer
      val - long to write out
      Returns:
      incremented offset
    • putByte

      public static int putByte(ByteBuffer buf, int offset, byte b)
      Put a byte value out to the specified BB position in big-endian format.
      Parameters:
      buf - the byte buffer
      offset - position in the buffer
      b - byte to write out
      Returns:
      incremented offset
    • directBufferAddress

      public static long directBufferAddress(ByteBuffer buf)
    • freeDirectBuffer

      public static void freeDirectBuffer(ByteBuffer buffer)