You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2025/06/22 07:32:06 UTC
(jena) 02/04: IndentedWriter: close() to call flush() on the wrapped output
This is an automated email from the ASF dual-hosted git repository.
andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git
commit 5d51868bffec5d0ea8a423cf1a5bc97f46e8e52b
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Sun Jun 1 09:36:39 2025 +0100
IndentedWriter: close() to call flush() on the wrapped output
---
.../org/apache/jena/atlas/io/IndentedWriter.java | 28 +++++++++++++++++-----
1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/jena-base/src/main/java/org/apache/jena/atlas/io/IndentedWriter.java b/jena-base/src/main/java/org/apache/jena/atlas/io/IndentedWriter.java
index a448fd5c57..bf5f90f44e 100644
--- a/jena-base/src/main/java/org/apache/jena/atlas/io/IndentedWriter.java
+++ b/jena-base/src/main/java/org/apache/jena/atlas/io/IndentedWriter.java
@@ -26,9 +26,14 @@ import java.io.Writer;
import org.apache.jena.atlas.lib.Closeable;
-/** A writer that records what the current indentation level is, and
- * uses that to insert a prefix at each line.
- * It can also insert line numbers at the beginning of lines. */
+/**
+ * A {@link AWriter} that records what the current indentation level is, and uses
+ * that to insert a prefix at each line.
+ * It can also insert line numbers at the beginning of lines.
+ * <p>
+ * An {@code IndentedWriter} flushed, bit does not close, the underlying output a
+ * stream on close.
+ */
public class IndentedWriter extends AWriterBase implements AWriter, Closeable
{
@@ -109,16 +114,23 @@ public class IndentedWriter extends AWriterBase implements AWriter, Closeable
public IndentedWriter clone() {
return clone(this);
}
+
private static Writer makeWriter(OutputStream out) {
return IO.asBufferedUTF8(out);
}
- /** Using Writers directly is discouraged */
+ /**
+ * Using {@link java.io.Writer Java I/O Writers} directly is discouraged
+ * and may case character encoding issues.
+ */
protected IndentedWriter(Writer writer) {
this(writer, false);
}
- /** Using Writers directly is discouraged */
+ /**
+ * Using {@link java.io.Writer Java I/O Writers} directly is discouraged
+ * and may case character encoding issues.
+ */
protected IndentedWriter(Writer writer, boolean withLineNumbers) {
out = writer;
lineNumbers = withLineNumbers;
@@ -253,7 +265,11 @@ public class IndentedWriter extends AWriterBase implements AWriter, Closeable
}
@Override
- public void close() { IO.close(out); }
+ public void close() {
+ // flush, not close.
+ // IndentedWriters wrap an underlying output, often a short term additional layer.
+ flush();
+ }
@Override
public void flush() { IO.flush(out); }