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.
bytes
@NotNull public kotlin.Array[] 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
@NotNull public java.io.ByteArrayInputStream open()
Returns a ByteArrayInputStream of the bytes.
@NotNull 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
bytes
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.bytes
,
class OpaqueBytes
@NotNull public ByteSequence take(int n)
Take the first n bytes of this sequence as a sub-sequence. See subSequence
for further semantics.
subSequence
@NotNull 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.
start
,
end
,
IllegalArgumentExceptionpublic void writeTo(@NotNull java.io.OutputStream output)
Write this sequence to an OutputStream.
@NotNull public java.nio.ByteBuffer putTo(@NotNull java.nio.ByteBuffer buffer)
Write this sequence to a ByteBuffer.
@NotNull 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.
@NotNull public kotlin.Array[] copyBytes()
Same as copy
but returns just the new byte array.
copy
public int compareTo(@NotNull 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(@Nullable java.lang.Object other)
public int hashCode()
@NotNull 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.
@JvmStatic @JvmOverloads @NotNull public static ByteSequence of(@NotNull kotlin.Array[] 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.
class ByteSequence
,
ByteArray@JvmStatic @JvmOverloads @NotNull public static ByteSequence of(@NotNull kotlin.Array[] bytes, int offset)
Construct a class ByteSequence
given a ByteArray and optional offset and size, that represents that potentially
sub-sequence of bytes.
class ByteSequence
,
ByteArray@JvmStatic @JvmOverloads @NotNull public static ByteSequence of(@NotNull kotlin.Array[] bytes)
Construct a class ByteSequence
given a ByteArray and optional offset and size, that represents that potentially
sub-sequence of bytes.
class ByteSequence
,
ByteArray