Add factory methods to CloseShieldInputStream, CloseShieldReader,
CloseShieldOutputStream, CloseShieldWriter,
Sort methods: static methods come first.
Fix some Javadocs.
Some formatting.
MODIFY
src/changes/changes.xml
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.

MODIFY
src/main/java/org/apache/commons/io/input/CloseShieldInputStream.java
src/main/java/org/apache/commons/io/input/CloseShieldInputStream.java
* 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
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 CloseShieldInputStream(final InputStream in) {
/**
* 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);
- }
-
}

MODIFY
src/main/java/org/apache/commons/io/input/CloseShieldReader.java
src/main/java/org/apache/commons/io/input/CloseShieldReader.java
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
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 CloseShieldReader(final Reader in) {
}
/**
- * 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);
- }
-
}

MODIFY
src/main/java/org/apache/commons/io/output/CloseShieldOutputStream.java
src/main/java/org/apache/commons/io/output/CloseShieldOutputStream.java
* 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
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 CloseShieldOutputStream(final OutputStream out) {
/**
* 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);
- }
-
}

MODIFY
src/main/java/org/apache/commons/io/output/CloseShieldWriter.java
src/main/java/org/apache/commons/io/output/CloseShieldWriter.java
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
*/
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 CloseShieldWriter(final Writer out) {
}
/**
- * 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);
- }
-
}

Add factory methods to CloseShieldInputStream, CloseShieldReader,
CloseShieldOutputStream, CloseShieldWriter, #173.

Sort methods: static methods come first.
Fix some Javadocs.
Some formatting.