Package org.apache.hadoop.hbase.util
Class UnsafeAccess
java.lang.Object
org.apache.hadoop.hbase.util.UnsafeAccess
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe offset to the first element in a byte array.static final boolean(package private) static final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcopy(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 voidcopy(ByteBuffer src, int srcOffset, byte[] dest, int destOffset, int length) Copies specified number of bytes from given offset ofsrcByteBuffer to thedestarray.static voidcopy(ByteBuffer src, int srcOffset, ByteBuffer dest, int destOffset, int length) Copies specified number of bytes from given offset ofsrcbuffer into thedestbuffer.static longstatic voidfreeDirectBuffer(ByteBuffer buffer) private static intgetAsInt(ByteBuffer buf, int offset) Reads bytes at the given offset as an int value.private static longgetAsLong(ByteBuffer buf, int offset) Reads bytes at the given offset as a long value.private static shortgetAsShort(ByteBuffer buf, int offset) Reads bytes at the given offset as a short value.static intputByte(ByteBuffer buf, int offset, byte b) Put a byte value out to the specified BB position in big-endian format.static intputInt(byte[] bytes, int offset, int val) Put an int value out to the specified byte array position in big-endian format.static intputInt(ByteBuffer buf, int offset, int val) Put an int value out to the specified ByteBuffer offset in big-endian format.static intputLong(byte[] bytes, int offset, long val) Put a long value out to the specified byte array position in big-endian format.static intputLong(ByteBuffer buf, int offset, long val) Put a long value out to the specified BB position in big-endian format.static intputShort(byte[] bytes, int offset, short val) Put a short value out to the specified byte array position in big-endian format.static intputShort(ByteBuffer buf, int offset, short val) Put a short value out to the specified BB position in big-endian format.static byteReturns the byte at the given offset of the objectstatic bytetoByte(ByteBuffer buf, int offset) Returns the byte at the given offsetstatic inttoInt(byte[] bytes, int offset) Converts a byte array to an int value considering it was written in big-endian format.static intReads a int value at the given Object's offset considering it was written in big-endian format.static inttoInt(ByteBuffer buf, int offset) Reads an int value at the given buffer's offset considering it was written in big-endian format.static longtoLong(byte[] bytes, int offset) Converts a byte array to a long value considering it was written in big-endian format.static longReads a long value at the given Object's offset considering it was written in big-endian format.static longtoLong(ByteBuffer buf, int offset) Reads a long value at the given buffer's offset considering it was written in big-endian format.static shorttoShort(byte[] bytes, int offset) Converts a byte array to a short value considering it was written in big-endian format.static shortReads a short value at the given Object's offset considering it was written in big-endian format.static shorttoShort(ByteBuffer buf, int offset) Reads a short value at the given buffer's offset considering it was written in big-endian format.private static voidunsafeCopy(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 ofsrcByteBuffer to thedestarray.- 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 ofsrcbuffer into thedestbuffer.- 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
-