use of org.apache.jena.atlas.io.AWriter in project jena by apache.
the class EscapeStr method stringEsc.
/*
* Escape characters in a string according to Turtle rules.
*/
public static String stringEsc(String s) {
AWriter w = new StringWriterI();
stringEsc(w, s, Chars.CH_QUOTE2, true, CharSpace.UTF8);
return w.toString();
}
use of org.apache.jena.atlas.io.AWriter in project jena by apache.
the class TSVOutput method format.
@Override
public void format(OutputStream out, ResultSet resultSet) {
// Use a Turtle formatter to format terms
NodeFormatterTTL formatter = new NodeFormatterTTL(null, null);
AWriter w = IO.wrapUTF8(out);
String sep = null;
List<String> varNames = resultSet.getResultVars();
List<Var> vars = new ArrayList<>(varNames.size());
// writes the variables on the first line
for (String v : varNames) {
if (sep != null)
w.write(sep);
else
sep = SEP;
Var var = Var.alloc(v);
w.write(var.toString());
vars.add(var);
}
w.write(NL);
// writes one binding by line
for (; resultSet.hasNext(); ) {
sep = null;
Binding b = resultSet.nextBinding();
for (Var v : vars) {
if (sep != null)
w.write(sep);
sep = SEP;
Node n = b.get(v);
if (n != null) {
// This will not include a raw tab.
formatter.format(w, n);
}
}
w.write(NL);
}
w.flush();
}
Aggregations