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 b856ffc Add factory methods to CloseShieldInputStream, CloseShieldReader, CloseShieldOutputStream, CloseShieldWriter, #173. b856ffc is described below commit b856ffc54736738e680e152763ee2cdfdbb50a0b Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Thu Dec 10 14:14:22 2020 -0500 Add factory methods to CloseShieldInputStream, CloseShieldReader, CloseShieldOutputStream, CloseShieldWriter, #173. Sort methods: static methods come first. Fix some Javadocs. Some formatting. --- src/changes/changes.xml | 3 ++ .../commons/io/input/CloseShieldInputStream.java | 40 +++++++++---------- .../apache/commons/io/input/CloseShieldReader.java | 45 ++++++++++------------ .../commons/io/output/CloseShieldOutputStream.java | 40 +++++++++---------- .../commons/io/output/CloseShieldWriter.java | 39 ++++++++++--------- 5 files changed, 82 insertions(+), 85 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index e5b9c76..3cab9b9 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -94,6 +94,9 @@ The <action> type attribute can be add,update,fix,remove. <action dev="ggregory" type="add" due-to="Gary Gregory"> Add PathUtils.createParentDirectories(Path, FileAttribute...). </action> + <action dev="ggregory" type="add" due-to="Rob Spoor, Gary Gregory"> + Add factory methods to CloseShieldInputStream, CloseShieldReader, CloseShieldOutputStream, CloseShieldWriter, #173. + </action> <!-- UPDATES --> <action dev="ggregory" type="update" due-to="Dependabot"> Update junit-jupiter from 5.6.2 to 5.7.0 #153. diff --git a/src/main/java/org/apache/commons/io/input/CloseShieldInputStream.java b/src/main/java/org/apache/commons/io/input/CloseShieldInputStream.java index 8b31603..35ef834 100644 --- a/src/main/java/org/apache/commons/io/input/CloseShieldInputStream.java +++ b/src/main/java/org/apache/commons/io/input/CloseShieldInputStream.java @@ -22,8 +22,8 @@ import java.io.InputStream; * Proxy stream that prevents the underlying input stream from being closed. * <p> * This class is typically used in cases where an input stream needs to be - * passed to a component that wants to explicitly close the stream even if - * more input would still be available to other components. + * passed to a component that wants to explicitly close the stream even if more + * input would still be available to other components. * </p> * * @since 1.4 @@ -31,13 +31,23 @@ import java.io.InputStream; public class CloseShieldInputStream extends ProxyInputStream { /** - * Creates a proxy that shields the given input stream from being - * closed. + * Creates a proxy that shields the given input stream from being closed. + * + * @param inputStream the input stream to wrap + * @return the created proxy + * @since 2.9.0 + */ + public static CloseShieldInputStream wrap(final InputStream inputStream) { + return new CloseShieldInputStream(inputStream); + } + + /** + * Creates a proxy that shields the given input stream from being closed. * * @param in underlying input stream - * @deprecated Using this constructor prevents IDEs from warning if - * the underlying input stream is never closed. - * Use {@link #wrap(InputStream)} instead. + * @deprecated Using this constructor prevents IDEs from warning if the + * underlying input stream is never closed. Use + * {@link #wrap(InputStream)} instead. */ @Deprecated public CloseShieldInputStream(final InputStream in) { @@ -46,24 +56,12 @@ public class CloseShieldInputStream extends ProxyInputStream { /** * Replaces the underlying input stream with a {@link ClosedInputStream} - * sentinel. The original input stream will remain open, but this proxy - * will appear closed. + * sentinel. The original input stream will remain open, but this proxy will + * appear closed. */ @Override public void close() { in = ClosedInputStream.CLOSED_INPUT_STREAM; } - /** - * Creates a proxy that shields the given input stream from being - * closed. - * - * @param inputStream the input stream to wrap - * @return the created proxy - * @since 2.9.0 - */ - public static CloseShieldInputStream wrap(final InputStream inputStream) { - return new CloseShieldInputStream(inputStream); - } - } diff --git a/src/main/java/org/apache/commons/io/input/CloseShieldReader.java b/src/main/java/org/apache/commons/io/input/CloseShieldReader.java index e1b33b2..2c473cb 100644 --- a/src/main/java/org/apache/commons/io/input/CloseShieldReader.java +++ b/src/main/java/org/apache/commons/io/input/CloseShieldReader.java @@ -19,11 +19,11 @@ package org.apache.commons.io.input; import java.io.Reader; /** - * Proxy stream that prevents the underlying reader from being closed. + * Proxy reader that prevents the underlying reader from being closed. * <p> - * This class is typically used in cases where a reader needs to be - * passed to a component that wants to explicitly close the reader even if - * more input would still be available to other components. + * This class is typically used in cases where a reader needs to be passed to a + * component that wants to explicitly close the reader even if more input would + * still be available to other components. * </p> * * @since 2.7 @@ -31,13 +31,23 @@ import java.io.Reader; public class CloseShieldReader extends ProxyReader { /** - * Creates a proxy that shields the given reader from being - * closed. + * Creates a proxy that shields the given reader from being closed. + * + * @param reader the reader to wrap + * @return the created proxy + * @since 2.9.0 + */ + public static CloseShieldReader wrap(final Reader reader) { + return new CloseShieldReader(reader); + } + + /** + * Creates a proxy that shields the given reader from being closed. * * @param in underlying reader - * @deprecated Using this constructor prevents IDEs from warning if - * the underlying reader is never closed. - * Use {@link #wrap(Reader)} instead. + * @deprecated Using this constructor prevents IDEs from warning if the + * underlying reader is never closed. Use {@link #wrap(Reader)} + * instead. */ @Deprecated public CloseShieldReader(final Reader in) { @@ -45,25 +55,12 @@ public class CloseShieldReader extends ProxyReader { } /** - * Replaces the underlying reader with a {@link ClosedReader} - * sentinel. The original reader will remain open, but this proxy - * will appear closed. + * Replaces the underlying reader with a {@link ClosedReader} sentinel. The + * original reader will remain open, but this proxy will appear closed. */ @Override public void close() { in = ClosedReader.CLOSED_READER; } - /** - * Creates a proxy that shields the given reader from being - * closed. - * - * @param reader the reader to wrap - * @return the created proxy - * @since 2.9.0 - */ - public static CloseShieldReader wrap(final Reader reader) { - return new CloseShieldReader(reader); - } - } diff --git a/src/main/java/org/apache/commons/io/output/CloseShieldOutputStream.java b/src/main/java/org/apache/commons/io/output/CloseShieldOutputStream.java index 6a0db0e..7c9cd40 100644 --- a/src/main/java/org/apache/commons/io/output/CloseShieldOutputStream.java +++ b/src/main/java/org/apache/commons/io/output/CloseShieldOutputStream.java @@ -22,8 +22,8 @@ import java.io.OutputStream; * Proxy stream that prevents the underlying output stream from being closed. * <p> * This class is typically used in cases where an output stream needs to be - * passed to a component that wants to explicitly close the stream even if - * other components would still use the stream for output. + * passed to a component that wants to explicitly close the stream even if other + * components would still use the stream for output. * </p> * * @since 1.4 @@ -31,13 +31,23 @@ import java.io.OutputStream; public class CloseShieldOutputStream extends ProxyOutputStream { /** - * Creates a proxy that shields the given output stream from being - * closed. + * Creates a proxy that shields the given output stream from being closed. + * + * @param outputStream the output stream to wrap + * @return the created proxy + * @since 2.9.0 + */ + public static CloseShieldOutputStream wrap(final OutputStream outputStream) { + return new CloseShieldOutputStream(outputStream); + } + + /** + * Creates a proxy that shields the given output stream from being closed. * * @param out underlying output stream - * @deprecated Using this constructor prevents IDEs from warning if - * the underlying output stream is never closed. - * Use {@link #wrap(OutputStream)} instead. + * @deprecated Using this constructor prevents IDEs from warning if the + * underlying output stream is never closed. Use + * {@link #wrap(OutputStream)} instead. */ @Deprecated public CloseShieldOutputStream(final OutputStream out) { @@ -46,24 +56,12 @@ public class CloseShieldOutputStream extends ProxyOutputStream { /** * Replaces the underlying output stream with a {@link ClosedOutputStream} - * sentinel. The original output stream will remain open, but this proxy - * will appear closed. + * sentinel. The original output stream will remain open, but this proxy will + * appear closed. */ @Override public void close() { out = ClosedOutputStream.CLOSED_OUTPUT_STREAM; } - /** - * Creates a proxy that shields the given output stream from being - * closed. - * - * @param outputStream the output stream to wrap - * @return the created proxy - * @since 2.9.0 - */ - public static CloseShieldOutputStream wrap(final OutputStream outputStream) { - return new CloseShieldOutputStream(outputStream); - } - } diff --git a/src/main/java/org/apache/commons/io/output/CloseShieldWriter.java b/src/main/java/org/apache/commons/io/output/CloseShieldWriter.java index 4a1efa1..c9c696e 100644 --- a/src/main/java/org/apache/commons/io/output/CloseShieldWriter.java +++ b/src/main/java/org/apache/commons/io/output/CloseShieldWriter.java @@ -19,10 +19,11 @@ package org.apache.commons.io.output; import java.io.Writer; /** - * Proxy stream that prevents the underlying writer from being closed. + * Proxy writer that prevents the underlying writer from being closed. * <p> - * This class is typically used in cases where a writer needs to be passed to a component that wants to explicitly close - * the writer even if other components would still use the writer for output. + * This class is typically used in cases where a writer needs to be passed to a + * component that wants to explicitly close the writer even if other components + * would still use the writer for output. * </p> * * @since 2.7 @@ -32,10 +33,21 @@ public class CloseShieldWriter extends ProxyWriter { /** * Creates a proxy that shields the given writer from being closed. * + * @param writer the writer to wrap + * @return the created proxy + * @since 2.9.0 + */ + public static CloseShieldWriter wrap(final Writer writer) { + return new CloseShieldWriter(writer); + } + + /** + * Creates a proxy that shields the given writer from being closed. + * * @param out underlying writer - * @deprecated Using this constructor prevents IDEs from warning if - * the underlying writer is never closed. - * Use {@link #wrap(Writer)} instead. + * @deprecated Using this constructor prevents IDEs from warning if the + * underlying writer is never closed. Use {@link #wrap(Writer)} + * instead. */ @Deprecated public CloseShieldWriter(final Writer out) { @@ -43,23 +55,12 @@ public class CloseShieldWriter extends ProxyWriter { } /** - * Replaces the underlying writer with a {@link ClosedWriter} sentinel. The original writer will remain open, but - * this proxy will appear closed. + * Replaces the underlying writer with a {@link ClosedWriter} sentinel. The + * original writer will remain open, but this proxy will appear closed. */ @Override public void close() { out = ClosedWriter.CLOSED_WRITER; } - /** - * Creates a proxy that shields the given writer from being closed. - * - * @param writer the writer to wrap - * @return the created proxy - * @since 2.9.0 - */ - public static CloseShieldWriter wrap(final Writer writer) { - return new CloseShieldWriter(writer); - } - }