public interface ByteSequence extends java.lang.Comparable<ByteSequence>
ByteSequence is a readable sequence of byte values. This interface provides uniform, read-only access to many different kinds of byte sequences.| Modifier and Type | Method and Description |
|---|---|
ByteSequenceReader |
asReader()
Returns a
ByteSequenceReader which can be used to incrementally read and decode data from this byte sequence. |
byte |
byteAt(int index)
Returns the byte value at the specified index.
|
int |
compareTo(byte[] b, int offset, int length)
Compares this byte sequence with the specified byte array sub-sequence for order.
|
int |
compareTo(ByteSequence o)
Compares this byte sequence with the specified byte sequence for order.
|
byte[] |
copyTo(byte[] b)
Copies the contents of this byte sequence to the provided byte array.
|
byte[] |
copyTo(byte[] b, int offset)
Copies the contents of this byte sequence to the specified location in the provided byte array.
|
ByteStringBuilder |
copyTo(ByteStringBuilder builder)
Appends the entire contents of this byte sequence to the provided
ByteStringBuilder. |
java.io.OutputStream |
copyTo(java.io.OutputStream stream)
Copies the entire contents of this byte sequence to the provided
OutputStream. |
boolean |
equals(byte[] b, int offset, int length)
Indicates whether the provided byte array sub-sequence is equal to this byte sequence.
|
boolean |
equals(java.lang.Object o)
Indicates whether the provided object is equal to this byte sequence.
|
int |
hashCode()
Returns a hash code for this byte sequence.
|
int |
length()
Returns the length of this byte sequence.
|
ByteSequence |
subSequence(int start, int end)
Returns a new byte sequence that is a subsequence of this byte sequence.
|
byte[] |
toByteArray()
Returns a byte array containing the bytes in this sequence in the same order as this sequence.
|
ByteString |
toByteString()
Returns the
ByteString representation of this byte sequence. |
java.lang.String |
toString()
Returns the UTF-8 decoded string representation of this byte sequence.
|
ByteSequenceReader asReader()
ByteSequenceReader which can be used to incrementally read and decode data from this byte sequence.
NOTE: any concurrent changes to the underlying byte sequence (if mutable) may cause subsequent reads to overrun and fail.
ByteSequenceReader which can be used to incrementally read and decode data from this byte sequence.
byte byteAt(int index)
throws java.lang.IndexOutOfBoundsException
An index ranges from zero to length() - 1. The first byte value of the sequence is at index zero, the next at index one, and so on, as for array indexing.
index - The index of the byte to be returned.java.lang.IndexOutOfBoundsException - If the index argument is negative or not less than length().
int compareTo(byte[] b,
int offset,
int length)
throws java.lang.IndexOutOfBoundsException
b - The byte array to compare.offset - The offset of the sub-sequence in the byte array to be compared; must be non-negative and no larger than b.length .length - The length of the sub-sequence in the byte array to be compared; must be non-negative and no larger than b.length - offset.java.lang.IndexOutOfBoundsException - If offset is negative or if length is negative or if offset + length is greater than b.length.int compareTo(ByteSequence o)
compareTo in interface java.lang.Comparable<ByteSequence>o - The byte sequence to be compared.byte[] copyTo(byte[] b)
Copying will stop when either the entire content of this sequence has been copied or if the end of the provided byte array has been reached.
An invocation of the form:
src.copyTo(b)Behaves in exactly the same way as the invocation:
src.copyTo(b, 0);
b - The byte array to which bytes are to be copied.
byte[] copyTo(byte[] b,
int offset)
throws java.lang.IndexOutOfBoundsException
Copying will stop when either the entire content of this sequence has been copied or if the end of the provided byte array has been reached.
An invocation of the form:
src.copyTo(b, offset)Behaves in exactly the same way as the invocation:
int len = Math.min(src.length(), b.length - offset); for (int i = 0; i < len; i++) b[offset + i] = src.get(i);Except that it is potentially much more efficient.
b - The byte array to which bytes are to be copied.offset - The offset within the array of the first byte to be written; must be non-negative and no larger than b.length.java.lang.IndexOutOfBoundsException - If offset is negative.ByteStringBuilder copyTo(ByteStringBuilder builder)
ByteStringBuilder.builder - The builder to copy to.
java.io.OutputStream copyTo(java.io.OutputStream stream)
throws java.io.IOException
OutputStream.stream - The OutputStream to copy to.OutputStream.java.io.IOException - If an error occurs while writing to the OutputStream.
boolean equals(byte[] b,
int offset,
int length)
throws java.lang.IndexOutOfBoundsException
b - The byte array for which to make the determination.offset - The offset of the sub-sequence in the byte array to be compared; must be non-negative and no larger than b.length .length - The length of the sub-sequence in the byte array to be compared; must be non-negative and no larger than b.length - offset.true if the content of the provided byte array sub-sequence is equal to that of this byte sequence, or false if not.java.lang.IndexOutOfBoundsException - If offset is negative or if length is negative or if offset + length is greater than b.length.boolean equals(java.lang.Object o)
equals in class java.lang.Objecto - The object for which to make the determination.true if the provided object is a byte sequence whose content is equal to that of this byte sequence, or false if not.int hashCode()
hashCode in class java.lang.Objectint length()
ByteSequence subSequence(int start, int end) throws java.lang.IndexOutOfBoundsException
The subsequence starts with the byte value at the specified start index and ends with the byte value at index end - 1. The length (in bytes) of the returned sequence is end - start, so if start == end then an empty sequence is returned.
NOTE: changes to the underlying byte sequence (if mutable) may render the returned sub-sequence invalid.
start - The start index, inclusive.end - The end index, exclusive.java.lang.IndexOutOfBoundsException - If start or end are negative, if end is greater than length(), or if start is greater than end.byte[] toByteArray()
An invocation of the form:
src.toByteArray()Behaves in exactly the same way as the invocation:
src.copyTo(new byte[src.length()]);
ByteString toByteString()
ByteString representation of this byte sequence.ByteString representation of this byte sequence.java.lang.String toString()
toString in class java.lang.Object