From ca99edf3d6c93339c2dca623aaa9b7a4bf2db7e5 Mon Sep 17 00:00:00 2001 From: Simon Templer Date: Tue, 12 Mar 2024 15:05:22 +0100 Subject: [PATCH] fix: don't close PrintStream when using printCell ...to avoid closing System.out which is used in most cases as target for printing a Cell in tests, which lead to incomplete output from tests. --- .../META-INF/MANIFEST.MF | 1 + .../common/align/io/impl/JaxbAlignmentIO.java | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/common/plugins/eu.esdihumboldt.hale.common.align/META-INF/MANIFEST.MF b/common/plugins/eu.esdihumboldt.hale.common.align/META-INF/MANIFEST.MF index 3adb7e08d2..eec7c07d4a 100644 --- a/common/plugins/eu.esdihumboldt.hale.common.align/META-INF/MANIFEST.MF +++ b/common/plugins/eu.esdihumboldt.hale.common.align/META-INF/MANIFEST.MF @@ -51,6 +51,7 @@ Import-Package: com.google.common.base;version="1.6.0", eu.esdihumboldt.util.io, javax.annotation;version="[1.2.0,1.2.0]", net.jcip.annotations, + org.apache.commons.io.output, org.apache.commons.lang;version="2.4.0", org.locationtech.jts.geom, org.slf4j;version="1.5.11", diff --git a/common/plugins/eu.esdihumboldt.hale.common.align/src/eu/esdihumboldt/hale/common/align/io/impl/JaxbAlignmentIO.java b/common/plugins/eu.esdihumboldt.hale.common.align/src/eu/esdihumboldt/hale/common/align/io/impl/JaxbAlignmentIO.java index bed39c7e0e..d2f1386118 100644 --- a/common/plugins/eu.esdihumboldt.hale.common.align/src/eu/esdihumboldt/hale/common/align/io/impl/JaxbAlignmentIO.java +++ b/common/plugins/eu.esdihumboldt.hale.common.align/src/eu/esdihumboldt/hale/common/align/io/impl/JaxbAlignmentIO.java @@ -19,8 +19,11 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.PrintStream; import java.net.URI; +import org.apache.commons.io.output.CloseShieldOutputStream; + import eu.esdihumboldt.hale.common.align.io.EntityResolver; import eu.esdihumboldt.hale.common.align.io.impl.internal.AlignmentToJaxb; import eu.esdihumboldt.hale.common.align.io.impl.internal.JaxbToAlignment; @@ -171,7 +174,21 @@ public static void save(AlignmentType alignment, IOReporter reporter, OutputStre } /** - * Print a cell to an output stream (intended for tests/debugging). + * Print a cell to a {@link PrintStream} (intended for tests/debugging). The + * stream is prevented from being closed, which is intended to prevent for + * instance System.out from being closed. + * + * @param cell the cell to print + * @param out the output stream + * @throws Exception if an error occurs trying to print the cell + */ + public static void printCell(MutableCell cell, PrintStream out) throws Exception { + printCell(cell, CloseShieldOutputStream.wrap(out)); + } + + /** + * Print a cell to an output stream (intended for tests/debugging). The + * stream is closed when the cell was written. * * @param cell the cell to print * @param out the output stream