Interface ComponentIterator<T extends ComponentIterator.Next>

  • Type Parameters:
    T - A type that implements ComponentIterator.Next, and either ReadableComponent or WritableComponent.
    All Superinterfaces:
    AutoCloseable, io.netty5.util.SafeCloseable
    All Known Implementing Classes:
    SingleComponentIterator

    public interface ComponentIterator<T extends ComponentIterator.Next>
    extends io.netty5.util.SafeCloseable
    A facade for iterating the readable or writable components of a 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.forEachReadable()) {
              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.
    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, or null 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, or null if there are no components.

        The object returned will implement both ComponentIterator.Next, and one of the ReadableComponent or WritableComponent interfaces.

        Returns:
        The first component of the iteration, or null if there are no components.