Module io.netty5.buffer
Package io.netty5.buffer
Interface ComponentIterator<T extends ComponentIterator.Next & BufferComponent>
-
- Type Parameters:
T- A type that implementsComponentIterator.NextandBufferComponent.
- All Superinterfaces:
AutoCloseable,io.netty5.util.SafeCloseable
public interface ComponentIterator<T extends ComponentIterator.Next & BufferComponent> extends io.netty5.util.SafeCloseableA facade for iterating the readable or writable components of aBuffer.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:
Note the use of thetry (var iteration = buffer.forEachComponent()) { for (var c = iteration.first(); c != null; c = c.next()) { ByteBuffer componentBuffer = c.readableBuffer(); // ... } }varkeyword 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.- See Also:
Buffer.forEachComponent()
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceComponentIterator.NextThis interface exposes external iteration on components.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Tfirst()Get the first component of the iteration, ornullif there are no components.default TfirstReadable()Get the first component of the iteration that has any bytes to read, ornullif there are no components with any readable bytes.default TfirstWritable()Get the first component of the iteration that has any space for writing bytes, ornullif there are no components with any spare capacity.
-
-
-
Method Detail
-
first
T first()
Get the first component of the iteration, ornullif there are no components.The object returned will implement both of the
ComponentIterator.NextandBufferComponentinterfaces.- Returns:
- The first component of the iteration, or
nullif there are no components.
-
firstReadable
default T firstReadable()
Get the first component of the iteration that has any bytes to read, ornullif there are no components with any readable bytes.The object returned will implement both of the
ComponentIterator.NextandBufferComponentinterfaces.- Returns:
- The first readable component of the iteration, or
nullif there are no readable components.
-
firstWritable
default T firstWritable()
Get the first component of the iteration that has any space for writing bytes, ornullif there are no components with any spare capacity.The object returned will implement both of the
ComponentIterator.NextandBufferComponentinterfaces.- Returns:
- The first writable component of the iteration, or
nullif there are no writable components.
-
-