Add and use AbstractStreamBuilder.getReader()
Update Javadoc
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 4fd5b2a..2e1a162 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -123,6 +123,7 @@
<action dev="ggregory" type="add" due-to="Gary Gregory">Add ThrottledInputStream.</action>
<action dev="ggregory" type="add" due-to="Gary Gregory">Add IORunnable.noop().</action>
<action dev="ggregory" type="add" due-to="Gary Gregory">Add ChecksumInputStream and test #548.</action>
+ <action dev="ggregory" type="add" due-to="Gary Gregory">Add AbstractStreamBuilder.getReader().</action>
<!-- UPDATE -->
<action dev="ggregory" type="fix" due-to="Gary Gregory">Bump commons.bytebuddy.version from 1.14.10 to 1.14.11 #534.</action>
</release>
diff --git a/src/main/java/org/apache/commons/io/build/AbstractStreamBuilder.java b/src/main/java/org/apache/commons/io/build/AbstractStreamBuilder.java
index 7b11323..519c2cf 100644
--- a/src/main/java/org/apache/commons/io/build/AbstractStreamBuilder.java
+++ b/src/main/java/org/apache/commons/io/build/AbstractStreamBuilder.java
@@ -20,6 +20,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.io.Reader;
import java.io.Writer;
import java.nio.charset.Charset;
import java.nio.file.OpenOption;
@@ -193,7 +194,22 @@
}
/**
- * Gets a Writer from the origin with OpenOption[].
+ * Gets a Reader from the origin with a Charset.
+ *
+ * @return A Reader
+ * @throws IllegalStateException if the {@code origin} is {@code null}.
+ * @throws UnsupportedOperationException if the origin cannot be converted to a {@link Reader}.
+ * @throws IOException if an I/O error occurs.
+ * @see AbstractOrigin#getReader(Charset)
+ * @see #getCharset()
+ * @since 2.16.0
+ */
+ protected Reader getReader() throws IOException {
+ return checkOrigin().getReader(getCharset());
+ }
+
+ /**
+ * Gets a Writer from the origin with an OpenOption[].
*
* @return An writer.
* @throws IllegalStateException if the {@code origin} is {@code null}.
diff --git a/src/main/java/org/apache/commons/io/input/ReaderInputStream.java b/src/main/java/org/apache/commons/io/input/ReaderInputStream.java
index c4e44ee..a9ea235 100644
--- a/src/main/java/org/apache/commons/io/input/ReaderInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/ReaderInputStream.java
@@ -31,7 +31,6 @@
import org.apache.commons.io.Charsets;
import org.apache.commons.io.IOUtils;
-import org.apache.commons.io.build.AbstractOrigin;
import org.apache.commons.io.build.AbstractStreamBuilder;
import org.apache.commons.io.charset.CharsetEncoders;
@@ -111,13 +110,13 @@
* Builds a new {@link ReaderInputStream}.
*
* <p>
- * You must set input that supports {@link Reader}, otherwise, this method throws an exception.
+ * You must set input that supports {@link #getReader()}, otherwise, this method throws an exception.
* </p>
* <p>
* This builder use the following aspects:
* </p>
* <ul>
- * <li>{@link Reader}</li>
+ * <li>{@link #getReader()}</li>
* <li>{@link #getBufferSize()}</li>
* <li>{@link #getCharset()}</li>
* <li>{@link CharsetEncoder}</li>
@@ -126,14 +125,14 @@
* @return a new instance.
* @throws UnsupportedOperationException if the origin cannot provide a Reader.
* @throws IllegalStateException if the {@code origin} is {@code null}.
- * @see AbstractOrigin#getReader(Charset)
+ * @see #getReader()
* @see CharsetEncoder
* @see #getBufferSize()
*/
@SuppressWarnings("resource")
@Override
public ReaderInputStream get() throws IOException {
- return new ReaderInputStream(checkOrigin().getReader(getCharset()), charsetEncoder, getBufferSize());
+ return new ReaderInputStream(getReader(), charsetEncoder, getBufferSize());
}
CharsetEncoder getCharsetEncoder() {
diff --git a/src/main/java/org/apache/commons/io/input/UncheckedBufferedReader.java b/src/main/java/org/apache/commons/io/input/UncheckedBufferedReader.java
index 30f52d8..a8b46b7 100644
--- a/src/main/java/org/apache/commons/io/input/UncheckedBufferedReader.java
+++ b/src/main/java/org/apache/commons/io/input/UncheckedBufferedReader.java
@@ -22,9 +22,7 @@
import java.io.Reader;
import java.io.UncheckedIOException;
import java.nio.CharBuffer;
-import java.nio.charset.Charset;
-import org.apache.commons.io.build.AbstractOrigin;
import org.apache.commons.io.build.AbstractStreamBuilder;
import org.apache.commons.io.function.Uncheck;
@@ -76,27 +74,26 @@
* Builds a new {@link UncheckedBufferedReader}.
*
* <p>
+ * You must set input that supports {@link #getReader()} on this builder, otherwise, this method throws an exception.
+ * </p>
+ * <p>
* This builder use the following aspects:
* </p>
* <ul>
- * <li>{@link Reader}</li>
+ * <li>{@link #getReader()}</li>
* <li>{@link #getBufferSize()}</li>
* </ul>
- * <p>
- * You must provide an origin that can be converted to a Reader by this builder, otherwise, this call will throw an
- * {@link UnsupportedOperationException}.
- * </p>
*
* @return a new instance.
* @throws UnsupportedOperationException if the origin cannot provide a Reader.
* @throws IllegalStateException if the {@code origin} is {@code null}.
- * @see AbstractOrigin#getReader(Charset)
+ * @see #getReader()
* @see #getBufferSize()
*/
@Override
public UncheckedBufferedReader get() {
// This an unchecked class, so this method is as well.
- return Uncheck.get(() -> new UncheckedBufferedReader(checkOrigin().getReader(getCharset()), getBufferSize()));
+ return Uncheck.get(() -> new UncheckedBufferedReader(getReader(), getBufferSize()));
}
}
diff --git a/src/main/java/org/apache/commons/io/input/UncheckedFilterReader.java b/src/main/java/org/apache/commons/io/input/UncheckedFilterReader.java
index e366461..176e8bc 100644
--- a/src/main/java/org/apache/commons/io/input/UncheckedFilterReader.java
+++ b/src/main/java/org/apache/commons/io/input/UncheckedFilterReader.java
@@ -22,9 +22,7 @@
import java.io.Reader;
import java.io.UncheckedIOException;
import java.nio.CharBuffer;
-import java.nio.charset.Charset;
-import org.apache.commons.io.build.AbstractOrigin;
import org.apache.commons.io.build.AbstractStreamBuilder;
import org.apache.commons.io.function.Uncheck;
@@ -71,25 +69,24 @@
/**
* Builds a new {@link UncheckedFilterReader}.
* <p>
- * You must set input that supports {@link Reader} on this builder, otherwise, this method throws an exception.
+ * You must set input that supports {@link #getReader()} on this builder, otherwise, this method throws an exception.
* </p>
* <p>
* This builder use the following aspects:
* </p>
* <ul>
- * <li>{@link Reader}</li>
- * <li>{@link #getCharset()}</li>
+ * <li>{@link #getReader()}</li>
* </ul>
*
* @return a new instance.
* @throws UnsupportedOperationException if the origin cannot provide a Reader.
* @throws IllegalStateException if the {@code origin} is {@code null}.
- * @see AbstractOrigin#getReader(Charset)
+ * @see #getReader()
*/
@Override
public UncheckedFilterReader get() {
// This an unchecked class, so this method is as well.
- return Uncheck.get(() -> new UncheckedFilterReader(checkOrigin().getReader(getCharset())));
+ return Uncheck.get(() -> new UncheckedFilterReader(getReader()));
}
}