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
Modifier and TypeFieldDescriptionprivate Iterator<ByteBuffer>
private ByteBuffer
private int
private final int[]
private final ByteBuffer[]
private int
private int
private int
Fields inherited from class org.apache.hadoop.hbase.nio.ByteBuff
CHANNEL_READER, FILE_READER, refCnt
-
Constructor Summary
ModifierConstructorDescriptionMultiByteBuff
(ByteBuffer... items) MultiByteBuff
(ByteBuffAllocator.Recycler recycler, ByteBuffer... items) (package private)
MultiByteBuff
(RefCnt refCnt, ByteBuffer... items) private
MultiByteBuff
(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 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 MultiByteBuffer.Returns an MBB which is a duplicate version of this MBB.boolean
byte
get()
A relative method that returns byte at the current position.void
get
(byte[] dst) Copies the content from this MBB'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 MBB'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 an this MBB to a ByteBufferbyte
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.private int
getInt
(int index, int itemIndex) int
getIntAfterPosition
(int offset) Fetches the int value at the given offset from current position.private static ByteBuffer
getItemByteBuffer
(ByteBuff buf, int byteBufferIndex) private static int
private int
getItemIndex
(int elemIndex) private static int
getItemIndexForByteBuff
(ByteBuff byteBuff, int offset, int length) private int
getItemIndexFromCurItemIndex
(int elemIndex) long
getLong()
Returns the long value at the current position.long
getLong
(int index) Fetches the long at the given index.private long
getLong
(int index, int itemIndex) long
getLongAfterPosition
(int offset) Fetches the long value at the given offset from current position.private int
getRelativeOffset
(int globalOffset, int itemIndex) private static int
getRelativeOffsetForByteBuff
(ByteBuff byteBuff, int globalOffset, int itemIndex) short
getShort()
Returns the short value at the current position.short
getShort
(int index) Fetches the short at the given index.private short
getShort
(int index, int itemIndex) short
getShortAfterPosition
(int offset) Fetches the short value at the given offset from current position.boolean
hasArray()
Returns false.int
hashCode()
final boolean
Returns true if there are elements between the current position and the limtprivate static byte
int0
(int x) private static byte
int1
(int x) private static byte
int2
(int x) private static byte
int3
(int x) private int
internalRead
(ReadableByteChannel channel, long offset, ByteBuff.ChannelReader reader) int
limit()
Returns the limit of this MBBlimit
(int limit) Marks the limit of this MBB.private static byte
long0
(long x) private static byte
long1
(long x) private static byte
long2
(long x) private static byte
long3
(long x) private static byte
long4
(long x) private static byte
long5
(long x) private static byte
long6
(long x) private static byte
long7
(long x) mark()
Marks the current position of the MBBmoveBack
(int length) Jumps back the current position of this MBB by specified length.int
position()
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 MultiByteBuff
put
(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.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 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 doneint
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
-
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:ByteBuff
Returns the byte[] if the underlying BB has single BB and hasArray true- Specified by:
array
in classByteBuff
- Throws:
UnsupportedOperationException
- MBB does not support array based operations
-
arrayOffset
Description copied from class:ByteBuff
Returns the arrayOffset of the byte[] incase of a single BB backed ByteBuff- Specified by:
arrayOffset
in 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: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.
-
getItemIndex
-
getItemIndexFromCurItemIndex
-
getInt
Fetches the int at the given index. Does not change position of the underlying ByteBuffers -
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
-
getShort
Fetches the short at the given index. Does not change position of the underlying ByteBuffers -
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
-
getShort
-
getLong
-
getLong
Fetches the long at the given index. Does not change position of the underlying ByteBuffers -
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.
-
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:
hasRemaining
in 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: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 -
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:
put
in 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:
put
in 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:
asSubByteBuffer
in 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:
asSubByteBuffer
in 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: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
-