File tree Expand file tree Collapse file tree 3 files changed +27
-2
lines changed
main/java/org/apache/commons/io
test/java/org/apache/commons/io/function Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -37,8 +37,7 @@ public interface IOIterable<T> {
3737 * @see Iterable#iterator()
3838 */
3939 default void forEach (final IOConsumer <? super T > action ) throws IOException {
40- Objects .requireNonNull (action );
41- iterator ().forEachRemaining (action );
40+ iterator ().forEachRemaining (Objects .requireNonNull (action ));
4241 }
4342
4443 /**
@@ -59,4 +58,13 @@ default IOSpliterator<T> spliterator() {
5958 return IOSpliteratorAdapter .adapt (new UncheckedIOIterable <>(this ).spliterator ());
6059 }
6160
61+ /**
62+ * Unwraps this instance and returns the underlying {@link Iterable}.
63+ * <p>
64+ * Implementations may not have anything to unwrap and that behavior is undefined for now.
65+ * </p>
66+ * @return the underlying Iterable.
67+ */
68+ Iterable <T > unwrap ();
69+
6270}
Original file line number Diff line number Diff line change @@ -584,4 +584,9 @@ public String toString(final int lineCount) throws IOException {
584584 return lines .isEmpty () ? EMPTY_STRING : String .join (System .lineSeparator (), lines ) + System .lineSeparator ();
585585 }
586586
587+ @ Override
588+ public Iterable <String > unwrap () {
589+ return null ;
590+ }
591+
587592}
Original file line number Diff line number Diff line change 1818package org .apache .commons .io .function ;
1919
2020import static org .junit .jupiter .api .Assertions .assertEquals ;
21+ import static org .junit .jupiter .api .Assertions .assertSame ;
2122import static org .junit .jupiter .api .Assertions .assertThrows ;
2223
2324import java .io .IOException ;
@@ -44,6 +45,11 @@ public IOIterator<Path> iterator() {
4445 return IOIterator .adapt (list );
4546 }
4647
48+ @ Override
49+ public Iterable <Path > unwrap () {
50+ return list ;
51+ }
52+
4753 }
4854
4955 private IOIterable <Path > iterable ;
@@ -76,4 +82,10 @@ public void testSpliterator() throws IOException {
7682 iterable .spliterator ().forEachRemaining (e -> ref .incrementAndGet ());
7783 assertEquals (2 , ref .get ());
7884 }
85+
86+ @ Test
87+ public void testUnrwap () throws IOException {
88+ assertSame (fixture .list , iterable .unwrap ());
89+ assertSame (fixture .unwrap (), iterable .unwrap ());
90+ }
7991}
You can’t perform that action at this time.
0 commit comments