1515 */
1616package io .netty .buffer .api ;
1717
18+ import io .netty .buffer .api .ComponentProcessor .OfReadable ;
19+ import io .netty .buffer .api .ComponentProcessor .OfWritable ;
20+ import io .netty .buffer .api .ComponentProcessor .ReadableComponent ;
21+ import io .netty .buffer .api .ComponentProcessor .WritableComponent ;
22+
1823import java .nio .ByteBuffer ;
1924import java .nio .ByteOrder ;
2025
@@ -493,7 +498,7 @@ default void ensureWritable(int size) {
493498
494499 /**
495500 * Get the number of "components" in this buffer, that are readable. These are the components that would be
496- * processed by {@link #forEachReadable(int, ComponentProcessor )}. For composite buffers, this is the number of
501+ * processed by {@link #forEachReadable(int, OfReadable )}. For composite buffers, this is the number of
497502 * transitive constituent buffers that are readable, while non-composite buffers only have at most one readable
498503 * component.
499504 * <p>
@@ -506,7 +511,7 @@ default void ensureWritable(int size) {
506511
507512 /**
508513 * Get the number of "components" in this buffer, that are writable. These are the components that would be
509- * processed by {@link #forEachWritable(int, ComponentProcessor )}. For composite buffers, this is the number of
514+ * processed by {@link #forEachWritable(int, OfWritable )}. For composite buffers, this is the number of
510515 * transitive constituent buffers that are writable, while non-composite buffers only have at most one writable
511516 * component.
512517 * <p>
@@ -520,20 +525,20 @@ default void ensureWritable(int size) {
520525 /**
521526 * Process all readable components of this buffer, and return the number of components processed.
522527 * <p>
523- * The given {@linkplain ComponentProcessor processor} is called for each component in this buffer, and passed a
524- * component index, for the given component in the iteration, and a {@link Component } object for accessing the data
525- * within the given component.
528+ * The given {@linkplain OfReadable processor} is called for each readable component in this buffer,
529+ * and passed a component index, for the given component in the iteration, and a {@link ReadableComponent } object
530+ * for accessing the data within the given component.
526531 * <p>
527- * The component index is specific to the particular invokation of this method, and may change. The first call to
528- * the consumer will be passed the given initial index, and the next call will be passed the initial index plus one,
529- * and so on.
532+ * The component index is specific to the particular invokation of this method. The first call to the consumer will
533+ * be passed the given initial index, and the next call will be passed the initial index plus one, and so on.
530534 * <p>
531- * The {@link ComponentProcessor} may stop the iteration at any time by returning {@code false}. This may cause the
532- * number of components processed to be returned as a negative number (to signal early return), and the number of
533- * components processed may then be less than the {@linkplain #countReadableComponents() readable component count}.
535+ * The {@linkplain OfReadable component processor} may stop the iteration at any time by returning {@code false}.
536+ * This will cause the number of components processed to be returned as a negative number (to signal early return),
537+ * and the number of components processed may then be less than the
538+ * {@linkplain #countReadableComponents() readable component count}.
534539 * <p>
535- * <strong>Note</strong> that the {@link Component } instance passed to the consumer could be reused for multiple
536- * calls, so the data must be extracted from the component in the context of the iteration.
540+ * <strong>Note</strong> that the {@link ReadableComponent } instance passed to the consumer could be reused for
541+ * multiple calls, so the data must be extracted from the component in the context of the iteration.
537542 * <p>
538543 * The {@link ByteBuffer} instances obtained from the component, share life time with that internal component.
539544 * This means they can be accessed as long as the internal memory store remain unchanged. Methods that may cause
@@ -549,14 +554,50 @@ default void ensureWritable(int size) {
549554 * this buffer instance.
550555 *
551556 * @param initialIndex The initial index of the iteration, and the index that will be passed to the first call to
552- * the {@linkplain ComponentProcessor #process(int, Component ) processor}.
557+ * the {@linkplain OfReadable #process(int, ReadableComponent ) processor}.
553558 * @param processor The processor that will be used to process the buffer components.
554559 * @return The number of readable components processed, as a positive number of all readable components were
555560 * processed, or as a negative number if the iteration was stopped because
556- * {@link ComponentProcessor #process(int, Component )} returned {@code false}.
561+ * {@link OfReadable #process(int, ReadableComponent )} returned {@code false}.
557562 * In any case, the number of components processed may be less than {@link #countComponents()}.
558563 */
559- int forEachReadable (int initialIndex , ComponentProcessor processor );
564+ int forEachReadable (int initialIndex , OfReadable processor );
560565
561- int forEachWritable (int initialIndex , ComponentProcessor processor );
566+ /**
567+ * Process all writable components of this buffer, and return the number of components processed.
568+ * <p>
569+ * The given {@linkplain OfWritable processor} is called for each writable component in this buffer,
570+ * and passed a component index, for the given component in the iteration, and a {@link WritableComponent} object
571+ * for accessing the data within the given component.
572+ * <p>
573+ * The component index is specific to the particular invokation of this method. The first call to the consumer will
574+ * be passed the given initial index, and the next call will be passed the initial index plus one, and so on.
575+ * <p>
576+ * The {@link OfWritable component processor} may stop the iteration at any time by returning {@code false}.
577+ * This will cause the number of components processed to be returned as a negative number (to signal early return),
578+ * and the number of components processed may then be less than the
579+ * {@linkplain #countReadableComponents() readable component count}.
580+ * <p>
581+ * <strong>Note</strong> that the {@link WritableComponent} instance passed to the consumer could be reused for
582+ * multiple calls, so the data must be extracted from the component in the context of the iteration.
583+ * <p>
584+ * The {@link ByteBuffer} instances obtained from the component, share life time with that internal component.
585+ * This means they can be accessed as long as the internal memory store remain unchanged. Methods that may cause
586+ * such changes, are any method that requires the buffer to be {@linkplain #isOwned() owned}.
587+ * <p>
588+ * The best way to ensure this doesn't cause any trouble, is to use the buffers directly as part of the iteration,
589+ * or immediately after the iteration.
590+ * <p>
591+ * Changes to position and limit of the byte buffers exposed via the processed components, are not reflected back to
592+ * this buffer instance.
593+ *
594+ * @param initialIndex The initial index of the iteration, and the index that will be passed to the first call to
595+ * the {@linkplain OfWritable#process(int, WritableComponent) processor}.
596+ * @param processor The processor that will be used to process the buffer components.
597+ * @return The number of writable components processed, as a positive number of all writable components were
598+ * processed, or as a negative number if the iteration was stopped because
599+ * {@link OfWritable#process(int, WritableComponent)} returned {@code false}.
600+ * In any case, the number of components processed may be less than {@link #countComponents()}.
601+ */
602+ int forEachWritable (int initialIndex , OfWritable processor );
562603}
0 commit comments