Top Description Methods
org.graalvm.polyglot.io

public Interface ByteSequence

Known Direct Implementers
org.graalvm.polyglot.impl.ModuleToUnnamedBridge.ModuleToUnnamedByteSequence, org.graalvm.polyglot.impl.UnnamedToModuleBridge.UnnamedToModuleByteSequence, org.graalvm.polyglot.io.ByteArraySequence
Imports
java.util.NoSuchElementException, .PrimitiveIterator, .Spliterator, .Spliterators, java.util.function.IntConsumer, java.util.stream.IntStream, .StreamSupport

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 TypeMethod and Description
public byte

Returns:

the specified byte value
byteAt
(int
the index of the byte value to be returned
index
)

Returns the byte value at the specified index.

public default IntStream

Returns:

an IntStream of byte values from this sequence
bytes
()

Returns a stream of int zero-extending the byte values from this sequence.

public static ByteSequence
create(byte[] buffer)

Creates a ByteSequence from an existing byte[].

public int

Returns:

the number of bytes in this sequence
length
()

Returns the length of this byte sequence.

public default ByteSequence

Returns:

the specified subsequence
subSequence
(int
the start index, inclusive
startIndex
,
int
the end index, exclusive
endIndex
)

Returns a ByteSequence that is a subsequence of this sequence.

public default byte[]
toByteArray()

Returns a byte[] containing the bytes in this sequence in the same order as this sequence.

Method Detail

byteAtback to summary
public byte byteAt(int index)

Returns the byte value at the specified index. An index ranges from zero to length() - 1. The first char value of the sequence is at index zero, the next at index one, and so on, as for array indexing.

Parameters
index:int

the index of the byte value to be returned

Returns:byte

the specified byte value

Exceptions
IndexOutOfBoundsException:
if the index argument is negative or not less than length()
Since
19.0
bytesback to summary
public default IntStream bytes()

Returns a stream of int zero-extending the byte values from this sequence.

Returns:IntStream

an IntStream of byte values from this sequence

Since
19.0
createback to summary
public static ByteSequence create(byte[] buffer)

Creates a ByteSequence from an existing byte[]. 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
lengthback to summary
public int length()

Returns the length of this byte sequence.

Returns:int

the number of bytes in this sequence

Since
19.0
subSequenceback to summary
public default ByteSequence subSequence(int startIndex, int endIndex)

Returns a ByteSequence that is a subsequence of this sequence. The subsequence starts with the byte value at the specified 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.

Parameters
startIndex:int

the start index, inclusive

endIndex:int

the end index, exclusive

Returns:ByteSequence

the specified subsequence

Exceptions
IndexOutOfBoundsException:
if start or end are negative, if end is greater than length(), or if start is greater than end
Since
19.0
toByteArrayback to summary
public default byte[] toByteArray()

Returns a byte[] 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