Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
368 changes: 184 additions & 184 deletions jena-arq/src/main/java/org/apache/jena/riot/lang/LangTurtleBase.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@

import java.io.OutputStream ;

import org.apache.jena.atlas.io.AWriter;
import org.apache.jena.atlas.io.IO;
import org.apache.jena.graph.Triple;
import org.apache.jena.riot.out.NodeFormatter;
import org.apache.jena.riot.out.NodeFormatterTTL;
import org.apache.jena.riot.writer.WriterStreamRDFPlain;
import org.apache.jena.sparql.core.Quad;

/**
* A StreamRDF which displays the items sent to the stream. It is primarily for
* development purposes.
* A 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. It is "N-Quads with abbreviations".
* format to be stable.
* <p>
* Use via
* <pre>
Expand All @@ -44,17 +47,33 @@ public class PrintingStreamRDF extends WriterStreamRDFPlain

public PrintingStreamRDF(OutputStream out) {
super(IO.wrapUTF8(out));
// 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.
}

public PrintingStreamRDF(AWriter out) {
super(out);
}

@Override
protected NodeFormatter getFmt() { return pretty; }

// No prefix formatting.
private static void printDirectURI(AWriter out, String iriStr) {
out.print("<") ;
out.print(iriStr) ;
out.print(">") ;
}

@Override
public void base(String base) {
out.print("BASE") ;
out.print(" ") ;
getFmt().formatURI(out, base);
out.print(" ") ;
printDirectURI(out, base);
out.println();
flush();
// Reset the formatter because of the new base URI.
pretty = new NodeFormatterTTL(base, prefixMap);
}
Expand All @@ -65,8 +84,25 @@ public void prefix(String prefix, String iri) {
out.print(" ") ;
out.print(prefix) ;
out.print(": ") ;
getFmt().formatURI(out, iri);
printDirectURI(out, iri);
out.println();
prefixMap.add(prefix, iri);
flush();
}

@Override
public void triple(Triple triple) {
super.triple(triple);
flush();
}

@Override
public void quad(Quad quad) {
super.quad(quad);
flush();
}

public void flush() {
IO.flush(out) ;
}
}
15 changes: 7 additions & 8 deletions jena-arq/src/main/java/org/apache/jena/riot/system/RiotLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import static org.apache.jena.riot.RDFLanguages.NTRIPLES;
import static org.apache.jena.riot.RDFLanguages.RDFJSON;
import static org.apache.jena.riot.RDFLanguages.sameLang;
import static org.apache.jena.riot.writer.WriterConst.PREFIX_IRI;

import java.io.OutputStream;
import java.io.Writer;
Expand Down Expand Up @@ -296,7 +295,7 @@ public static void writeBase(IndentedWriter out, String base, boolean newStyle)
private static void writeBaseNewStyle(IndentedWriter out, String base) {
if (base != null) {
out.print("BASE ");
out.pad(PREFIX_IRI);
out.pad(7); // Align to possible prefixes. 7 is the length of "prefix "
out.print("<");
out.print(base);
out.print(">");
Expand All @@ -307,7 +306,7 @@ private static void writeBaseNewStyle(IndentedWriter out, String base) {
private static void writeBaseOldStyle(IndentedWriter out, String base) {
if (base != null) {
out.print("@base ");
out.pad(PREFIX_IRI);
out.pad(8); // Align to possible prefixes. 8 is the length of "@prefix "
out.print("<");
out.print(base);
out.print(">");
Expand Down Expand Up @@ -348,11 +347,11 @@ public static void writePrefix(IndentedWriter out, String prefix, String uri, bo
writePrefix(out, prefix, uri, newStyle, 0);
}

private static void writePrefix(IndentedWriter out, String prefix, String uri, boolean newStyle, int maxPrefixLenght) {
private static void writePrefix(IndentedWriter out, String prefix, String uri, boolean newStyle, int maxPrefixLength) {
if (newStyle)
writePrefixNewStyle(out, prefix, uri, maxPrefixLenght);
writePrefixNewStyle(out, prefix, uri, maxPrefixLength);
else
writePrefixOldStyle(out, prefix, uri, maxPrefixLenght);
writePrefixOldStyle(out, prefix, uri, maxPrefixLength);
}

/**
Expand All @@ -362,7 +361,7 @@ private static void writePrefixNewStyle(IndentedWriter out, String prefix, Strin
out.print("PREFIX ");
out.print(prefix);
out.print(": ");
out.pad(9 + intent); // 9 e.q. length of "PREFIX" plus ": "
out.pad(9 + intent); // 9 is length of "PREFIX : "
out.print("<");
out.print(uri);
out.print(">");
Expand All @@ -376,7 +375,7 @@ private static void writePrefixOldStyle(IndentedWriter out, String prefix, Strin
out.print("@prefix ");
out.print(prefix);
out.print(": ");
out.pad(10 + intent); // 10 e.q. length of "@prefix" plus ": "
out.pad(10 + intent); // 10 is length of "@prefix : "
out.print("<");
out.print(uri);
out.print(">");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public class StreamRDFLib
*/
public static StreamRDF print(OutputStream out) { return new PrintingStreamRDF(out); }

/**
* Create a {@link StreamRDF} that prints to an {@link AWriter}.
* This is debug output.
*/
public static StreamRDF print(AWriter out) { return new PrintingStreamRDF(out); }

/**
* Create a {@link StreamRDF} that outputs to an {@link OutputStream}. It is important
* to call {@link StreamRDF#start} and {@link StreamRDF#finish} because the output is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import java.io.StringWriter ;

/** IndentLineBuffer is a buffer that records an indent level
/** IndentLineBuffer is a buffer that records an indent level
* and uses that to insert a prefix at each line.
* It can also insert line numbers at the beginning of lines.
*/
Expand All @@ -29,22 +29,22 @@ public class IndentedLineBuffer extends IndentedWriter
{
StringWriter sw ;
public IndentedLineBuffer() { this(false) ; }

public IndentedLineBuffer(boolean withLineNumbers)
{
super(new StringWriter(), withLineNumbers) ;
sw = (StringWriter)super.out ;
}

public StringBuffer getBuffer() { return sw.getBuffer(); }

public String asString() { return sw.toString() ; }
@Override
public String toString() { return asString() ; }

// Names more usually used for a buffer.
public void append(String fmt, Object... args) { printf(fmt, args) ; }
public void append(char ch) { print(ch) ;}

public void clear() { sw.getBuffer().setLength(0) ; }
}
Loading