You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/01/28 14:22:10 UTC
(commons-io) branch master updated: Add and use AbstractStreamBuilder.getReader()
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push:
new 3b95c8c4 Add and use AbstractStreamBuilder.getReader()
3b95c8c4 is described below
commit 3b95c8c4987955b2f3bedc37dc217cb2e190b63d
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Jan 28 09:22:05 2024 -0500
Add and use AbstractStreamBuilder.getReader()
Update Javadoc
---
src/changes/changes.xml | 1 +
.../apache/commons/io/build/AbstractStreamBuilder.java | 18 +++++++++++++++++-
.../org/apache/commons/io/input/ReaderInputStream.java | 9 ++++-----
.../commons/io/input/UncheckedBufferedReader.java | 15 ++++++---------
.../apache/commons/io/input/UncheckedFilterReader.java | 11 ++++-------
5 files changed, 32 insertions(+), 22 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 4fd5b2a3..2e1a1628 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -123,6 +123,7 @@ The <action> type attribute can be add,update,fix,remove.
<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 7b113237..519c2cf0 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 @@ package org.apache.commons.io.build;
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 @@ public abstract class AbstractStreamBuilder<T, B extends AbstractStreamBuilder<T
}
/**
- * 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 c4e44eea..a9ea2351 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 java.util.Objects;
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 @@ public class ReaderInputStream extends InputStream {
* 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 @@ public class ReaderInputStream extends InputStream {
* @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 30f52d88..a8b46b79 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.IOException;
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 @@ public final class UncheckedBufferedReader extends BufferedReader {
* 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 e366461c..176e8bcc 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.IOException;
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 @@ public final class UncheckedFilterReader extends FilterReader {
/**
* 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()));
}
}