@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(ByteBuffAllocator.Recycler recycler,
ByteBuffer... items) |
MultiByteBuff(ByteBuffer... items) |
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.
|
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()
Returns false.
|
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.
|
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
|
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 the position
from where the copy should start 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
public MultiByteBuff(ByteBuffer... items)
public MultiByteBuff(ByteBuffAllocator.Recycler recycler, ByteBuffer... items)
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
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)
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.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 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.