Package org.apache.hadoop.hbase.nio
Class MultiByteBuff
java.lang.Object
org.apache.hadoop.hbase.nio.ByteBuff
org.apache.hadoop.hbase.nio.MultiByteBuff
- All Implemented Interfaces:
HBaseReferenceCounted,org.apache.hbase.thirdparty.io.netty.util.ReferenceCounted
Provides a unified view of all the underlying ByteBuffers and will look as if a bigger sequential
buffer. This class provides similar APIs as in
ByteBuffer to put/get int, short, long etc
and doing operations like mark, reset, slice etc. This has to be used when data is split across
multiple byte buffers and we don't want copy them to single buffer for reading from it.-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.hadoop.hbase.nio.ByteBuff
ByteBuff.ChannelReader -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Iterator<ByteBuffer>private ByteBufferprivate intprivate final int[]private final ByteBuffer[]private intprivate intprivate intFields inherited from class org.apache.hadoop.hbase.nio.ByteBuff
CHANNEL_READER, FILE_READER, refCnt -
Constructor Summary
ConstructorsModifierConstructorDescriptionMultiByteBuff(ByteBuffer... items) MultiByteBuff(ByteBuffAllocator.Recycler recycler, ByteBuffer... items) (package private)MultiByteBuff(RefCnt refCnt, ByteBuffer... items) privateMultiByteBuff(RefCnt refCnt, ByteBuffer[] items, int[] itemBeginPos, int limit, int limitedIndex, int curItemIndex, int markedIndex) -
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 MultiByteBuffer.Returns an MBB which is a duplicate version of this MBB.booleanbyteget()A relative method that returns byte at the current position.voidget(byte[] dst) Copies the content from this MBB'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 MBB'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 an this MBB to a ByteBufferbytegetByteAfterPosition(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.private intgetInt(int index, int itemIndex) intgetIntAfterPosition(int offset) Fetches the int value at the given offset from current position.private static ByteBuffergetItemByteBuffer(ByteBuff buf, int byteBufferIndex) private static intprivate intgetItemIndex(int elemIndex) private static intgetItemIndexForByteBuff(ByteBuff byteBuff, int offset, int length) private intgetItemIndexFromCurItemIndex(int elemIndex) longgetLong()Returns the long value at the current position.longgetLong(int index) Fetches the long at the given index.private longgetLong(int index, int itemIndex) longgetLongAfterPosition(int offset) Fetches the long value at the given offset from current position.private intgetRelativeOffset(int globalOffset, int itemIndex) private static intgetRelativeOffsetForByteBuff(ByteBuff byteBuff, int globalOffset, int itemIndex) shortgetShort()Returns the short value at the current position.shortgetShort(int index) Fetches the short at the given index.private shortgetShort(int index, int itemIndex) shortgetShortAfterPosition(int offset) Fetches the short value at the given offset from current position.booleanhasArray()Returns false.inthashCode()final booleanReturns true if there are elements between the current position and the limtprivate static byteint0(int x) private static byteint1(int x) private static byteint2(int x) private static byteint3(int x) private intinternalRead(ReadableByteChannel channel, long offset, ByteBuff.ChannelReader reader) intlimit()Returns the limit of this MBBlimit(int limit) Marks the limit of this MBB.private static bytelong0(long x) private static bytelong1(long x) private static bytelong2(long x) private static bytelong3(long x) private static bytelong4(long x) private static bytelong5(long x) private static bytelong6(long x) private static bytelong7(long x) mark()Marks the current position of the MBBmoveBack(int length) Jumps back the current position of this MBB by specified length.intposition()Returns this MBB's current positionposition(int position) Sets this MBB's position to the given value.put(byte b) Writes a byte to this MBB at the current position and increments the positionfinal MultiByteBuffput(byte[] src) Copies from the given byte[] to this MBBput(byte[] src, int offset, int length) Copies from the given byte[] to this MBB.put(int index, byte b) Writes a byte to this MBB at the given index and won't affect the position of any of the buffers.Copies from a src BB to this MBB.putInt(int val) Writes an int to this MBB at its current position.putLong(long val) Writes a long to this MBB 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 MBB is reset back to last marked position.retain()rewind()Rewinds this MBB and the position is set to 0skip(int length) Jumps the current position of this MBB by specified length.slice()Returns an MBB which is a sliced version of this MBB.byte[]toBytes(int offset, int length) Copy the content from this MBB to a byte[] based on the given offset and length the position from where the copy should start the length upto which the copy has to be doneintwrite(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
-
items
-
curItem
-
curItemIndex
-
limit
-
limitedItemIndex
-
markedItemIndex
-
itemBeginPos
-
buffsIterator
-
-
Constructor Details
-
MultiByteBuff
-
MultiByteBuff
-
MultiByteBuff
MultiByteBuff(RefCnt refCnt, ByteBuffer... items) -
MultiByteBuff
private MultiByteBuff(RefCnt refCnt, ByteBuffer[] items, int[] itemBeginPos, int limit, int limitedIndex, int curItemIndex, int markedIndex)
-
-
Method Details
-
array
Description copied from class:ByteBuffReturns the byte[] if the underlying BB has single BB and hasArray true- Specified by:
arrayin classByteBuff- Throws:
UnsupportedOperationException- MBB does not support array based operations
-
arrayOffset
Description copied from class:ByteBuffReturns the arrayOffset of the byte[] incase of a single BB backed ByteBuff- Specified by:
arrayOffsetin classByteBuff- Throws:
UnsupportedOperationException- MBB does not support array based operations
-
hasArray
Returns false. MBB does not support array based operations -
capacity
Returns the total capacity of this MultiByteBuffer. -
get
Fetches 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.
-
getItemIndex
-
getItemIndexFromCurItemIndex
-
getInt
Fetches the int at the given index. Does not change position of the underlying ByteBuffers -
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
-
getShort
Fetches the short at the given index. Does not change position of the underlying ByteBuffers -
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
-
getShort
-
getLong
-
getLong
Fetches the long at the given index. Does not change position of the underlying ByteBuffers -
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.
-
position
Returns this MBB's current position -
position
Sets this MBB's position to the given value. -
rewind
Rewinds this MBB and the position is set to 0 -
mark
Marks the current position of the MBB -
reset
Similar toByteBuffer.reset(), ensures that this MBB is reset back to last marked position. -
remaining
Returns the number of elements between the current position and the limit. -
hasRemaining
Returns true if there are elements between the current position and the limt- Specified by:
hasRemainingin classByteBuff- Returns:
- true if there are elements, false otherwise
-
get
A relative method that returns byte at the current position. Increments the current position by the size of a byte. -
getShort
Returns the short value at the current position. Also advances the position by the size of short -
getInt
Returns the int value at the current position. Also advances the position by the size of int -
getLong
Returns the long value at the current position. Also advances the position by the size of long -
get
Copies the content from this MBB's current position to the byte array and fills it. Also advances the position of the MBB by the length of the byte[]. -
get
Copies the specified number of bytes from this MBB's current position to the byte[]'s offset. Also advances the position of the MBB 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 -
limit
Marks the limit of this MBB. -
limit
Returns the limit of this MBB -
slice
Returns an MBB which is a sliced version of this MBB. The position, limit and mark of the new MBB will be independent than that of the original MBB. The content of the new MBB will start at this MBB's current position -
duplicate
Returns an MBB which is a duplicate version of this MBB. The position, limit and mark of the new MBB will be independent than that of the original MBB. The content of the new MBB will start at this MBB's current position The position, limit and mark of the new MBB would be identical to this MBB in terms of values. -
put
Writes a byte to this MBB at the current position and increments the position -
put
Writes a byte to this MBB at the given index and won't affect the position of any of the buffers.- Specified by:
putin classByteBuff- Returns:
- this object
- Throws:
IndexOutOfBoundsException- If index is negative or not smaller than thelimit
-
put
Copies from a src BB to this MBB. This will be absolute positional copying and won't affect the position of any of the buffers.- Specified by:
putin classByteBuff- Parameters:
destOffset- the position in this MBB to which the copy should happensrc- the src MBBsrcOffset- the offset in the src MBB from where the elements should be readlength- the length upto which the copy should happen- Throws:
BufferUnderflowException- If there are fewer than length bytes remaining in src ByteBuff.BufferOverflowException- If there is insufficient available space in this MBB for length bytes.
-
getItemByteBuffer
-
getItemIndexForByteBuff
-
getRelativeOffsetForByteBuff
-
getRelativeOffset
-
getItemByteBufferCount
-
putInt
Writes an int to this MBB at its current position. Also advances the position by size of int -
int3
-
int2
-
int1
-
int0
-
put
Copies from the given byte[] to this MBB -
put
Copies from the given byte[] to this MBB. -
putLong
Writes a long to this MBB at its current position. Also advances the position by size of long -
long7
-
long6
-
long5
-
long4
-
long3
-
long2
-
long1
-
long0
-
skip
Jumps the current position of this MBB by specified length. -
moveBack
Jumps back the current position of this MBB by specified length. -
asSubByteBuffer
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:
asSubByteBufferin classByteBuff- Parameters:
length- number of bytes required.- Returns:
- bytes from current position till length specified, as a single ByteButter.
-
asSubByteBuffer
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:
asSubByteBufferin classByteBuff- Parameters:
offset- the offset in this MBB 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. The method would set the values on the pair that is passed in by the caller
-
get
Copies the content from an this MBB to a ByteBuffer -
toBytes
Copy the content from this MBB to a byte[] based on the given offset and length the position from where the copy should start the length upto which the copy has to be done -
internalRead
private int internalRead(ReadableByteChannel channel, long offset, ByteBuff.ChannelReader reader) throws IOException - Throws:
IOException
-
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
-