Module io.netty5.buffer
Package io.netty5.buffer.api
Interface ComponentIterator<T extends ComponentIterator.Next>
-
- Type Parameters:
T
- A type that implementsComponentIterator.Next
, and eitherReadableComponent
orWritableComponent
.
- All Superinterfaces:
AutoCloseable
,SafeCloseable
- All Known Implementing Classes:
SingleComponentIterator
public interface ComponentIterator<T extends ComponentIterator.Next> extends SafeCloseable
A 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.forEachReadable()) { for (var c = iteration.first(); c != null; c = c.next()) { ByteBuffer componentBuffer = c.readableBuffer(); // ... } }
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.- See Also:
Buffer.forEachReadable()
,Buffer.forEachWritable()
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
ComponentIterator.Next
This interface exposes external iteration on components.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description T
first()
Get the first component of the iteration, ornull
if there are no components.-
Methods inherited from interface io.netty5.util.SafeCloseable
close
-
-
-
-
Method Detail
-
first
T first()
Get the first component of the iteration, ornull
if there are no components.The object returned will implement both
ComponentIterator.Next
, and one of theReadableComponent
orWritableComponent
interfaces.- Returns:
- The first component of the iteration, or
null
if there are no components.
-
-