Package org.apache.hadoop.hbase.util
Class UnsafeAccess
java.lang.Object
org.apache.hadoop.hbase.util.UnsafeAccess
-
Field Summary
Modifier and TypeFieldDescriptionstatic final long
The offset to the first element in a byte array.static final boolean
(package private) static final long
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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 ofsrc
ByteBuffer to thedest
array.static void
copy
(ByteBuffer src, int srcOffset, ByteBuffer dest, int destOffset, int length) Copies specified number of bytes from given offset ofsrc
buffer into thedest
buffer.static long
static void
freeDirectBuffer
(ByteBuffer buffer) 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
Returns the byte at the given offset of the objectstatic byte
toByte
(ByteBuffer buf, int offset) Returns the byte at the given offsetstatic int
toInt
(byte[] bytes, int offset) Converts a byte array to an int value considering it was written in big-endian format.static int
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
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
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)
-
Field Details
-
BYTE_ARRAY_BASE_OFFSET
The offset to the first element in a byte array. -
LITTLE_ENDIAN
-
UNSAFE_COPY_THRESHOLD
- See Also:
-
-
Constructor Details
-
UnsafeAccess
private UnsafeAccess()
-
-
Method Details
-
toShort
Converts a byte array to a short value considering it was written in big-endian format.- Parameters:
bytes
- byte arrayoffset
- offset into array- Returns:
- the short value
-
toInt
Converts a byte array to an int value considering it was written in big-endian format.- Parameters:
bytes
- byte arrayoffset
- offset into array- Returns:
- the int value
-
toLong
Converts a byte array to a long value considering it was written in big-endian format.- Parameters:
bytes
- byte arrayoffset
- offset into array- Returns:
- the long value
-
putShort
Put a short value out to the specified byte array position in big-endian format.- Parameters:
bytes
- the byte arrayoffset
- position in the arrayval
- short to write out- Returns:
- incremented offset
-
putInt
Put an int value out to the specified byte array position in big-endian format.- Parameters:
bytes
- the byte arrayoffset
- position in the arrayval
- int to write out- Returns:
- incremented offset
-
putLong
Put a long value out to the specified byte array position in big-endian format.- Parameters:
bytes
- the byte arrayoffset
- position in the arrayval
- long to write out- Returns:
- incremented offset
-
toShort
Reads a short value at the given buffer's offset considering it was written in big-endian format.- Returns:
- short value at offset
-
toShort
Reads a short value at the given Object's offset considering it was written in big-endian format.- Returns:
- short value at offset
-
getAsShort
Reads bytes at the given offset as a short value.- Returns:
- short value at offset
-
toInt
Reads an int value at the given buffer's offset considering it was written in big-endian format.- Returns:
- int value at offset
-
toInt
Reads a int value at the given Object's offset considering it was written in big-endian format.- Returns:
- int value at offset
-
getAsInt
Reads bytes at the given offset as an int value.- Returns:
- int value at offset
-
toLong
Reads a long value at the given buffer's offset considering it was written in big-endian format.- Returns:
- long value at offset
-
toLong
Reads a long value at the given Object's offset considering it was written in big-endian format.- Returns:
- long value at offset
-
getAsLong
Reads bytes at the given offset as a long value.- Returns:
- long value at offset
-
toByte
Returns the byte at the given offset- Parameters:
buf
- the buffer to readoffset
- the offset at which the byte has to be read- Returns:
- the byte at the given offset
-
toByte
Returns the byte at the given offset of the object- Returns:
- the byte at the given offset
-
putInt
Put an int value out to the specified ByteBuffer offset in big-endian format.- Parameters:
buf
- the ByteBuffer to write tooffset
- offset in the ByteBufferval
- int to write out- Returns:
- incremented offset
-
copy
Copies the bytes from given array's offset to length part into the given buffer.- Parameters:
src
- source arraysrcOffset
- offset into source bufferdest
- destination bufferdestOffset
- offset into destination bufferlength
- length of data to copy
-
unsafeCopy
-
copy
Copies specified number of bytes from given offset ofsrc
ByteBuffer to thedest
array.- Parameters:
src
- source buffersrcOffset
- offset into source bufferdest
- destination arraydestOffset
- offset into destination bufferlength
- length of data to copy
-
copy
Copies specified number of bytes from given offset ofsrc
buffer into thedest
buffer.- Parameters:
src
- source buffersrcOffset
- offset into source bufferdest
- destination bufferdestOffset
- offset into destination bufferlength
- length of data to copy
-
putShort
Put a short value out to the specified BB position in big-endian format.- Parameters:
buf
- the byte bufferoffset
- position in the bufferval
- short to write out- Returns:
- incremented offset
-
putLong
Put a long value out to the specified BB position in big-endian format.- Parameters:
buf
- the byte bufferoffset
- position in the bufferval
- long to write out- Returns:
- incremented offset
-
putByte
Put a byte value out to the specified BB position in big-endian format.- Parameters:
buf
- the byte bufferoffset
- position in the bufferb
- byte to write out- Returns:
- incremented offset
-
directBufferAddress
-
freeDirectBuffer
-