@InterfaceAudience.Private public abstract class ByteBuff extends Object
Modifier and Type | Field and Description |
---|---|
private static int |
NIO_BUFFER_LIMIT |
Constructor and Description |
---|
ByteBuff() |
Modifier and Type | Method and Description |
---|---|
abstract byte[] |
array() |
abstract int |
arrayOffset() |
abstract ByteBuffer |
asSubByteBuffer(int length)
Returns bytes from current position till length specified, as a single ByteBuffer.
|
abstract void |
asSubByteBuffer(int offset,
int length,
ObjectIntPair<ByteBuffer> pair)
Returns bytes from given offset till length specified, as a single ByteBuffer.
|
abstract int |
capacity() |
static int |
channelRead(ReadableByteChannel channel,
ByteBuffer buf) |
static int |
compareTo(ByteBuff buf1,
int o1,
int len1,
ByteBuff buf2,
int o2,
int len2)
Compares two ByteBuffs
|
abstract ByteBuff |
duplicate()
Returns an ByteBuff which is a duplicate version of this ByteBuff.
|
abstract byte |
get()
A relative method that returns byte at the current position.
|
abstract void |
get(byte[] dst)
Copies the content from this ByteBuff's current position to the byte array and fills it.
|
abstract 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.
|
abstract 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 |
abstract byte |
get(int index)
Fetches the byte at the given index.
|
abstract 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.
|
abstract byte |
getByteAfterPosition(int offset)
Fetches the byte at the given offset from current position.
|
abstract int |
getInt()
Returns the int value at the current position.
|
abstract int |
getInt(int index)
Fetches the int at the given index.
|
abstract int |
getIntAfterPosition(int offset)
Fetches the int value at the given offset from current position.
|
abstract long |
getLong()
Returns the long value at the current position.
|
abstract long |
getLong(int index)
Fetches the long at the given index.
|
abstract long |
getLongAfterPosition(int offset)
Fetches the long value at the given offset from current position.
|
abstract short |
getShort()
Returns the short value at the current position.
|
abstract short |
getShort(int index)
Fetches the short value at the given index.
|
abstract short |
getShortAfterPosition(int offset)
Fetches the short value at the given offset from current position.
|
abstract boolean |
hasArray() |
abstract boolean |
hasRemaining()
Returns true if there are elements between the current position and the limt
|
abstract int |
limit()
Returns the limit of this ByteBuff
|
abstract ByteBuff |
limit(int limit)
Marks the limit of this ByteBuff.
|
abstract ByteBuff |
mark()
Marks the current position of the ByteBuff
|
abstract ByteBuff |
moveBack(int len)
Jumps back the current position of this ByteBuff by specified length.
|
abstract int |
position() |
abstract ByteBuff |
position(int position)
Sets this ByteBuff's position to the given value.
|
abstract ByteBuff |
put(byte b)
Writes a byte to this ByteBuff at the current position and increments the position
|
abstract ByteBuff |
put(byte[] src)
Copies from the given byte[] to this ByteBuff
|
abstract ByteBuff |
put(byte[] src,
int offset,
int length)
Copies from the given byte[] to this ByteBuff
|
abstract ByteBuff |
put(int index,
byte b)
Writes a byte to this ByteBuff at the given index
|
abstract ByteBuff |
put(int offset,
ByteBuff src,
int srcOffset,
int length)
Copies the contents from the src ByteBuff to this ByteBuff.
|
abstract ByteBuff |
putInt(int value)
Writes an int to this ByteBuff at its current position.
|
abstract ByteBuff |
putLong(long value)
Writes a long to this ByteBuff at its current position.
|
abstract int |
read(ReadableByteChannel channel)
Reads bytes from the given channel into this ByteBuff
|
static int |
readCompressedInt(ByteBuff buf)
Read integer from ByteBuff coded in 7 bits and increment position.
|
static long |
readLong(ByteBuff in,
int fitInBytes)
Read long which was written to fitInBytes bytes and increment position.
|
static long |
readVLong(ByteBuff in)
Similar to
WritableUtils.readVLong(java.io.DataInput) but reads from a
ByteBuff . |
abstract int |
remaining()
Returns the number of elements between the current position and the
limit.
|
abstract ByteBuff |
reset()
Similar to
ByteBuffer .reset(), ensures that this ByteBuff
is reset back to last marked position. |
abstract ByteBuff |
rewind()
Rewinds this ByteBuff and the position is set to 0
|
abstract ByteBuff |
skip(int len)
Jumps the current position of this ByteBuff by specified length.
|
abstract ByteBuff |
slice()
Returns an ByteBuff which is a sliced version of this ByteBuff.
|
byte[] |
toBytes()
Copy the content from this ByteBuff to a byte[].
|
abstract byte[] |
toBytes(int offset,
int length)
Copy the content from this ByteBuff to a byte[] based on the given offset and
length
|
String |
toString() |
static String |
toStringBinary(ByteBuff b,
int off,
int len) |
static int |
unsignedBinarySearch(ByteBuff a,
int fromIndex,
int toIndex,
byte key)
Search sorted array "a" for byte "key".
|
private static final int NIO_BUFFER_LIMIT
public ByteBuff()
public abstract int position()
public abstract ByteBuff position(int position)
position
- public abstract ByteBuff skip(int len)
len
- the length to be skippedpublic abstract ByteBuff moveBack(int len)
len
- the length to move backpublic abstract int capacity()
public abstract int limit()
public abstract ByteBuff limit(int limit)
limit
- public abstract ByteBuff rewind()
public abstract ByteBuff mark()
public abstract ByteBuffer asSubByteBuffer(int length)
length
- number of bytes required.public abstract void asSubByteBuffer(int offset, int length, ObjectIntPair<ByteBuffer> pair)
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 abstract int remaining()
public abstract boolean hasRemaining()
public abstract ByteBuff reset()
ByteBuffer
.reset(), ensures that this ByteBuff
is reset back to last marked position.public abstract ByteBuff slice()
public abstract ByteBuff duplicate()
public abstract byte get()
public abstract byte get(int index)
index
- public abstract byte getByteAfterPosition(int offset)
offset
- public abstract ByteBuff put(byte b)
b
- public abstract ByteBuff put(int index, byte b)
index
- b
- public abstract void get(byte[] dst, int offset, int length)
dst
- offset
- within the current arraylength
- upto which the bytes to be copiedpublic abstract void get(int sourceOffset, byte[] dst, int offset, int length)
sourceOffset
- the offset in this ByteBuff from where the copy should happendst
- the byte[] to which the ByteBuff's content is to be copiedoffset
- within the current arraylength
- upto which the bytes to be copiedpublic abstract void get(byte[] dst)
dst
- public abstract ByteBuff put(byte[] src, int offset, int length)
src
- offset
- the position in the byte array from which the copy should be donelength
- the length upto which the copy should happenpublic abstract ByteBuff put(byte[] src)
src
- public abstract boolean hasArray()
public abstract byte[] array()
public abstract int arrayOffset()
public abstract short getShort()
public abstract short getShort(int index)
index
- public abstract short getShortAfterPosition(int offset)
offset
- public abstract int getInt()
public abstract ByteBuff putInt(int value)
value
- Int value to writepublic abstract int getInt(int index)
index
- public abstract int getIntAfterPosition(int offset)
offset
- public abstract long getLong()
public abstract ByteBuff putLong(long value)
value
- Long value to writepublic abstract long getLong(int index)
index
- public abstract long getLongAfterPosition(int offset)
offset
- public byte[] toBytes()
public abstract byte[] toBytes(int offset, int length)
offset
- the position from where the copy should startlength
- the length upto which the copy has to be donepublic abstract void get(ByteBuffer out, int sourceOffset, int length)
out
but not change the position maker
for this ByteBuffout
- the ByteBuffer to which the copy has to happensourceOffset
- the offset in the ByteBuff from which the elements has
to be copiedlength
- the length in this ByteBuff upto which the elements has to be copiedpublic abstract ByteBuff put(int offset, ByteBuff src, int srcOffset, int length)
offset
- the position in this ByteBuff to which the copy should happensrc
- the src ByteBuffsrcOffset
- the offset in the src ByteBuff from where the elements should be readlength
- the length up to which the copy should happenpublic abstract int read(ReadableByteChannel channel) throws IOException
channel
- IOException
public static int channelRead(ReadableByteChannel channel, ByteBuffer buf) throws IOException
IOException
public static int readCompressedInt(ByteBuff buf)
public static int compareTo(ByteBuff buf1, int o1, int len1, ByteBuff buf2, int o2, int len2)
buf1
- the first ByteBuffo1
- the offset in the first ByteBuff from where the compare has to happenlen1
- the length in the first ByteBuff upto which the compare has to happenbuf2
- the second ByteBuffo2
- the offset in the second ByteBuff from where the compare has to happenlen2
- the length in the second ByteBuff upto which the compare has to happenpublic static long readLong(ByteBuff in, int fitInBytes)
fitInBytes
- In how many bytes given long is stored.public static long readVLong(ByteBuff in)
WritableUtils.readVLong(java.io.DataInput)
but reads from a
ByteBuff
.public static int unsignedBinarySearch(ByteBuff a, int fromIndex, int toIndex, byte key)
a
- Array to search. Entries must be sorted and unique.fromIndex
- First index inclusive of "a" to include in the search.toIndex
- Last index exclusive of "a" to include in the search.key
- The byte to search for.public static String toStringBinary(ByteBuff b, int off, int len)
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.