@InterfaceAudience.Private public class MultiByteBuff extends ByteBuff
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.ByteBuff.ChannelReader
Modifier and Type | Field and Description |
---|---|
private Iterator<ByteBuffer> |
buffsIterator |
private ByteBuffer |
curItem |
private int |
curItemIndex |
private int[] |
itemBeginPos |
private ByteBuffer[] |
items |
private int |
limit |
private int |
limitedItemIndex |
private int |
markedItemIndex |
CHANNEL_READER, FILE_READER, refCnt
Modifier | Constructor and Description |
---|---|
|
MultiByteBuff(ByteBuffAllocator.Recycler recycler,
ByteBuffer... items) |
|
MultiByteBuff(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) |
Modifier and Type | Method and Description |
---|---|
byte[] |
array()
Returns the byte[] if the underlying BB has single BB and hasArray true
|
int |
arrayOffset()
Returns the arrayOffset of the byte[] incase of a single BB backed ByteBuff
|
ByteBuffer |
asSubByteBuffer(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.
|
MultiByteBuff |
duplicate()
Returns an MBB which is a duplicate version of this MBB.
|
boolean |
equals(Object obj) |
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.
|
void |
get(ByteBuffer out,
int sourceOffset,
int length)
Copies the content from an this MBB to a ByteBuffer
|
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.
|
byte |
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 |
getItemByteBufferCount(ByteBuff buf) |
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() |
boolean |
hasRemaining()
Returns true if there are elements between the current position and the limt
|
private 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 MBB
|
MultiByteBuff |
limit(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) |
MultiByteBuff |
mark()
Marks the current position of the MBB
|
MultiByteBuff |
moveBack(int length)
Jumps back the current position of this MBB by specified length.
|
ByteBuffer[] |
nioByteBuffers() |
int |
position()
Returns this MBB's current position
|
MultiByteBuff |
position(int position)
Sets this MBB's position to the given value.
|
MultiByteBuff |
put(byte b)
Writes a byte to this MBB at the current position and increments the position n * @return this
object
|
MultiByteBuff |
put(byte[] src)
Copies from the given byte[] to this MBB
|
MultiByteBuff |
put(byte[] src,
int offset,
int length)
Copies from the given byte[] to this MBB.
|
MultiByteBuff |
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.
|
MultiByteBuff |
put(int destOffset,
ByteBuff src,
int srcOffset,
int length)
Copies from a src BB to this MBB.
|
MultiByteBuff |
putInt(int val)
Writes an int to this MBB at its current position.
|
MultiByteBuff |
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 ByteBuff
|
int |
read(ReadableByteChannel channel)
Reads bytes from the given channel into this ByteBuf.
|
int |
remaining()
Returns the number of elements between the current position and the limit.
|
MultiByteBuff |
reset()
Similar to
ByteBuffer .reset(), ensures that this MBB is reset back to last marked
position. |
MultiByteBuff |
retain() |
MultiByteBuff |
rewind()
Rewinds this MBB and the position is set to 0
|
MultiByteBuff |
skip(int length)
Jumps the current position of this MBB by specified length.
|
MultiByteBuff |
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 n * the
position from where the copy should start n * the length upto which the copy has to be done
|
int |
write(FileChannel channel,
long offset)
Write this ByteBuff's data into target file
|
checkRefCount, compareTo, getRefCnt, read, readCompressedInt, readLong, refCnt, release, toBytes, toString, touch, touch, wrap, wrap, wrap, wrap, wrap, wrap
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
release, retain
private final ByteBuffer[] items
private ByteBuffer curItem
private int curItemIndex
private int limit
private int limitedItemIndex
private int markedItemIndex
private final int[] itemBeginPos
private Iterator<ByteBuffer> buffsIterator
public MultiByteBuff(ByteBuffer... items)
public MultiByteBuff(ByteBuffAllocator.Recycler recycler, ByteBuffer... items)
MultiByteBuff(RefCnt refCnt, ByteBuffer... items)
private MultiByteBuff(RefCnt refCnt, ByteBuffer[] items, int[] itemBeginPos, int limit, int limitedIndex, int curItemIndex, int markedIndex)
public byte[] array()
ByteBuff
array
in class ByteBuff
UnsupportedOperationException
- MBB does not support array based operationspublic int arrayOffset()
ByteBuff
arrayOffset
in class ByteBuff
UnsupportedOperationException
- MBB does not support array based operationspublic boolean hasArray()
public int capacity()
public byte get(int index)
public byte getByteAfterPosition(int offset)
ByteBuff
getByteAfterPosition
in class ByteBuff
private int getItemIndex(int elemIndex)
private int getItemIndexFromCurItemIndex(int elemIndex)
public int getInt(int index)
public int getIntAfterPosition(int offset)
ByteBuff
getIntAfterPosition
in class ByteBuff
public short getShort(int index)
public short getShortAfterPosition(int offset)
ByteBuff
getShortAfterPosition
in class ByteBuff
private int getInt(int index, int itemIndex)
private short getShort(int index, int itemIndex)
private long getLong(int index, int itemIndex)
public long getLong(int index)
public long getLongAfterPosition(int offset)
ByteBuff
getLongAfterPosition
in class ByteBuff
public int position()
public MultiByteBuff position(int position)
public MultiByteBuff rewind()
public MultiByteBuff mark()
public MultiByteBuff reset()
ByteBuffer
.reset(), ensures that this MBB is reset back to last marked
position.public int remaining()
public final boolean hasRemaining()
hasRemaining
in class ByteBuff
public byte get()
public short getShort()
public int getInt()
public long getLong()
public void get(byte[] dst)
public void get(byte[] dst, int offset, int length)
public void get(int sourceOffset, byte[] dst, int offset, int length)
ByteBuff
public MultiByteBuff limit(int limit)
public int limit()
public MultiByteBuff slice()
public MultiByteBuff duplicate()
public MultiByteBuff put(byte b)
public MultiByteBuff put(int index, byte b)
put
in class ByteBuff
IndexOutOfBoundsException
- If index is negative or not smaller than the
limit
public MultiByteBuff put(int destOffset, ByteBuff src, int srcOffset, int length)
put
in class ByteBuff
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 happenBufferUnderflowException
- If there are fewer than length bytes remaining in src
ByteBuff.BufferOverflowException
- If there is insufficient available space in this MBB for
length bytes.private static ByteBuffer getItemByteBuffer(ByteBuff buf, int byteBufferIndex)
private static int getItemIndexForByteBuff(ByteBuff byteBuff, int offset, int length)
private static int getRelativeOffsetForByteBuff(ByteBuff byteBuff, int globalOffset, int itemIndex)
private int getRelativeOffset(int globalOffset, int itemIndex)
private static int getItemByteBufferCount(ByteBuff buf)
public MultiByteBuff putInt(int val)
private static byte int3(int x)
private static byte int2(int x)
private static byte int1(int x)
private static byte int0(int x)
public final MultiByteBuff put(byte[] src)
public MultiByteBuff put(byte[] src, int offset, int length)
public MultiByteBuff putLong(long val)
private static byte long7(long x)
private static byte long6(long x)
private static byte long5(long x)
private static byte long4(long x)
private static byte long3(long x)
private static byte long2(long x)
private static byte long1(long x)
private static byte long0(long x)
public MultiByteBuff skip(int length)
public MultiByteBuff moveBack(int length)
public ByteBuffer asSubByteBuffer(int length)
asSubByteBuffer
in class ByteBuff
length
- number of bytes required.public void asSubByteBuffer(int offset, int length, ObjectIntPair<ByteBuffer> pair)
asSubByteBuffer
in class ByteBuff
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 callerpublic void get(ByteBuffer out, int sourceOffset, int length)
public byte[] toBytes(int offset, int length)
private int internalRead(ReadableByteChannel channel, long offset, ByteBuff.ChannelReader reader) throws IOException
IOException
public int read(ReadableByteChannel channel) throws IOException
ByteBuff
read
in class ByteBuff
IOException
public int read(FileChannel channel, long offset) throws IOException
ByteBuff
read
in class ByteBuff
IOException
public int write(FileChannel channel, long offset) throws IOException
ByteBuff
write
in class ByteBuff
IOException
public ByteBuffer[] nioByteBuffers()
nioByteBuffers
in class ByteBuff
public MultiByteBuff retain()
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.