Module io.netty5.buffer
Package io.netty5.buffer
Interface ComponentIterator<T extends ComponentIterator.Next & BufferComponent>
-
- Type Parameters:
T
- A type that implementsComponentIterator.Next
andBufferComponent
.
- All Superinterfaces:
AutoCloseable
,io.netty5.util.SafeCloseable
public interface ComponentIterator<T extends ComponentIterator.Next & BufferComponent> extends io.netty5.util.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.forEachComponent()) { 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.forEachComponent()
-
-
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 Default Methods Modifier and Type Method Description T
first()
Get the first component of the iteration, ornull
if there are no components.default T
firstReadable()
Get the first component of the iteration that has any bytes to read, ornull
if there are no components with any readable bytes.default T
firstWritable()
Get the first component of the iteration that has any space for writing bytes, ornull
if there are no components with any spare capacity.
-
-
-
Method Detail
-
first
T first()
Get the first component of the iteration, ornull
if there are no components.The object returned will implement both of the
ComponentIterator.Next
andBufferComponent
interfaces.- Returns:
- The first component of the iteration, or
null
if there are no components.
-
firstReadable
default T firstReadable()
Get the first component of the iteration that has any bytes to read, ornull
if there are no components with any readable bytes.The object returned will implement both of the
ComponentIterator.Next
andBufferComponent
interfaces.- Returns:
- The first readable component of the iteration, or
null
if there are no readable components.
-
firstWritable
default T firstWritable()
Get the first component of the iteration that has any space for writing bytes, ornull
if there are no components with any spare capacity.The object returned will implement both of the
ComponentIterator.Next
andBufferComponent
interfaces.- Returns:
- The first writable component of the iteration, or
null
if there are no writable components.
-
-