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 d95e1f3d42da2c45f80b2b2e3d1083489940e66a Author: Andy Seaborne <[email protected]> AuthorDate: Tue Mar 31 09:28:42 2026 +0100 Allow prefixes to have an initial setting (PrintingStreamRDF) --- .../apache/jena/riot/system/PrintingStreamRDF.java | 32 ++++++++++++++-------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/jena-arq/src/main/java/org/apache/jena/riot/system/PrintingStreamRDF.java b/jena-arq/src/main/java/org/apache/jena/riot/system/PrintingStreamRDF.java index fab8dbbd0a..0e6020b44f 100644 --- a/jena-arq/src/main/java/org/apache/jena/riot/system/PrintingStreamRDF.java +++ b/jena-arq/src/main/java/org/apache/jena/riot/system/PrintingStreamRDF.java @@ -34,37 +34,46 @@ import org.apache.jena.riot.writer.WriterStreamRDFPlain; import org.apache.jena.sparql.core.Quad; /** - * A StreamRDF which displays the items sent to the stream. + * A {@link StreamRDF} which displays the items sent to the stream. * It is primarily for development purposes. * <p> - * The output is not a legal syntax. Do not consider this - * format to be stable. + * The output is not a legal syntax. + * Do not consider this format to be stable. * <p> * It is not optimized for throughput and it flushes every line. * Consider using {@link WriterStreamRDFFlat} for performance. * <p> - * * Use via * <pre> - * StreamRDFLib.print(System.out); + * StreamRDF stream = StreamRDFLib.print(System.out); * </pre> */ public class PrintingStreamRDF extends WriterStreamRDFPlain { + // This is a development helper. + private final PrefixMap prefixMap = PrefixMapFactory.create(); private final NodeToLabel nodeMapper = NodeToLabel.createScopeByDocument(); - private NodeFormatter pretty = new NodeFormatterTTL(null, prefixMap, nodeMapper ); + private NodeFormatter pretty = new NodeFormatterTTL(null, prefixMap, nodeMapper); public PrintingStreamRDF(OutputStream out) { - super(IO.wrapUTF8(out)); + this(out, null); // Always flush on each items. // Too many points provide buffering or automatic newline - // handling in different ways to get implicit consistent behaviour. - // This is a development helper. + // handling in different ways to get implicit consistent behaviour. } public PrintingStreamRDF(AWriter out) { - super(out); + this(out, null); + } + + /** + * Print, with prefixes already loaded (not printed). + */ + public PrintingStreamRDF(OutputStream out, PrefixMap prefixes) { + super(IO.wrapUTF8(out)); + if ( prefixMap != null ) + prefixMap.putAll(prefixes); } /** @@ -72,7 +81,8 @@ public class PrintingStreamRDF extends WriterStreamRDFPlain */ public PrintingStreamRDF(AWriter out, PrefixMap prefixes) { super(out); - prefixMap.putAll(prefixes); + if ( prefixMap != null ) + prefixMap.putAll(prefixes); } @Override
