@InterfaceAudience.Public @InterfaceStability.Evolving public class SimpleByteRange extends Object implements ByteRange
ByteRange
implementation.Modifier and Type | Field and Description |
---|---|
protected byte[] |
bytes
The array containing the bytes in this range.
|
protected int |
length
The number of bytes in the range.
|
protected int |
offset
The index of the first byte in this range.
|
Constructor and Description |
---|
SimpleByteRange()
Create a new
ByteRange lacking a backing array and with an
undefined viewport. |
SimpleByteRange(byte[] bytes)
Create a new
ByteRange over the provided bytes . |
SimpleByteRange(byte[] bytes,
int offset,
int length)
Create a new
ByteRange over the provided bytes . |
SimpleByteRange(int capacity)
Create a new
ByteRange over a new backing array of size
capacity . |
Modifier and Type | Method and Description |
---|---|
protected void |
clearHashCache() |
int |
compareTo(ByteRange other)
Bitwise comparison of each byte in the array.
|
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.
|
boolean |
equals(Object thatObject) |
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 |
getLength()
The length of the range.
|
int |
getOffset()
The offset, the index into the underlying byte[] at which this range
begins.
|
int |
hashCode() |
boolean |
isEmpty() |
static boolean |
isEmpty(ByteRange range) |
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 |
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[]. |
String |
toString() |
ByteRange |
unset()
Nullifies this ByteRange.
|
protected byte[] bytes
protected int offset
ByteRange.get(0)
will
return bytes[offset].protected int length
public SimpleByteRange()
ByteRange
lacking a backing array and with an
undefined viewport.public SimpleByteRange(int capacity)
ByteRange
over a new backing array of size
capacity
. The range's offset and length are 0 and capacity
,
respectively.capacity
- the size of the backing array.public SimpleByteRange(byte[] bytes)
ByteRange
over the provided bytes
.bytes
- The array to wrap.public SimpleByteRange(byte[] bytes, int offset, int length)
ByteRange
over the provided bytes
.bytes
- The array to wrap.offset
- The offset into bytes
considered the beginning
of this range.length
- The length of this range.public byte[] getBytes()
ByteRange
public ByteRange unset()
ByteRange
public ByteRange set(int capacity)
ByteRange
ByteRange
over a new byte[]. offset
is set to
0 and length
is set to capacity
.public ByteRange 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()
.public ByteRange 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
.public int getOffset()
ByteRange
getOffset
in interface ByteRange
ByteRange.getBytes()
public ByteRange setOffset(int offset)
ByteRange
offset + length
may not be
greater than bytes.length
.public int getLength()
ByteRange
public ByteRange setLength(int length)
ByteRange
offset + length
should not be
greater than bytes.length
.public boolean isEmpty()
public static boolean isEmpty(ByteRange range)
range
is of zero length, false otherwise.public byte get(int index)
ByteRange
index
.public ByteRange get(int index, byte[] dst)
ByteRange
dst
with bytes from the range, starting from index
.public ByteRange 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
.public ByteRange put(int index, byte val)
ByteRange
val
at index
.public ByteRange put(int index, byte[] val)
ByteRange
val
at index
.public ByteRange 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.public byte[] deepCopyToNewArray()
ByteRange
deepCopyToNewArray
in interface ByteRange
public ByteRange deepCopy()
ByteRange
ByteRange
with new backing byte[] containing a copy
of the content from this
range's window.public void deepCopyTo(byte[] destination, int destinationOffset)
ByteRange
deepCopyTo
in interface ByteRange
destination
- Copy to this arraydestinationOffset
- First index in the destination array.public void deepCopySubRangeTo(int innerOffset, int copyLength, byte[] destination, int destinationOffset)
ByteRange
deepCopySubRangeTo
in interface ByteRange
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.public ByteRange 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[].public ByteRange 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[].protected void clearHashCache()
public int compareTo(ByteRange other)
compareTo
in interface Comparable<ByteRange>
Copyright © 2015 The Apache Software Foundation. All Rights Reserved.