@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.Constructor and Description |
---|
MultiByteBuff(ByteBuffer... items) |
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.
|
int |
getIntAfterPosition(int offset)
Fetches the int value at the given offset from current position.
|
long |
getLong()
Returns the long value at the current position.
|
long |
getLong(int index)
Fetches the long at the given index.
|
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.
|
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
|
int |
limit()
Returns the limit of this MBB
|
MultiByteBuff |
limit(int limit)
Marks the limit of this MBB.
|
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
public MultiByteBuff(ByteBuffer... items)
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
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
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)
public MultiByteBuff putInt(int val)
public final MultiByteBuff put(byte[] src)
public MultiByteBuff put(byte[] src, int offset, int length)
public MultiByteBuff putLong(long val)
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–2019 Cloudera. All rights reserved.