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 ByteSequence.getBytes
and is size bytes long.
ByteSequence.getBytes
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.
|
byte[] |
copyBytes()
Same as
ByteSequence.copy but returns just the new byte array. |
boolean |
equals(java.lang.Object other) |
byte[] |
getBytes()
The underlying bytes. Some implementations may choose to make a copy of the underlying ByteArray for
security reasons. For example,
class OpaqueBytes . |
int |
getOffset()
The start position of the sequence within the byte array.
|
int |
getSize()
The number of bytes this sequence represents.
|
int |
hashCode() |
java.io.ByteArrayInputStream |
open()
Returns a ByteArrayInputStream of the bytes.
|
java.nio.ByteBuffer |
putTo(java.nio.ByteBuffer buffer)
Write this sequence to a ByteBuffer.
|
java.nio.ByteBuffer |
slice(int start,
int end)
A new read-only ByteBuffer view of this sequence or part of it.
If start or end are negative then IllegalArgumentException is thrown, otherwise they are clamped if necessary.
This method cannot be used to get bytes before offset or after offset+size, and never makes a new array.
|
ByteSequence |
subSequence(int offset,
int size)
Create a sub-sequence of this sequence. A copy of the underlying array may be made, if a subclass overrides
ByteSequence.getBytes to do so, as class OpaqueBytes does. |
ByteSequence |
take(int n)
Take the first n bytes of this sequence as a sub-sequence. See
ByteSequence.subSequence for further semantics. |
java.lang.String |
toString() |
void |
writeTo(java.io.OutputStream output)
Write this sequence to an OutputStream.
|
public static ByteSequence.Companion Companion
public byte[] getBytes()
The underlying bytes. Some implementations may choose to make a copy of the underlying ByteArray for
security reasons. For example, class OpaqueBytes
.
class OpaqueBytes
public java.io.ByteArrayInputStream open()
Returns a ByteArrayInputStream of the bytes.
public ByteSequence subSequence(int offset, int size)
Create a sub-sequence of this sequence. A copy of the underlying array may be made, if a subclass overrides
ByteSequence.getBytes
to do so, as class OpaqueBytes
does.
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.ByteSequence.getBytes
,
class OpaqueBytes
public ByteSequence take(int n)
Take the first n bytes of this sequence as a sub-sequence. See ByteSequence.subSequence
for further semantics.
ByteSequence.subSequence
public java.nio.ByteBuffer slice(int start, int end)
A new read-only ByteBuffer view of this sequence or part of it. If start or end are negative then IllegalArgumentException is thrown, otherwise they are clamped if necessary. This method cannot be used to get bytes before offset or after offset+size, and never makes a new array.
public void writeTo(java.io.OutputStream output)
Write this sequence to an OutputStream.
public java.nio.ByteBuffer putTo(java.nio.ByteBuffer buffer)
Write this sequence to a ByteBuffer.
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 byte[] copyBytes()
Same as ByteSequence.copy
but returns just the new byte array.
ByteSequence.copy
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 int getOffset()
The start position of the sequence within the byte array.
public int getSize()
The number of bytes this sequence represents.