@InterfaceAudience.Private public class SingleByteBuff extends ByteBuff
Modifier and Type | Field and Description |
---|---|
private ByteBuffer |
buf |
private static boolean |
UNSAFE_AVAIL |
private static boolean |
UNSAFE_UNALIGNED |
private long |
unsafeOffset |
private Object |
unsafeRef |
Constructor and Description |
---|
SingleByteBuff(ByteBuffer buf) |
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() |
SingleByteBuff |
duplicate()
Returns an ByteBuff which is a duplicate version of this ByteBuff.
|
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 ByteBuff'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 ByteBuff's current position to
the byte[]'s offset.
|
void |
get(ByteBuffer out,
int sourceOffset,
int length)
Copies the content from this ByteBuff to a ByteBuffer
Note : This will advance the position marker of
out but not change the position maker
for this ByteBuff |
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 |
getEnclosingByteBuffer() |
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 value 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 ByteBuff
|
SingleByteBuff |
limit(int limit)
Marks the limit of this ByteBuff.
|
SingleByteBuff |
mark()
Marks the current position of the ByteBuff
|
SingleByteBuff |
moveBack(int len)
Jumps back the current position of this ByteBuff by specified length.
|
int |
position() |
SingleByteBuff |
position(int position)
Sets this ByteBuff's position to the given value.
|
SingleByteBuff |
put(byte b)
Writes a byte to this ByteBuff at the current position and increments the position
|
SingleByteBuff |
put(byte[] src)
Copies from the given byte[] to this ByteBuff
|
SingleByteBuff |
put(byte[] src,
int offset,
int length)
Copies from the given byte[] to this ByteBuff
|
SingleByteBuff |
put(int index,
byte b)
Writes a byte to this ByteBuff at the given index
|
SingleByteBuff |
put(int offset,
ByteBuff src,
int srcOffset,
int length)
Copies the contents from the src ByteBuff to this ByteBuff.
|
SingleByteBuff |
putInt(int value)
Writes an int to this ByteBuff at its current position.
|
SingleByteBuff |
putLong(long value)
Writes a long to this ByteBuff 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.
|
SingleByteBuff |
reset()
Similar to
ByteBuffer .reset(), ensures that this ByteBuff
is reset back to last marked position. |
SingleByteBuff |
rewind()
Rewinds this ByteBuff and the position is set to 0
|
SingleByteBuff |
skip(int len)
Jumps the current position of this ByteBuff by specified length.
|
SingleByteBuff |
slice()
Returns an ByteBuff which is a sliced version of this ByteBuff.
|
byte[] |
toBytes(int offset,
int length)
Copy the content from this ByteBuff to a byte[] based on the given offset and
length
|
channelRead, compareTo, readCompressedInt, readLong, readVLong, toBytes, toString, toStringBinary, unsignedBinarySearch
private static final boolean UNSAFE_AVAIL
private static final boolean UNSAFE_UNALIGNED
private final ByteBuffer buf
private long unsafeOffset
public SingleByteBuff(ByteBuffer buf)
public int position()
public SingleByteBuff position(int position)
ByteBuff
public SingleByteBuff skip(int len)
ByteBuff
public SingleByteBuff moveBack(int len)
ByteBuff
public int capacity()
public SingleByteBuff limit(int limit)
ByteBuff
public SingleByteBuff rewind()
ByteBuff
public SingleByteBuff mark()
ByteBuff
public ByteBuffer asSubByteBuffer(int length)
ByteBuff
asSubByteBuffer
in class ByteBuff
length
- number of bytes required.public void asSubByteBuffer(int offset, int length, ObjectIntPair<ByteBuffer> pair)
ByteBuff
asSubByteBuffer
in class ByteBuff
offset
- the offset in this ByteBuff 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.
Since this API gets called in a loop we are passing a pair to it which could be created
outside the loop and the method would set the values on the pair that is passed in by
the caller. Thus it avoids more object creations that would happen if the pair that is
returned is created by this method every time.public int remaining()
ByteBuff
public boolean hasRemaining()
ByteBuff
hasRemaining
in class ByteBuff
public SingleByteBuff reset()
ByteBuff
ByteBuffer
.reset(), ensures that this ByteBuff
is reset back to last marked position.public SingleByteBuff slice()
ByteBuff
public SingleByteBuff duplicate()
ByteBuff
public byte get()
ByteBuff
public byte get(int index)
ByteBuff
public byte getByteAfterPosition(int offset)
ByteBuff
getByteAfterPosition
in class ByteBuff
public SingleByteBuff put(byte b)
ByteBuff
public SingleByteBuff put(int index, byte b)
ByteBuff
public void get(byte[] dst, int offset, int length)
ByteBuff
public void get(int sourceOffset, byte[] dst, int offset, int length)
ByteBuff
public void get(byte[] dst)
ByteBuff
public SingleByteBuff put(int offset, ByteBuff src, int srcOffset, int length)
ByteBuff
public SingleByteBuff put(byte[] src, int offset, int length)
ByteBuff
public SingleByteBuff put(byte[] src)
ByteBuff
public boolean hasArray()
public byte[] array()
public int arrayOffset()
arrayOffset
in class ByteBuff
public short getShort()
ByteBuff
public short getShort(int index)
ByteBuff
public short getShortAfterPosition(int offset)
ByteBuff
getShortAfterPosition
in class ByteBuff
public int getInt()
ByteBuff
public SingleByteBuff putInt(int value)
ByteBuff
public int getInt(int index)
ByteBuff
public int getIntAfterPosition(int offset)
ByteBuff
getIntAfterPosition
in class ByteBuff
public long getLong()
ByteBuff
public SingleByteBuff putLong(long value)
ByteBuff
public long getLong(int index)
ByteBuff
public long getLongAfterPosition(int offset)
ByteBuff
getLongAfterPosition
in class ByteBuff
public byte[] toBytes(int offset, int length)
ByteBuff
public void get(ByteBuffer out, int sourceOffset, int length)
ByteBuff
out
but not change the position maker
for this ByteBuffpublic int read(ReadableByteChannel channel) throws IOException
ByteBuff
read
in class ByteBuff
IOException
public ByteBuffer getEnclosingByteBuffer()
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.