public class ByteSequence
An abstraction of a byte array, with offset and size that does no copying of bytes unless asked to.
The data of interest typically starts at position offset within the bytes and is size bytes long.
Modifier and Type | Class and Description |
---|---|
static class |
ByteSequence.Companion |
Modifier and Type | Field and Description |
---|---|
static ByteSequence.Companion |
Companion |
Modifier and Type | Method and Description |
---|---|
int |
compareTo(ByteSequence other)
Compare byte arrays byte by byte. Arrays that are shorter are deemed less than longer arrays if all the bytes
of the shorter array equal those in the same position of the longer array.
|
ByteSequence |
copy()
Copy this sequence, complete with new backing array. This can be helpful to break references to potentially
large backing arrays from small sub-sequences.
|
boolean |
equals(java.lang.Object other) |
byte[] |
getBytes()
The underlying bytes.
|
int |
getOffset()
The start position of the sequence within the byte array.
|
int |
getSize()
The number of bytes this sequence represents.
|
int |
hashCode() |
static ByteSequence |
of(byte[] bytes,
int offset,
int size)
Construct a
class ByteSequence given a ByteArray and optional offset and size, that represents that potentially
sub-sequence of bytes. The returned implementation is optimised when the whole ByteArray is the sequence. |
static ByteSequence |
of(byte[] bytes,
int offset)
Construct a
class ByteSequence given a ByteArray and optional offset and size, that represents that potentially
sub-sequence of bytes. The returned implementation is optimised when the whole ByteArray is the sequence. |
static ByteSequence |
of(byte[] bytes)
Construct a
class ByteSequence given a ByteArray and optional offset and size, that represents that potentially
sub-sequence of bytes. The returned implementation is optimised when the whole ByteArray is the sequence. |
java.io.ByteArrayInputStream |
open()
Returns a ByteArrayInputStream of the bytes
|
ByteSequence |
subSequence(int offset,
int size)
Create a sub-sequence backed by the same array.
|
ByteSequence |
take(int n)
Take the first n bytes of this sequence as a sub-sequence. See subSequence for further semantics.
|
java.lang.String |
toString() |
public static ByteSequence.Companion Companion
public byte[] getBytes()
The underlying bytes.
public int getSize()
The number of bytes this sequence represents.
public int getOffset()
The start position of the sequence within the byte array.
public java.io.ByteArrayInputStream open()
Returns a ByteArrayInputStream of the bytes
public ByteSequence subSequence(int offset, int size)
Create a sub-sequence backed by the same array.
offset
- The offset within this sequence to start the new sequence. Note: not the offset within the backing array.size
- The size of the intended sub sequence.public ByteSequence take(int n)
Take the first n bytes of this sequence as a sub-sequence. See subSequence for further semantics.
public ByteSequence copy()
Copy this sequence, complete with new backing array. This can be helpful to break references to potentially large backing arrays from small sub-sequences.
public int compareTo(ByteSequence other)
Compare byte arrays byte by byte. Arrays that are shorter are deemed less than longer arrays if all the bytes of the shorter array equal those in the same position of the longer array.
public boolean equals(java.lang.Object other)
public int hashCode()
public java.lang.String toString()
public static ByteSequence of(byte[] bytes, int offset, int size)
Construct a class ByteSequence
given a ByteArray and optional offset and size, that represents that potentially
sub-sequence of bytes. The returned implementation is optimised when the whole ByteArray is the sequence.
class ByteSequence
,
ByteArray,
ByteArraypublic static ByteSequence of(byte[] bytes, int offset)
Construct a class ByteSequence
given a ByteArray and optional offset and size, that represents that potentially
sub-sequence of bytes. The returned implementation is optimised when the whole ByteArray is the sequence.
class ByteSequence
,
ByteArray,
ByteArraypublic static ByteSequence of(byte[] bytes)
Construct a class ByteSequence
given a ByteArray and optional offset and size, that represents that potentially
sub-sequence of bytes. The returned implementation is optimised when the whole ByteArray is the sequence.
class ByteSequence
,
ByteArray,
ByteArray