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<Var>(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() ;
}