@InterfaceAudience.Public public interface PositionedByteRange extends ByteRange
Extends ByteRange
with additional methods to support tracking a
consumers position within the viewport. The API is extended with methods
get()
and put(byte)
for interacting with the backing
array from the current position forward. This frees the caller from managing
their own index into the array.
Designed to be a slimmed-down, mutable alternative to ByteBuffer
.
Modifier and Type | Method and Description |
---|---|
PositionedByteRange |
deepCopy()
Create a new
ByteRange with new backing byte[] containing a copy
of the content from this range's window. |
byte |
get()
Retrieve the next byte from this range.
|
PositionedByteRange |
get(byte[] dst)
Fill
dst with bytes from the range, starting from position . |
PositionedByteRange |
get(byte[] dst,
int offset,
int length)
Fill
dst with bytes from the range, starting from the current
position . |
PositionedByteRange |
get(int index,
byte[] dst)
Fill
dst with bytes from the range, starting from index . |
PositionedByteRange |
get(int index,
byte[] dst,
int offset,
int length)
Fill
dst with bytes from the range, starting from index . |
int |
getInt()
Retrieve the next int value from this range.
|
int |
getLimit()
Return the current limit
|
long |
getLong()
Retrieve the next long value from this range.
|
int |
getPosition()
The current
position marker. |
int |
getRemaining()
The number of bytes remaining between position and the end of the range.
|
short |
getShort()
Retrieve the next short value from this range.
|
long |
getVLong()
Retrieve the next long value, which is stored as VLong, from this range
|
byte |
peek()
Retrieve the next byte from this range without incrementing position.
|
PositionedByteRange |
put(byte val)
Store
val at the next position in this range. |
PositionedByteRange |
put(byte[] val)
Store the content of
val in this range, starting at the next position. |
PositionedByteRange |
put(byte[] val,
int offset,
int length)
Store
length bytes from val into this range. |
PositionedByteRange |
put(int index,
byte val)
Store
val at index . |
PositionedByteRange |
put(int index,
byte[] val)
Store
val at index . |
PositionedByteRange |
put(int index,
byte[] val,
int offset,
int length)
Store
length bytes from val into this range, starting at
index . |
PositionedByteRange |
putInt(int val)
Store int
val at the next position in this range. |
PositionedByteRange |
putInt(int index,
int val)
Store the int value at
index |
PositionedByteRange |
putLong(int index,
long val)
Store the long value at
index |
PositionedByteRange |
putLong(long val)
Store long
val at the next position in this range. |
PositionedByteRange |
putShort(int index,
short val)
Store the short value at
index |
PositionedByteRange |
putShort(short val)
Store short
val at the next position in this range. |
int |
putVLong(long val)
Store the long
val at the next position as a VLong |
PositionedByteRange |
set(byte[] bytes)
Reuse this
ByteRange over a new byte[]. |
PositionedByteRange |
set(byte[] bytes,
int offset,
int length)
Reuse this
ByteRange over a new byte[]. |
PositionedByteRange |
set(int capacity)
Reuse this
ByteRange over a new byte[]. |
PositionedByteRange |
setLength(int length)
Update the length of this range.
|
PositionedByteRange |
setLimit(int limit)
Limits the byte range upto a specified value.
|
PositionedByteRange |
setOffset(int offset)
Update the beginning of this range.
|
PositionedByteRange |
setPosition(int position)
Update the
position index. |
PositionedByteRange |
shallowCopy()
Create a new
ByteRange that points at this range's byte[]. |
PositionedByteRange |
shallowCopySubRange(int innerOffset,
int copyLength)
Create a new
ByteRange that points at this range's byte[]. |
PositionedByteRange |
unset()
Nullifies this ByteRange.
|
deepCopySubRangeTo, deepCopyTo, deepCopyToNewArray, get, getBytes, getInt, getLength, getLong, getOffset, getShort, getVLong, isEmpty, putVLong
compareTo
int getPosition()
position
marker. This valuae is 0-indexed, relative to
the beginning of the range.PositionedByteRange setPosition(int position)
position
index. May not be greater than length
.position
- the new position in this range.int getRemaining()
byte peek()
byte get()
short getShort()
int getInt()
long getLong()
long getVLong()
PositionedByteRange get(byte[] dst)
dst
with bytes from the range, starting from position
.
This range's position
is incremented by the length of dst
,
the number of bytes copied.dst
- the destination of the copy.PositionedByteRange get(byte[] dst, int offset, int length)
dst
with bytes from the range, starting from the current
position
. length
bytes are copied into dst
,
starting at offset
. This range's position
is incremented
by the number of bytes copied.dst
- the destination of the copy.offset
- the offset into dst
to start the copy.length
- the number of bytes to copy into dst
.PositionedByteRange put(byte val)
val
at the next position in this range.val
- the new value.PositionedByteRange putShort(short val)
val
at the next position in this range.val
- the new value.PositionedByteRange putInt(int val)
val
at the next position in this range.val
- the new value.PositionedByteRange putLong(long val)
val
at the next position in this range.val
- the new value.int putVLong(long val)
val
at the next position as a VLongval
- the value to storePositionedByteRange put(byte[] val)
val
in this range, starting at the next position.val
- the new value.PositionedByteRange put(byte[] val, int offset, int length)
length
bytes from val
into this range. Bytes from
val
are copied starting at offset
into the range, starting at
the current position.val
- the new value.offset
- the offset in val
from which to start copying.length
- the number of bytes to copy from val
.PositionedByteRange setLimit(int limit)
limit
- int getLimit()
PositionedByteRange unset()
ByteRange
PositionedByteRange set(int capacity)
ByteRange
ByteRange
over a new byte[]. offset
is set to
0 and length
is set to capacity
.PositionedByteRange set(byte[] bytes)
ByteRange
ByteRange
over a new byte[]. offset
is set to
0 and length
is set to bytes.length
. A null bytes
IS supported, in which case this method will behave equivalently to
ByteRange.unset()
.PositionedByteRange set(byte[] bytes, int offset, int length)
ByteRange
ByteRange
over a new byte[]. A null bytes
IS
supported, in which case this method will behave equivalently to
ByteRange.unset()
, regardless of the values of offset
and
length
.PositionedByteRange setOffset(int offset)
ByteRange
offset + length
may not be
greater than bytes.length
.PositionedByteRange setLength(int length)
ByteRange
offset + length
should not be
greater than bytes.length
.PositionedByteRange get(int index, byte[] dst)
ByteRange
dst
with bytes from the range, starting from index
.PositionedByteRange get(int index, byte[] dst, int offset, int length)
ByteRange
dst
with bytes from the range, starting from index
.
length
bytes are copied into dst
, starting at offset
.PositionedByteRange put(int index, byte val)
ByteRange
val
at index
.PositionedByteRange putShort(int index, short val)
ByteRange
index
PositionedByteRange putInt(int index, int val)
ByteRange
index
PositionedByteRange putLong(int index, long val)
ByteRange
index
PositionedByteRange put(int index, byte[] val)
ByteRange
val
at index
.PositionedByteRange put(int index, byte[] val, int offset, int length)
ByteRange
length
bytes from val
into this range, starting at
index
. Bytes from val
are copied starting at offset
into the range.PositionedByteRange deepCopy()
ByteRange
ByteRange
with new backing byte[] containing a copy
of the content from this
range's window.PositionedByteRange shallowCopy()
ByteRange
ByteRange
that points at this range's byte[].
Modifying the shallowCopy will modify the bytes in this range's array.
Pass over the hash code if it is already cached.shallowCopy
in interface ByteRange
ByteRange
object referencing this range's byte[].PositionedByteRange shallowCopySubRange(int innerOffset, int copyLength)
ByteRange
ByteRange
that points at this range's byte[]. The new
range can have different values for offset and length, but modifying the
shallowCopy will modify the bytes in this range's array. Pass over the
hash code if it is already cached.shallowCopySubRange
in interface ByteRange
innerOffset
- First byte of clone will be this.offset + copyOffset.copyLength
- Number of bytes in the clone.ByteRange
object referencing this range's byte[].Copyright © 2007–2019 Cloudera. All rights reserved.