ResultSetFormatter { static public void output(ResultSet resultSet, ResultsFormat rFmt) { output(System.out, resultSet, rFmt) ; } private  ResultSetFormatter(); static void out(ResultSet qresults); static void out(OutputStream out, ResultSet qresults); static void out(ResultSet qresults, Query query); static void out(ResultSet qresults, Prologue prologue); static void out(ResultSet qresults, PrefixMapping pmap); static void out(OutputStream out, ResultSet qresults, PrefixMapping pmap); static void out(OutputStream out, ResultSet qresults, Prologue prologue); static void out(boolean answer); static void out(OutputStream out, boolean answer); static String asText(ResultSet qresults); static String asText(ResultSet qresults, Prologue prologue); static int consume(ResultSet resultSet); static List<QuerySolution> toList(ResultSet resultSet); static void output(ResultSet resultSet, ResultsFormat rFmt); static void output(OutputStream outStream, ResultSet resultSet, ResultsFormat rFmt); static void output(ResultSet resultSet, Lang resultFormat); static void output(OutputStream outStream, ResultSet resultSet, Lang resultFormat); static void output(boolean result, Lang resultFormat); static void output(OutputStream outStream, boolean result, Lang resultFormat); static void output(OutputStream outStream, Iterator<JsonObject> jsonItems); static void outputAsXML(ResultSet qresults); static void outputAsXML(OutputStream outStream, ResultSet qresults); static void outputAsXML(ResultSet qresults, String stylesheet); static void outputAsXML(OutputStream outStream, ResultSet qresults, String stylesheet); static void outputAsXML(boolean booleanResult); static void outputAsXML(OutputStream outStream, boolean booleanResult); static void outputAsXML(boolean booleanResult, String stylesheet); static void outputAsXML(OutputStream outStream, boolean booleanResult, String stylesheet); static String asXMLString(ResultSet qresults); static String asXMLString(ResultSet qresults, String stylesheet); static String asXMLString(boolean booleanResult); static String asXMLString(boolean booleanResult, String stylesheet); static void outputAsJSON(ResultSet resultSet); static void outputAsJSON(OutputStream outStream, ResultSet resultSet); static void outputAsJSON(boolean booleanResult); static void outputAsJSON(OutputStream outStream, boolean booleanResult); static void outputAsSSE(boolean booleanResult); static void outputAsSSE(OutputStream outStream, boolean booleanResult); static void outputAsSSE(ResultSet resultSet); static void outputAsSSE(ResultSet resultSet, Prologue prologue); static void outputAsSSE(OutputStream outStream, ResultSet resultSet); static void outputAsSSE(OutputStream outStream, ResultSet resultSet, Prologue prologue); static void outputAsCSV(boolean booleanResult); static void outputAsCSV(OutputStream outStream, boolean booleanResult); static void outputAsCSV(ResultSet resultSet); static void outputAsCSV(OutputStream outStream, ResultSet resultSet); static void outputAsTSV(boolean booleanResult); static void outputAsTSV(OutputStream outStream, boolean booleanResult); static void outputAsTSV(ResultSet resultSet); static void outputAsTSV(OutputStream outStream, ResultSet resultSet);  }
@Test public void testIterator() throws IOException { Model model = ModelFactory.createDefaultModel(); { Resource r = model.createResource(AnonId.create("first")); Property p = model.getProperty(""); RDFNode node = ResourceFactory.createTypedLiteral("123", XSDDatatype.XSDdecimal); model.add(r, p, node); r = model.createResource(AnonId.create("second")); p = model.getProperty(""); node = ResourceFactory.createTypedLiteral("abc", XSDDatatype.XSDstring); model.add(r, p, node); r = model.createResource(AnonId.create("third")); p = model.getProperty(""); node = ResourceFactory.createLangLiteral("def", "en"); model.add(r, p, node); r = model.createResource(AnonId.create("fourth")); p = model.getProperty(""); node = ResourceFactory.createTypedLiteral("true", XSDDatatype.XSDboolean); model.add(r, p, node); } Query query = QueryFactory.create("JSON { \"s\": ?s , \"p\": ?p , \"o\" : ?o } " + "WHERE { ?s ?p ?o }", Syntax.syntaxARQ); try ( QueryExecution qexec = QueryExecutionFactory.create(query, model) ) { JsonIterator execJsonItems = (JsonIterator) qexec.execJsonItems(); try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) { ResultSetFormatter.output(baos, execJsonItems); String output = baos.toString(Charset.forName("UTF-8")); assertTrue(output.contains("\"_:first\"")); assertTrue(output.contains("\"_:second\"")); assertTrue(output.contains("\"_:third\"")); assertTrue(output.contains("\"_:fourth\"")); assertFalse(output.contains("\"true\"")); assertTrue(output.contains("true")); assertTrue(output.contains("123")); assertFalse(output.contains("\"123\"")); assertTrue(output.contains("\"abc\"")); } } }