use of org.apache.jena.sparql.util.NodeToLabelMap in project jena by apache.
the class CSVOutput method format.
@Override
public void format(OutputStream out, ResultSet resultSet) {
try {
Writer w = FileUtils.asUTF8(out);
NodeToLabelMap bnodes = new NodeToLabelMap();
w = new BufferedWriter(w);
String sep = null;
List<String> varNames = resultSet.getResultVars();
List<Var> vars = new ArrayList<>(varNames.size());
// Convert to Vars and output the header line.
for (String v : varNames) {
if (sep != null)
w.write(sep);
else
sep = ",";
w.write(csvSafe(v));
vars.add(Var.alloc(v));
}
w.write(NL);
// Data output
for (; resultSet.hasNext(); ) {
sep = null;
Binding b = resultSet.nextBinding();
for (Var v : vars) {
if (sep != null)
w.write(sep);
sep = ",";
Node n = b.get(v);
if (n != null)
output(w, n, bnodes);
}
w.write(NL);
}
w.flush();
} catch (IOException ex) {
throw new ARQException(ex);
}
}
Aggregations