@InterfaceAudience.Private public class SingleByteBuff extends ByteBuff
ByteBuff.ChannelReader| 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 |
CHANNEL_READER, FILE_READER, refCnt| Constructor and Description |
|---|
SingleByteBuff(ByteBuffAllocator.Recycler recycler,
ByteBuffer buf) |
SingleByteBuff(ByteBuffer buf) |
SingleByteBuff(RefCnt refCnt,
ByteBuffer buf) |
| 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 ByteBuff.
|
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.
|
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()
Returns true or false if the underlying BB support hasArray
|
int |
hashCode() |
boolean |
hasRemaining()
Returns true if there are elements between the current position and the limit.
|
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.
|
ByteBuffer[] |
nioByteBuffers() |
int |
position()
Returns this ByteBuff's current 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 n * @return 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(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.
|
SingleByteBuff |
reset()
Similar to
ByteBuffer.reset(), ensures that this ByteBuff is reset back to last marked
position. |
SingleByteBuff |
retain() |
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.
|
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, wrapclone, finalize, getClass, notify, notifyAll, wait, wait, waitrelease, retainprivate static final boolean UNSAFE_AVAIL
private static final boolean UNSAFE_UNALIGNED
private final ByteBuffer buf
private long unsafeOffset
public SingleByteBuff(ByteBuffer buf)
public SingleByteBuff(ByteBuffAllocator.Recycler recycler, ByteBuffer buf)
SingleByteBuff(RefCnt refCnt, ByteBuffer buf)
public int position()
ByteBuffpublic SingleByteBuff position(int position)
ByteBuffpublic SingleByteBuff skip(int len)
ByteBuffpublic SingleByteBuff moveBack(int len)
ByteBuffpublic int capacity()
ByteBuffpublic SingleByteBuff limit(int limit)
ByteBuffpublic SingleByteBuff rewind()
ByteBuffpublic SingleByteBuff mark()
ByteBuffpublic ByteBuffer asSubByteBuffer(int length)
ByteBuffasSubByteBuffer in class ByteBufflength - number of bytes required.public void asSubByteBuffer(int offset, int length, ObjectIntPair<ByteBuffer> pair)
ByteBuffasSubByteBuffer in class ByteBuffoffset - 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()
ByteBuffpublic boolean hasRemaining()
ByteBuffhasRemaining in class ByteBuffpublic SingleByteBuff reset()
ByteBuffByteBuffer.reset(), ensures that this ByteBuff is reset back to last marked
position.public SingleByteBuff slice()
ByteBuffpublic SingleByteBuff duplicate()
ByteBuffpublic byte get()
ByteBuffpublic byte get(int index)
ByteBuffpublic byte getByteAfterPosition(int offset)
ByteBuffgetByteAfterPosition in class ByteBuffpublic SingleByteBuff put(byte b)
ByteBuffpublic SingleByteBuff put(int index, byte b)
ByteBuffpublic void get(byte[] dst, int offset, int length)
ByteBuffpublic void get(int sourceOffset, byte[] dst, int offset, int length)
ByteBuffpublic void get(byte[] dst)
ByteBuffpublic SingleByteBuff put(int offset, ByteBuff src, int srcOffset, int length)
ByteBuffpublic SingleByteBuff put(byte[] src, int offset, int length)
ByteBuffpublic SingleByteBuff put(byte[] src)
ByteBuffpublic boolean hasArray()
ByteBuffpublic byte[] array()
ByteBuffpublic int arrayOffset()
ByteBuffarrayOffset in class ByteBuffpublic short getShort()
ByteBuffpublic short getShort(int index)
ByteBuffpublic short getShortAfterPosition(int offset)
ByteBuffgetShortAfterPosition in class ByteBuffpublic int getInt()
ByteBuffpublic SingleByteBuff putInt(int value)
ByteBuffpublic int getInt(int index)
ByteBuffpublic int getIntAfterPosition(int offset)
ByteBuffgetIntAfterPosition in class ByteBuffpublic long getLong()
ByteBuffpublic SingleByteBuff putLong(long value)
ByteBuffpublic long getLong(int index)
ByteBuffpublic long getLongAfterPosition(int offset)
ByteBuffgetLongAfterPosition in class ByteBuffpublic byte[] toBytes(int offset, int length)
ByteBuffpublic void get(ByteBuffer out, int sourceOffset, int length)
ByteBuffout but not change the position maker for this ByteBuffpublic int read(ReadableByteChannel channel) throws IOException
ByteBuffread in class ByteBuffIOExceptionpublic int read(FileChannel channel, long offset) throws IOException
ByteBuffread in class ByteBuffIOExceptionpublic int write(FileChannel channel, long offset) throws IOException
ByteBuffwrite in class ByteBuffIOExceptionpublic ByteBuffer[] nioByteBuffers()
nioByteBuffers in class ByteBuffpublic SingleByteBuff retain()
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.