Interface ByteSequence
public interface ByteSequence
A ByteSequence is a readable sequence of
byte values. This interface
provides uniform, read-only access to many different kinds of byte sequences.
This interface does not refine the general contracts of the
equals and hashCode methods. The result of comparing two objects that implement ByteSequence is
therefore, in general, undefined. Each object may be implemented by a different class, and there
is no guarantee that each class will be capable of testing its instances for equality with those
of the other. It is therefore inappropriate to use arbitrary ByteSequence instances as
elements in a set or as keys in a map.
- Since:
- 19.0
-
Method Summary
Modifier and TypeMethodDescriptionbytebyteAt(int index) Returns thebytevalue at the specified index.default IntStreambytes()Returns a stream ofintzero-extending thebytevalues from this sequence.static ByteSequencecreate(byte[] buffer) Creates aByteSequencefrom an existingbyte[].intlength()Returns the length of this byte sequence.default ByteSequencesubSequence(int startIndex, int endIndex) Returns aByteSequencethat is a subsequence of this sequence.default byte[]Returns abyte[]containing the bytes in this sequence in the same order as this sequence.
-
Method Details
-
length
int length()Returns the length of this byte sequence.- Returns:
- the number of
bytes in this sequence - Since:
- 19.0
-
byteAt
byte byteAt(int index) Returns thebytevalue at the specified index. An index ranges from zero to length() - 1. The firstcharvalue of the sequence is at index zero, the next at index one, and so on, as for array indexing.- Parameters:
index- the index of thebytevalue to be returned- Returns:
- the specified
bytevalue - Throws:
IndexOutOfBoundsException- if the index argument is negative or not less than length()- Since:
- 19.0
-
subSequence
Returns aByteSequencethat is a subsequence of this sequence. The subsequence starts with thebytevalue at the specified index and ends with thebytevalue at index end - 1. The length (inbytes) of the returned sequence is end - start, so if start == end then an empty sequence is returned.- Parameters:
startIndex- the start index, inclusiveendIndex- the end index, exclusive- Returns:
- the specified subsequence
- Throws:
IndexOutOfBoundsException- if start or end are negative, if end is greater than length(), or if start is greater than end- Since:
- 19.0
-
toByteArray
default byte[] toByteArray()Returns abyte[]containing the bytes in this sequence in the same order as this sequence. The length of the byte array will be the length of this sequence. Creates a new byte array with every invocation.- Since:
- 19.0
-
bytes
Returns a stream ofintzero-extending thebytevalues from this sequence.- Returns:
- an IntStream of byte values from this sequence
- Since:
- 19.0
-
create
Creates aByteSequencefrom an existingbyte[]. The byte array is not defensively copied, therefore the given bytes must not mutate to ensure the contract of an immutable ByteSequence.- Since:
- 19.0
-