@InterfaceAudience.Public public interface ByteRange extends Comparable<ByteRange>
ByteRange
maintains an underlying byte[] and a viewport into that
byte[] as a range of bytes. The ByteRange
is a mutable, reusable
object, so the underlying byte[] can be modified after instantiation. This
is done using the set(byte[])
and unset()
methods. Direct
access to the byte[] is also available via getBytes()
. The viewport
is defined by an offset
into the byte[] and a length
. The
range of bytes is 0-indexed, and is accessed by index via the
get(int)
and put(int, byte)
methods.
This interface differs from ByteBuffer:
byte
access only; does not encode other primitives.equals(Object)
, #hashCode()
, and
#compareTo(ByteRange)
so that it can be used in standard java
Collections. Comparison operations are lexicographic, which is native to
HBase.
Mutable, and always evaluates #equals(Object)
, #hashCode()
,
and #compareTo(ByteRange)
based on the current contents.
Can contain convenience methods for comparing, printing, cloning, spawning
new arrays, copying to other arrays, etc. Please place non-core methods into
ByteRangeUtils
.
Modifier and Type | Method and Description |
---|---|
ByteRange |
deepCopy()
Create a new
ByteRange with new backing byte[] containing a copy
of the content from this range's window. |
void |
deepCopySubRangeTo(int innerOffset,
int copyLength,
byte[] destination,
int destinationOffset)
Wrapper for System.arraycopy.
|
void |
deepCopyTo(byte[] destination,
int destinationOffset)
Wrapper for System.arraycopy.
|
byte[] |
deepCopyToNewArray()
Instantiate a new byte[] with exact length, which is at least 24 bytes +
length.
|
byte |
get(int index)
Retrieve the byte at
index . |
ByteRange |
get(int index,
byte[] dst)
Fill
dst with bytes from the range, starting from index . |
ByteRange |
get(int index,
byte[] dst,
int offset,
int length)
Fill
dst with bytes from the range, starting from index . |
byte[] |
getBytes()
The underlying byte[].
|
int |
getInt(int index)
Retrieve the int value at
index |
int |
getLength()
The length of the range.
|
long |
getLong(int index)
Retrieve the long value at
index |
int |
getOffset()
The offset, the index into the underlying byte[] at which this range
begins.
|
short |
getShort(int index)
Retrieve the short value at
index |
long |
getVLong(int index)
Retrieve the long value at
index which is stored as VLong |
boolean |
isEmpty() |
ByteRange |
put(int index,
byte val)
Store
val at index . |
ByteRange |
put(int index,
byte[] val)
Store
val at index . |
ByteRange |
put(int index,
byte[] val,
int offset,
int length)
Store
length bytes from val into this range, starting at
index . |
ByteRange |
putInt(int index,
int val)
Store the int value at
index |
ByteRange |
putLong(int index,
long val)
Store the long value at
index |
ByteRange |
putShort(int index,
short val)
Store the short value at
index |
int |
putVLong(int index,
long val)
Store the long value at
index as a VLong |
ByteRange |
set(byte[] bytes)
Reuse this
ByteRange over a new byte[]. |
ByteRange |
set(byte[] bytes,
int offset,
int length)
Reuse this
ByteRange over a new byte[]. |
ByteRange |
set(int capacity)
Reuse this
ByteRange over a new byte[]. |
ByteRange |
setLength(int length)
Update the length of this range.
|
ByteRange |
setOffset(int offset)
Update the beginning of this range.
|
ByteRange |
shallowCopy()
Create a new
ByteRange that points at this range's byte[]. |
ByteRange |
shallowCopySubRange(int innerOffset,
int copyLength)
Create a new
ByteRange that points at this range's byte[]. |
ByteRange |
unset()
Nullifies this ByteRange.
|
compareTo
byte[] getBytes()
ByteRange unset()
ByteRange set(int capacity)
ByteRange
over a new byte[]. offset
is set to
0 and length
is set to capacity
.capacity
- the size of a new byte[].ByteRange set(byte[] bytes)
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
unset()
.bytes
- the array to wrap.ByteRange set(byte[] bytes, int offset, int length)
ByteRange
over a new byte[]. A null bytes
IS
supported, in which case this method will behave equivalently to
unset()
, regardless of the values of offset
and
length
.bytes
- The array to wrap.offset
- The offset into bytes
considered the beginning of
this range.length
- The length of this range.int getOffset()
getBytes()
ByteRange setOffset(int offset)
offset + length
may not be
greater than bytes.length
.offset
- the new start of this range.int getLength()
ByteRange setLength(int length)
offset + length
should not be
greater than bytes.length
.length
- The new length of this range.boolean isEmpty()
byte get(int index)
index
.index
- zero-based index into this range.short getShort(int index)
index
index
- zero-based index into this rangeindex
int getInt(int index)
index
index
- zero-based index into this rangeindex
long getLong(int index)
index
index
- zero-based index into this rangeindex
long getVLong(int index)
index
which is stored as VLongindex
- zero-based index into this rangeindex
which is stored as VLongByteRange get(int index, byte[] dst)
dst
with bytes from the range, starting from index
.index
- zero-based index into this range.dst
- the destination of the copy.ByteRange get(int index, byte[] dst, int offset, int length)
dst
with bytes from the range, starting from index
.
length
bytes are copied into dst
, starting at offset
.index
- zero-based index into this range.dst
- the destination of the copy.offset
- the offset into dst
to start the copy.length
- the number of bytes to copy into dst
.ByteRange put(int index, byte val)
val
at index
.index
- the index in the range where val
is stored.val
- the value to store.ByteRange putShort(int index, short val)
index
index
- the index in the range where val
is storedval
- the value to storeByteRange putInt(int index, int val)
index
index
- the index in the range where val
is storedval
- the value to storeByteRange putLong(int index, long val)
index
index
- the index in the range where val
is storedval
- the value to storeint putVLong(int index, long val)
index
as a VLongindex
- the index in the range where val
is storedval
- the value to storeByteRange put(int index, byte[] val)
val
at index
.index
- the index in the range where val
is stored.val
- the value to store.ByteRange put(int index, byte[] val, int offset, int length)
length
bytes from val
into this range, starting at
index
. Bytes from val
are copied starting at offset
into the range.index
- position in this range to start the copy.val
- the value to store.offset
- the offset in val
from which to start copying.length
- the number of bytes to copy from val
.byte[] deepCopyToNewArray()
ByteRange deepCopy()
ByteRange
with new backing byte[] containing a copy
of the content from this
range's window.void deepCopyTo(byte[] destination, int destinationOffset)
destination
- Copy to this arraydestinationOffset
- First index in the destination array.void deepCopySubRangeTo(int innerOffset, int copyLength, byte[] destination, int destinationOffset)
innerOffset
- Start copying from this index in this source
ByteRange. First byte copied is bytes[offset + innerOffset]copyLength
- Copy this many bytesdestination
- Copy to this arraydestinationOffset
- First index in the destination array.ByteRange shallowCopy()
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.ByteRange
object referencing this range's byte[].ByteRange shallowCopySubRange(int innerOffset, int copyLength)
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.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.