Package org.apache.hadoop.hbase.nio
Class SingleByteBuff
java.lang.Object
org.apache.hadoop.hbase.nio.ByteBuff
org.apache.hadoop.hbase.nio.SingleByteBuff
- All Implemented Interfaces:
HBaseReferenceCounted
,org.apache.hbase.thirdparty.io.netty.util.ReferenceCounted
An implementation of ByteBuff where a single BB backs the BBI. This just acts as a wrapper over a
normal BB - offheap or onheap
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.hadoop.hbase.nio.ByteBuff
ByteBuff.ChannelReader
-
Field Summary
Modifier and TypeFieldDescriptionprivate final ByteBuffer
private static final boolean
private static final boolean
private long
private Object
Fields inherited from class org.apache.hadoop.hbase.nio.ByteBuff
CHANNEL_READER, FILE_READER, refCnt
-
Constructor Summary
ConstructorDescriptionSingleByteBuff
(ByteBuffer buf) SingleByteBuff
(ByteBuffAllocator.Recycler recycler, ByteBuffer buf) SingleByteBuff
(RefCnt refCnt, ByteBuffer buf) -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
array()
Returns the byte[] if the underlying BB has single BB and hasArray trueint
Returns the arrayOffset of the byte[] incase of a single BB backed ByteBuffasSubByteBuffer
(int length) Returns bytes from current position till length specified, as a single ByteBuffer.void
asSubByteBuffer
(int offset, int length, ObjectIntPair<ByteBuffer> pair) Returns bytes from given offset till length specified, as a single ByteBuffer.int
capacity()
Returns the total capacity of this ByteBuff.Returns an ByteBuff which is a duplicate version of this ByteBuff.boolean
byte
get()
A relative method that returns byte at the current position.void
get
(byte[] dst) Copies the content from this ByteBuff's current position to the byte array and fills it.void
get
(byte[] dst, int offset, int length) Copies the specified number of bytes from this ByteBuff's current position to the byte[]'s offset.byte
get
(int index) Fetches the byte at the given index.void
get
(int sourceOffset, byte[] dst, int offset, int length) Copies the specified number of bytes from this ByteBuff's given position to the byte[]'s offset.void
get
(ByteBuffer out, int sourceOffset, int length) Copies the content from this ByteBuff to a ByteBuffer Note : This will advance the position marker ofout
but not change the position maker for this ByteBuffbyte
getByteAfterPosition
(int offset) Fetches the byte at the given offset from current position.int
getInt()
Returns the int value at the current position.int
getInt
(int index) Fetches the int at the given index.int
getIntAfterPosition
(int offset) Fetches the int value at the given offset from current position.long
getLong()
Returns the long value at the current position.long
getLong
(int index) Fetches the long at the given index.long
getLongAfterPosition
(int offset) Fetches the long value at the given offset from current position.short
getShort()
Returns the short value at the current position.short
getShort
(int index) Fetches the short value at the given index.short
getShortAfterPosition
(int offset) Fetches the short value at the given offset from current position.boolean
hasArray()
Returns true or false if the underlying BB support hasArrayint
hashCode()
boolean
Returns true if there are elements between the current position and the limit.int
limit()
Returns the limit of this ByteBufflimit
(int limit) Marks the limit of this ByteBuffmark()
Marks the current position of the ByteBuffmoveBack
(int len) Jumps back the current position of this ByteBuff by specified length.int
position()
Returns this ByteBuff's current positionposition
(int position) Sets this ByteBuff's position to the given value.put
(byte b) Writes a byte to this ByteBuff at the current position and increments the positionput
(byte[] src) Copies from the given byte[] to this ByteBuffput
(byte[] src, int offset, int length) Copies from the given byte[] to this ByteBuffput
(int index, byte b) Writes a byte to this ByteBuff at the given indexCopies the contents from the src ByteBuff to this ByteBuff.putInt
(int value) Writes an int to this ByteBuff at its current position.putLong
(long value) Writes a long to this ByteBuff at its current position.int
read
(FileChannel channel, long offset) Reads bytes from FileChannel into this ByteBuffint
read
(ReadableByteChannel channel) Reads bytes from the given channel into this ByteBuf.int
Returns the number of elements between the current position and the limit.reset()
Similar toByteBuffer
.reset(), ensures that this ByteBuff is reset back to last marked position.retain()
rewind()
Rewinds this ByteBuff and the position is set to 0skip
(int len) Jumps the current position of this ByteBuff by specified length.slice()
Returns an ByteBuff which is a sliced version of this ByteBuff.byte[]
toBytes
(int offset, int length) Copy the content from this ByteBuff to a byte[] based on the given offset and length.int
write
(FileChannel channel, long offset) Write this ByteBuff's data into target fileMethods inherited from class org.apache.hadoop.hbase.nio.ByteBuff
checkRefCount, compareTo, getRefCnt, read, readCompressedInt, readLong, refCnt, release, toBytes, toString, touch, touch, wrap, wrap, wrap, wrap, wrap, wrap
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.hadoop.hbase.nio.HBaseReferenceCounted
release, retain
-
Field Details
-
UNSAFE_AVAIL
-
UNSAFE_UNALIGNED
-
buf
-
unsafeOffset
-
unsafeRef
-
-
Constructor Details
-
SingleByteBuff
-
SingleByteBuff
-
SingleByteBuff
SingleByteBuff(RefCnt refCnt, ByteBuffer buf)
-
-
Method Details
-
position
Description copied from class:ByteBuff
Returns this ByteBuff's current position -
position
Description copied from class:ByteBuff
Sets this ByteBuff's position to the given value. -
skip
Description copied from class:ByteBuff
Jumps the current position of this ByteBuff by specified length. -
moveBack
Description copied from class:ByteBuff
Jumps back the current position of this ByteBuff by specified length. -
capacity
Description copied from class:ByteBuff
Returns the total capacity of this ByteBuff. -
limit
Description copied from class:ByteBuff
Returns the limit of this ByteBuff -
limit
Description copied from class:ByteBuff
Marks the limit of this ByteBuff -
rewind
Description copied from class:ByteBuff
Rewinds this ByteBuff and the position is set to 0 -
mark
Description copied from class:ByteBuff
Marks the current position of the ByteBuff -
asSubByteBuffer
Description copied from class:ByteBuff
Returns bytes from current position till length specified, as a single ByteBuffer. When all these bytes happen to be in a single ByteBuffer, which this object wraps, that ByteBuffer item as such will be returned. So users are warned not to change the position or limit of this returned ByteBuffer. The position of the returned byte buffer is at the begin of the required bytes. When the required bytes happen to span across multiple ByteBuffers, this API will copy the bytes to a newly created ByteBuffer of required size and return that.- Specified by:
asSubByteBuffer
in classByteBuff
- Parameters:
length
- number of bytes required.- Returns:
- bytes from current position till length specified, as a single ByteButter.
-
asSubByteBuffer
Description copied from class:ByteBuff
Returns bytes from given offset till length specified, as a single ByteBuffer. When all these bytes happen to be in a single ByteBuffer, which this object wraps, that ByteBuffer item as such will be returned (with offset in this ByteBuffer where the bytes starts). So users are warned not to change the position or limit of this returned ByteBuffer. When the required bytes happen to span across multiple ByteBuffers, this API will copy the bytes to a newly created ByteBuffer of required size and return that.- Specified by:
asSubByteBuffer
in classByteBuff
- Parameters:
offset
- the offset in this ByteBuff from where the subBuffer should be createdlength
- the length of the subBufferpair
- a pair that will have the bytes from the current position till length specified, as a single ByteBuffer and offset in that Buffer where the bytes starts. Since this API gets called in a loop we are passing a pair to it which could be created outside the loop and the method would set the values on the pair that is passed in by the caller. Thus it avoids more object creations that would happen if the pair that is returned is created by this method every time.
-
remaining
Description copied from class:ByteBuff
Returns the number of elements between the current position and the limit. -
hasRemaining
Description copied from class:ByteBuff
Returns true if there are elements between the current position and the limit.- Specified by:
hasRemaining
in classByteBuff
-
reset
Description copied from class:ByteBuff
Similar toByteBuffer
.reset(), ensures that this ByteBuff is reset back to last marked position. -
slice
Description copied from class:ByteBuff
Returns an ByteBuff which is a sliced version of this ByteBuff. The position, limit and mark of the new ByteBuff will be independent than that of the original ByteBuff. The content of the new ByteBuff will start at this ByteBuff's current position -
duplicate
Description copied from class:ByteBuff
Returns an ByteBuff which is a duplicate version of this ByteBuff. The position, limit and mark of the new ByteBuff will be independent than that of the original ByteBuff. The content of the new ByteBuff will start at this ByteBuff's current position The position, limit and mark of the new ByteBuff would be identical to this ByteBuff in terms of values. -
get
Description copied from class:ByteBuff
A relative method that returns byte at the current position. Increments the current position by the size of a byte. -
get
Description copied from class:ByteBuff
Fetches the byte at the given index. Does not change position of the underlying ByteBuffers -
getByteAfterPosition
Description copied from class:ByteBuff
Fetches the byte at the given offset from current position. Does not change position of the underlying ByteBuffers.- Specified by:
getByteAfterPosition
in classByteBuff
- Returns:
- the byte value at the given index.
-
put
Description copied from class:ByteBuff
Writes a byte to this ByteBuff at the current position and increments the position -
put
Description copied from class:ByteBuff
Writes a byte to this ByteBuff at the given index -
get
Description copied from class:ByteBuff
Copies the specified number of bytes from this ByteBuff's current position to the byte[]'s offset. Also advances the position of the ByteBuff by the given length. -
get
Description copied from class:ByteBuff
Copies the specified number of bytes from this ByteBuff's given position to the byte[]'s offset. The position of the ByteBuff remains in the current position only -
get
Description copied from class:ByteBuff
Copies the content from this ByteBuff's current position to the byte array and fills it. Also advances the position of the ByteBuff by the length of the byte[]. -
put
Description copied from class:ByteBuff
Copies the contents from the src ByteBuff to this ByteBuff. This will be absolute positional copying and won't affect the position of any of the buffers. -
put
Description copied from class:ByteBuff
Copies from the given byte[] to this ByteBuff -
put
Description copied from class:ByteBuff
Copies from the given byte[] to this ByteBuff -
hasArray
Description copied from class:ByteBuff
Returns true or false if the underlying BB support hasArray -
array
Description copied from class:ByteBuff
Returns the byte[] if the underlying BB has single BB and hasArray true -
arrayOffset
Description copied from class:ByteBuff
Returns the arrayOffset of the byte[] incase of a single BB backed ByteBuff- Specified by:
arrayOffset
in classByteBuff
-
getShort
Description copied from class:ByteBuff
Returns the short value at the current position. Also advances the position by the size of short. -
getShort
Description copied from class:ByteBuff
Fetches the short value at the given index. Does not change position of the underlying ByteBuffers. The caller is sure that the index will be after the current position of this ByteBuff. So even if the current short does not fit in the current item we can safely move to the next item and fetch the remaining bytes forming the short -
getShortAfterPosition
Description copied from class:ByteBuff
Fetches the short value at the given offset from current position. Does not change position of the underlying ByteBuffers.- Specified by:
getShortAfterPosition
in classByteBuff
- Returns:
- the short value at the given index.
-
getInt
Description copied from class:ByteBuff
Returns the int value at the current position. Also advances the position by the size of int. -
putInt
Description copied from class:ByteBuff
Writes an int to this ByteBuff at its current position. Also advances the position by size of int. -
getInt
Description copied from class:ByteBuff
Fetches the int at the given index. Does not change position of the underlying ByteBuffers. Even if the current int does not fit in the current item we can safely move to the next item and fetch the remaining bytes forming the int. -
getIntAfterPosition
Description copied from class:ByteBuff
Fetches the int value at the given offset from current position. Does not change position of the underlying ByteBuffers.- Specified by:
getIntAfterPosition
in classByteBuff
-
getLong
Description copied from class:ByteBuff
Returns the long value at the current position. Also advances the position by the size of long. -
putLong
Description copied from class:ByteBuff
Writes a long to this ByteBuff at its current position. Also advances the position by size of long. -
getLong
Description copied from class:ByteBuff
Fetches the long at the given index. Does not change position of the underlying ByteBuffers. The caller is sure that the index will be after the current position of this ByteBuff. So even if the current long does not fit in the current item we can safely move to the next item and fetch the remaining bytes forming the long -
getLongAfterPosition
Description copied from class:ByteBuff
Fetches the long value at the given offset from current position. Does not change position of the underlying ByteBuffers.- Specified by:
getLongAfterPosition
in classByteBuff
- Returns:
- the long value at the given index.
-
toBytes
Description copied from class:ByteBuff
Copy the content from this ByteBuff to a byte[] based on the given offset and length. -
get
Description copied from class:ByteBuff
Copies the content from this ByteBuff to a ByteBuffer Note : This will advance the position marker ofout
but not change the position maker for this ByteBuff -
read
Description copied from class:ByteBuff
Reads bytes from the given channel into this ByteBuf.- Specified by:
read
in classByteBuff
- Throws:
IOException
-
read
Description copied from class:ByteBuff
Reads bytes from FileChannel into this ByteBuff- Specified by:
read
in classByteBuff
- Throws:
IOException
-
write
Description copied from class:ByteBuff
Write this ByteBuff's data into target file- Specified by:
write
in classByteBuff
- Throws:
IOException
-
nioByteBuffers
- Specified by:
nioByteBuffers
in classByteBuff
-
equals
-
hashCode
-
retain
-