Next and BufferComponent.
Buffer.Note
the iterator object must be closed after use. The easiest way to ensure this, is to use a try-with-resources clause.
The typical code pattern for using this API looks like the following:
try (var iteration = buffer.forEachComponent()) {
for (var c = iteration.first(); c != null; c = c.next()) {
ByteBuffer componentBuffer = c.readableBuffer();
// ...
}
}
Note the use of the var keyword for local variables, which are required for correctly expressing the
generic types used in the iteration.
Following this code pattern will ensure that the components, and their parent buffer, will be correctly
life-cycled.
Buffer#forEachComponent()
| Modifier and Type | Class and Description |
|---|---|
| public static interface | ComponentIterator.Next
This interface exposes external iteration on components. |
| Modifier and Type | Method and Description |
|---|---|
| public T | Returns: The first component of the iteration, ornull if there are no components.Get the first component of the iteration, or |
| public default T | Returns: The first readable component of the iteration, ornull if there are no readable components.Get the first component of the iteration that has any bytes to read, or |
| public default T | Returns: The first writable component of the iteration, ornull if there are no writable components.Get the first component of the iteration that has any space for writing bytes,
or |
| private static <T extends ComponentIterator. | |
| private static <T extends ComponentIterator. |
| first | back to summary |
|---|---|
| public T first() Get the first component of the iteration, or
The object returned will implement both of the
| |
| firstReadable | back to summary |
|---|---|
| public default T firstReadable() Get the first component of the iteration that has any bytes to read, or
The object returned will implement both of the
| |
| firstWritable | back to summary |
|---|---|
| public default T firstWritable() Get the first component of the iteration that has any space for writing bytes,
or
The object returned will implement both of the
| |
| nextReadable | back to summary |
|---|---|
| private static <T extends ComponentIterator. | |
| nextWritable | back to summary |
|---|---|
| private static <T extends ComponentIterator. | |
| Modifier and Type | Method and Description |
|---|---|
| public < A type that implements the N extends ComponentIterator.Next and BufferComponent interfaces. | Returns: The next component in the iteration, ornull if there are no more components.Get the next component of the iteration, or |
| public default <N extends ComponentIterator. | Returns: The next readable component of the iteration, ornull if there are no readable components.Get the next component of the iteration that has any bytes to read, or |
| public default <N extends ComponentIterator. | Returns: The next writable component of the iteration, ornull if there are no writable components.Get the next component of the iteration that has any space for writing bytes,
or |
| next | back to summary |
|---|---|
| public <N extends ComponentIterator. Get the next component of the iteration, or The returned object, if any, will be of the same type as this object, and would typically be assigned to the same variable.
Iteration is only valid while the
| |
| nextReadable | back to summary |
|---|---|
| public default <N extends ComponentIterator. Get the next component of the iteration that has any bytes to read, or
The object returned will implement both of the
| |
| nextWritable | back to summary |
|---|---|
| public default <N extends ComponentIterator. Get the next component of the iteration that has any space for writing bytes,
or
The object returned will implement both of the
| |