This is an automated email from the ASF dual-hosted git repository.
Claudenw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/creadur-rat.git
The following commit(s) were added to refs/heads/master by this push:
new 21ef18dd RAT-551: Replace NoCloseOutputStream with Apache Commons
CloseShieldOutputStream (#653)
21ef18dd is described below
commit 21ef18dd264e0d7ef7ae9ca36312bd00a80702c3
Author: Claude Warren <[email protected]>
AuthorDate: Sat May 2 15:21:44 2026 +0200
RAT-551: Replace NoCloseOutputStream with Apache Commons
CloseShieldOutputStream (#653)
* Replace NoCloseOutputStream with apahe commons CloseShieldOutputStream
Co-authored-by: P. Ottlinger <[email protected]>
---
.../java/org/apache/rat/ReportConfiguration.java | 67 ++--------------------
.../org/apache/rat/ReportConfigurationTest.java | 4 +-
.../main/java/org/apache/rat/anttasks/Report.java | 3 +-
src/changes/changes.xml | 3 +
4 files changed, 11 insertions(+), 66 deletions(-)
diff --git
a/apache-rat-core/src/main/java/org/apache/rat/ReportConfiguration.java
b/apache-rat-core/src/main/java/org/apache/rat/ReportConfiguration.java
index aacd360b..799dfaf5 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/ReportConfiguration.java
+++ b/apache-rat-core/src/main/java/org/apache/rat/ReportConfiguration.java
@@ -39,6 +39,7 @@ import java.util.SortedSet;
import java.util.function.Consumer;
import org.apache.commons.io.function.IOSupplier;
+import org.apache.commons.io.output.CloseShieldOutputStream;
import org.apache.rat.analysis.IHeaderMatcher;
import org.apache.rat.commandline.StyleSheets;
import org.apache.rat.config.AddLicenseHeaders;
@@ -504,10 +505,10 @@ public class ReportConfiguration {
* Sets the supplier for the output stream. The supplier may be called
multiple
* times to provide the stream. Suppliers should prepare streams that are
* appended to and that can be closed. If an {@code OutputStream} should
not be
- * closed consider wrapping it in a {@code NoCloseOutputStream}
+ * closed consider wrapping it in a {@code CloseShieldOutputStream}
* @param out The OutputStream supplier that provides the output stream to
write
* the report to. A null value will use System.out.
- * @see NoCloseOutputStream
+ * @see CloseShieldOutputStream
*/
public void setOut(final IOSupplier<OutputStream> out) {
this.out = out;
@@ -542,7 +543,7 @@ public class ReportConfiguration {
* @return The supplier of the output stream to write the report to.
*/
public IOSupplier<OutputStream> getOutput() {
- return out == null ? () -> new NoCloseOutputStream(System.out) : out;
+ return out == null ? () -> CloseShieldOutputStream.wrap(System.out) :
out;
}
/**
@@ -841,64 +842,4 @@ public class ReportConfiguration {
throw new ConfigurationException(msg);
}
}
-
- /**
- * A wrapper around an output stream that does not close the output stream.
- */
- public static class NoCloseOutputStream extends OutputStream {
- /** the output stream this stream wraps */
- private final OutputStream delegate;
-
- /**
- * Constructor.
- * @param delegate the output stream to wrap.
- */
- public NoCloseOutputStream(final OutputStream delegate) {
- this.delegate = delegate;
- }
-
- @Override
- public void write(final int arg0) throws IOException {
- delegate.write(arg0);
- }
-
- /**
- * Does not actually close the delegate. But does perform a flush.
- * @throws IOException on Error.
- */
- @Override
- public void close() throws IOException {
- this.delegate.flush();
- }
-
- @Override
- public boolean equals(final Object obj) {
- return delegate.equals(obj);
- }
-
- @Override
- public void flush() throws IOException {
- delegate.flush();
- }
-
- @Override
- public int hashCode() {
- return delegate.hashCode();
- }
-
- @Override
- public String toString() {
- return delegate.toString();
- }
-
- @Override
- public void write(final byte[] arg0, final int arg1, final int arg2)
throws IOException {
- delegate.write(arg0, arg1, arg2);
- }
-
- @Override
- public void write(final byte[] b) throws IOException {
- delegate.write(b);
- }
- }
}
diff --git
a/apache-rat-core/src/test/java/org/apache/rat/ReportConfigurationTest.java
b/apache-rat-core/src/test/java/org/apache/rat/ReportConfigurationTest.java
index 8ff47a28..69af88b2 100644
--- a/apache-rat-core/src/test/java/org/apache/rat/ReportConfigurationTest.java
+++ b/apache-rat-core/src/test/java/org/apache/rat/ReportConfigurationTest.java
@@ -41,7 +41,7 @@ import java.util.SortedSet;
import java.util.function.Function;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
-import org.apache.rat.ReportConfiguration.NoCloseOutputStream;
+import org.apache.commons.io.output.CloseShieldOutputStream;
import org.apache.rat.analysis.IHeaderMatcher;
import org.apache.rat.config.AddLicenseHeaders;
import org.apache.rat.config.exclusion.StandardCollection;
@@ -452,7 +452,7 @@ public class ReportConfigurationTest {
@Test
public void outputTest() throws IOException {
-
assertThat(underTest.getOutput().get()).isExactlyInstanceOf(NoCloseOutputStream.class);
+
assertThat(underTest.getOutput().get()).isExactlyInstanceOf(CloseShieldOutputStream.class);
assertThat(underTest.getWriter()).isNotNull();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
diff --git a/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java
b/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java
index 1dd3414a..a069084f 100644
--- a/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java
+++ b/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java
@@ -29,6 +29,7 @@ import java.util.Set;
import org.apache.commons.cli.Option;
import org.apache.commons.io.filefilter.IOFileFilter;
+import org.apache.commons.io.output.CloseShieldOutputStream;
import org.apache.rat.ConfigurationException;
import org.apache.rat.DeprecationReporter;
import org.apache.rat.ImplementationException;
@@ -443,7 +444,7 @@ public class Report extends BaseAntTask {
public void execute() {
try {
Reporter r = new Reporter(validate(getConfiguration()));
- r.output(StyleSheets.PLAIN.getStyleSheet(), () -> new
ReportConfiguration.NoCloseOutputStream(System.out));
+ r.output(StyleSheets.PLAIN.getStyleSheet(), () ->
CloseShieldOutputStream.wrap(System.out));
r.output();
} catch (BuildException e) {
throw e;
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index c8bf1f55..b115353d 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -68,6 +68,9 @@ in order to be properly linked in site reports.
</release>
-->
<release version="1.0.0-SNAPSHOT" date="xxxx-yy-zz" description="Current
SNAPSHOT - release to be done">
+ <action issue="RAT-551" type="add" dev="claudenw">
+ Replace NoCloseOutputStream with Apache Commons
CloseShieldOutputStream.
+ </action>
<action issue="RAT-536" type="fix" dev="pottlinger" due-to="Hervé
Boutemy">
Enable reproducible build and keep a changing timestamp for webpage
generation.
</action>