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
FieldsModifier and TypeFieldDescriptionprivate final ByteBufferprivate static final booleanprivate static final booleanprivate longprivate ObjectFields inherited from class org.apache.hadoop.hbase.nio.ByteBuff
CHANNEL_READER, FILE_READER, refCnt -
Constructor Summary
ConstructorsConstructorDescriptionSingleByteBuff(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 trueintReturns 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.voidasSubByteBuffer(int offset, int length, ObjectIntPair<ByteBuffer> pair) Returns bytes from given offset till length specified, as a single ByteBuffer.intcapacity()Returns the total capacity of this ByteBuff.Returns an ByteBuff which is a duplicate version of this ByteBuff.booleanbyteget()A relative method that returns byte at the current position.voidget(byte[] dst) Copies the content from this ByteBuff's current position to the byte array and fills it.voidget(byte[] dst, int offset, int length) Copies the specified number of bytes from this ByteBuff's current position to the byte[]'s offset.byteget(int index) Fetches the byte at the given index.voidget(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.voidget(ByteBuffer out, int sourceOffset, int length) Copies the content from this ByteBuff to a ByteBuffer Note : This will advance the position marker ofoutbut not change the position maker for this ByteBuffbytegetByteAfterPosition(int offset) Fetches the byte at the given offset from current position.intgetInt()Returns the int value at the current position.intgetInt(int index) Fetches the int at the given index.intgetIntAfterPosition(int offset) Fetches the int value at the given offset from current position.longgetLong()Returns the long value at the current position.longgetLong(int index) Fetches the long at the given index.longgetLongAfterPosition(int offset) Fetches the long value at the given offset from current position.shortgetShort()Returns the short value at the current position.shortgetShort(int index) Fetches the short value at the given index.shortgetShortAfterPosition(int offset) Fetches the short value at the given offset from current position.booleanhasArray()Returns true or false if the underlying BB support hasArrayinthashCode()booleanReturns true if there are elements between the current position and the limit.intlimit()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.intposition()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.intread(FileChannel channel, long offset) Reads bytes from FileChannel into this ByteBuffintread(ReadableByteChannel channel) Reads bytes from the given channel into this ByteBuf.intReturns 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.intwrite(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, wrapMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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:ByteBuffReturns this ByteBuff's current position -
position
Description copied from class:ByteBuffSets this ByteBuff's position to the given value. -
skip
Description copied from class:ByteBuffJumps the current position of this ByteBuff by specified length. -
moveBack
Description copied from class:ByteBuffJumps back the current position of this ByteBuff by specified length. -
capacity
Description copied from class:ByteBuffReturns the total capacity of this ByteBuff. -
limit
Description copied from class:ByteBuffReturns the limit of this ByteBuff -
limit
Description copied from class:ByteBuffMarks the limit of this ByteBuff -
rewind
Description copied from class:ByteBuffRewinds this ByteBuff and the position is set to 0 -
mark
Description copied from class:ByteBuffMarks the current position of the ByteBuff -
asSubByteBuffer
Description copied from class:ByteBuffReturns 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:
asSubByteBufferin classByteBuff- Parameters:
length- number of bytes required.- Returns:
- bytes from current position till length specified, as a single ByteButter.
-
asSubByteBuffer
Description copied from class:ByteBuffReturns 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:
asSubByteBufferin 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:ByteBuffReturns the number of elements between the current position and the limit. -
hasRemaining
Description copied from class:ByteBuffReturns true if there are elements between the current position and the limit.- Specified by:
hasRemainingin classByteBuff
-
reset
Description copied from class:ByteBuffSimilar toByteBuffer.reset(), ensures that this ByteBuff is reset back to last marked position. -
slice
Description copied from class:ByteBuffReturns 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:ByteBuffReturns 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:ByteBuffA relative method that returns byte at the current position. Increments the current position by the size of a byte. -
get
Description copied from class:ByteBuffFetches the byte at the given index. Does not change position of the underlying ByteBuffers -
getByteAfterPosition
Description copied from class:ByteBuffFetches the byte at the given offset from current position. Does not change position of the underlying ByteBuffers.- Specified by:
getByteAfterPositionin classByteBuff- Returns:
- the byte value at the given index.
-
put
Description copied from class:ByteBuffWrites a byte to this ByteBuff at the current position and increments the position -
put
Description copied from class:ByteBuffWrites a byte to this ByteBuff at the given index -
get
Description copied from class:ByteBuffCopies 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:ByteBuffCopies 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:ByteBuffCopies 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:ByteBuffCopies 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:ByteBuffCopies from the given byte[] to this ByteBuff -
put
Description copied from class:ByteBuffCopies from the given byte[] to this ByteBuff -
hasArray
Description copied from class:ByteBuffReturns true or false if the underlying BB support hasArray -
array
Description copied from class:ByteBuffReturns the byte[] if the underlying BB has single BB and hasArray true -
arrayOffset
Description copied from class:ByteBuffReturns the arrayOffset of the byte[] incase of a single BB backed ByteBuff- Specified by:
arrayOffsetin classByteBuff
-
getShort
Description copied from class:ByteBuffReturns the short value at the current position. Also advances the position by the size of short. -
getShort
Description copied from class:ByteBuffFetches 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:ByteBuffFetches the short value at the given offset from current position. Does not change position of the underlying ByteBuffers.- Specified by:
getShortAfterPositionin classByteBuff- Returns:
- the short value at the given index.
-
getInt
Description copied from class:ByteBuffReturns the int value at the current position. Also advances the position by the size of int. -
putInt
Description copied from class:ByteBuffWrites an int to this ByteBuff at its current position. Also advances the position by size of int. -
getInt
Description copied from class:ByteBuffFetches 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:ByteBuffFetches the int value at the given offset from current position. Does not change position of the underlying ByteBuffers.- Specified by:
getIntAfterPositionin classByteBuff
-
getLong
Description copied from class:ByteBuffReturns the long value at the current position. Also advances the position by the size of long. -
putLong
Description copied from class:ByteBuffWrites a long to this ByteBuff at its current position. Also advances the position by size of long. -
getLong
Description copied from class:ByteBuffFetches 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:ByteBuffFetches the long value at the given offset from current position. Does not change position of the underlying ByteBuffers.- Specified by:
getLongAfterPositionin classByteBuff- Returns:
- the long value at the given index.
-
toBytes
Description copied from class:ByteBuffCopy the content from this ByteBuff to a byte[] based on the given offset and length. -
get
Description copied from class:ByteBuffCopies the content from this ByteBuff to a ByteBuffer Note : This will advance the position marker ofoutbut not change the position maker for this ByteBuff -
read
Description copied from class:ByteBuffReads bytes from the given channel into this ByteBuf.- Specified by:
readin classByteBuff- Throws:
IOException
-
read
Description copied from class:ByteBuffReads bytes from FileChannel into this ByteBuff- Specified by:
readin classByteBuff- Throws:
IOException
-
write
Description copied from class:ByteBuffWrite this ByteBuff's data into target file- Specified by:
writein classByteBuff- Throws:
IOException
-
nioByteBuffers
- Specified by:
nioByteBuffersin classByteBuff
-
equals
-
hashCode
-
retain
-