Skip to content

Commit 0e4e8e1

Browse files
authored
Add UnsynchronizedBufferedReader.unwrap() (#850)
1 parent 250ac38 commit 0e4e8e1

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/main/java/org/apache/commons/io/input/UnsynchronizedBufferedReader.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,4 +482,17 @@ public long skip(final long amount) throws IOException {
482482
return amount;
483483
}
484484

485+
/**
486+
* Unwraps this instance by returning the underlying {@link Reader}.
487+
* <p>
488+
* Use with caution.
489+
* </p>
490+
*
491+
* @return the underlying {@link Reader}.
492+
* @since 2.23.0
493+
*/
494+
public Reader unwrap() {
495+
return in;
496+
}
497+
485498
}

src/test/java/org/apache/commons/io/input/UnsynchronizedBufferedReaderTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
2222
import static org.junit.jupiter.api.Assertions.assertEquals;
2323
import static org.junit.jupiter.api.Assertions.assertNull;
24+
import static org.junit.jupiter.api.Assertions.assertSame;
2425
import static org.junit.jupiter.api.Assertions.assertThrows;
2526
import static org.junit.jupiter.api.Assertions.assertTrue;
2627

@@ -633,4 +634,12 @@ void testSkipIllegal() throws IOException {
633634
br = new UnsynchronizedBufferedReader(new StringReader(testString));
634635
assertThrows(IllegalArgumentException.class, () -> br.skip(-1));
635636
}
637+
638+
@SuppressWarnings("resource")
639+
@Test
640+
void testUnwrap() throws IOException {
641+
final StringReader reader = new StringReader(testString);
642+
br = new UnsynchronizedBufferedReader(reader);
643+
assertSame(reader, br.unwrap());
644+
}
636645
}

0 commit comments

Comments
 (0)