@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.Modifier and Type | Field and Description |
---|---|
private ByteBuffer |
curItem |
private int |
curItemIndex |
private int[] |
itemBeginPos |
private ByteBuffer[] |
items |
private int |
limit |
private int |
limitedItemIndex |
private int |
markedItemIndex |
Modifier | Constructor and Description |
---|---|
|
MultiByteBuff(ByteBuffer... items) |
private |
MultiByteBuff(ByteBuffer[] items,
int[] itemBeginPos,
int limit,
int limitedIndex,
int curItemIndex,
int markedIndex) |
Modifier and Type | Method and Description |
---|---|
byte[] |
array() |
int |
arrayOffset() |
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() |
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.
|
ByteBuffer[] |
getEnclosingByteBuffers() |
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 index) |
private int |
getItemIndex(int elemIndex) |
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.
|
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() |
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) |
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.
|
int |
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
|
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
|
MultiByteBuff |
put(int offset,
ByteBuff src,
int srcOffset,
int length)
Copies from a src MBB 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(ReadableByteChannel channel)
Reads bytes from the given channel into this ByteBuff
|
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 |
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
|
channelRead, compareTo, readCompressedInt, readLong, readVLong, toBytes, toString, toStringBinary, unsignedBinarySearch
private final ByteBuffer[] items
private ByteBuffer curItem
private int curItemIndex
private int limit
private int limitedItemIndex
private int markedItemIndex
private final int[] itemBeginPos
public MultiByteBuff(ByteBuffer... items)
private MultiByteBuff(ByteBuffer[] items, int[] itemBeginPos, int limit, int limitedIndex, int curItemIndex, int markedIndex)
public byte[] array()
array
in class ByteBuff
UnsupportedOperationException
- MBB does not support
array based operationspublic int arrayOffset()
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)
public MultiByteBuff put(int offset, ByteBuff src, int srcOffset, int length)
private static ByteBuffer getItemByteBuffer(ByteBuff buf, int index)
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)
public int read(ReadableByteChannel channel) throws IOException
ByteBuff
read
in class ByteBuff
IOException
public ByteBuffer[] getEnclosingByteBuffers()
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.