diff --git a/src/main/java/org/apache/commons/io/input/UnsynchronizedBufferedReader.java b/src/main/java/org/apache/commons/io/input/UnsynchronizedBufferedReader.java index b5484116c32..c12869d6fbe 100644 --- a/src/main/java/org/apache/commons/io/input/UnsynchronizedBufferedReader.java +++ b/src/main/java/org/apache/commons/io/input/UnsynchronizedBufferedReader.java @@ -482,4 +482,17 @@ public long skip(final long amount) throws IOException { return amount; } + /** + * Unwraps this instance by returning the underlying {@link Reader}. + *

+ * Use with caution. + *

+ * + * @return the underlying {@link Reader}. + * @since 2.23.0 + */ + public Reader unwrap() { + return in; + } + } diff --git a/src/test/java/org/apache/commons/io/input/UnsynchronizedBufferedReaderTest.java b/src/test/java/org/apache/commons/io/input/UnsynchronizedBufferedReaderTest.java index 3638970a7e9..e45c1dff9d6 100644 --- a/src/test/java/org/apache/commons/io/input/UnsynchronizedBufferedReaderTest.java +++ b/src/test/java/org/apache/commons/io/input/UnsynchronizedBufferedReaderTest.java @@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -633,4 +634,12 @@ void testSkipIllegal() throws IOException { br = new UnsynchronizedBufferedReader(new StringReader(testString)); assertThrows(IllegalArgumentException.class, () -> br.skip(-1)); } + + @SuppressWarnings("resource") + @Test + void testUnwrap() throws IOException { + final StringReader reader = new StringReader(testString); + br = new UnsynchronizedBufferedReader(reader); + assertSame(reader, br.unwrap()); + } }