Search in sources :

Example 6 with TupleQueryResultWriter

use of org.eclipse.rdf4j.query.resultio.TupleQueryResultWriter in project rdf4j by eclipse.

the class SPARQLCSVTupleBackgroundTest method testEmptyResults.

@Test
public void testEmptyResults() throws Exception {
    TupleQueryResultFormat format = getTupleFormat();
    ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
    TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out);
    writer.startDocument();
    writer.startHeader();
    writer.handleLinks(Arrays.<String>asList());
    QueryResults.report(createTupleNoBindingSets(), writer);
    assertRegex("a,b,c(\r\n)?", out.toString("UTF-8"));
}
Also used : TupleQueryResultWriter(org.eclipse.rdf4j.query.resultio.TupleQueryResultWriter) TupleQueryResultFormat(org.eclipse.rdf4j.query.resultio.TupleQueryResultFormat) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AbstractQueryResultIOTupleTest(org.eclipse.rdf4j.query.resultio.AbstractQueryResultIOTupleTest) Test(org.junit.Test)

Example 7 with TupleQueryResultWriter

use of org.eclipse.rdf4j.query.resultio.TupleQueryResultWriter in project rdf4j by eclipse.

the class SPARQLTSVTupleBackgroundTest method toString.

private String toString(TupleQueryResult results) throws QueryResultHandlerException, TupleQueryResultHandlerException, QueryEvaluationException, UnsupportedEncodingException {
    TupleQueryResultFormat format = getTupleFormat();
    ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
    TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out);
    writer.startDocument();
    writer.startHeader();
    writer.handleLinks(Arrays.<String>asList());
    QueryResults.report(results, writer);
    return out.toString("UTF-8");
}
Also used : TupleQueryResultWriter(org.eclipse.rdf4j.query.resultio.TupleQueryResultWriter) TupleQueryResultFormat(org.eclipse.rdf4j.query.resultio.TupleQueryResultFormat) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 8 with TupleQueryResultWriter

use of org.eclipse.rdf4j.query.resultio.TupleQueryResultWriter in project rdf4j by eclipse.

the class SPARQLCSVTupleBackgroundTest method testEndOfLine.

@Test
public void testEndOfLine() throws Exception {
    TupleQueryResultFormat format = getTupleFormat();
    ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
    TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out);
    writer.startDocument();
    writer.startHeader();
    writer.handleLinks(Arrays.<String>asList());
    QueryResults.report(createTupleNoBindingSets(), writer);
    assertEquals("\r\n", out.toString("UTF-8").replaceAll("\\S+", ""));
}
Also used : TupleQueryResultWriter(org.eclipse.rdf4j.query.resultio.TupleQueryResultWriter) TupleQueryResultFormat(org.eclipse.rdf4j.query.resultio.TupleQueryResultFormat) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AbstractQueryResultIOTupleTest(org.eclipse.rdf4j.query.resultio.AbstractQueryResultIOTupleTest) Test(org.junit.Test)

Example 9 with TupleQueryResultWriter

use of org.eclipse.rdf4j.query.resultio.TupleQueryResultWriter in project rdf4j by eclipse.

the class SPARQLCSVTupleBackgroundTest method testmultipleVarResults.

@Test
public void testmultipleVarResults() throws Exception {
    TupleQueryResultFormat format = getTupleFormat();
    ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
    TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out);
    writer.startDocument();
    writer.startHeader();
    writer.handleLinks(Arrays.<String>asList());
    QueryResults.report(createTupleMultipleBindingSets(), writer);
    assertRegex("a,b,c\r\n" + "foo:bar,_:bnode,baz\r\n" + "1,,Hello World!\r\n" + "http://example.org/test/ns/bindingA,http://example.com/other/ns/bindingB,\"http://example.com/other/ns/binding,C\"\r\n" + "\"string with newline at the end       \n\",string with space at the end         ,    \r\n" + "''single-quoted string,\"\"\"\"\"double-quoted string\",\t\tunencoded tab characters followed by encoded \t\t(\r\n)?", out.toString("UTF-8"));
}
Also used : TupleQueryResultWriter(org.eclipse.rdf4j.query.resultio.TupleQueryResultWriter) TupleQueryResultFormat(org.eclipse.rdf4j.query.resultio.TupleQueryResultFormat) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AbstractQueryResultIOTupleTest(org.eclipse.rdf4j.query.resultio.AbstractQueryResultIOTupleTest) Test(org.junit.Test)

Example 10 with TupleQueryResultWriter

use of org.eclipse.rdf4j.query.resultio.TupleQueryResultWriter in project rdf4j by eclipse.

the class SPARQLTSVTupleTest method toString.

private String toString(TupleQueryResult results) throws QueryResultHandlerException, TupleQueryResultHandlerException, QueryEvaluationException, UnsupportedEncodingException {
    TupleQueryResultFormat format = getTupleFormat();
    ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
    TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out);
    writer.startDocument();
    writer.startHeader();
    writer.handleLinks(Arrays.<String>asList());
    QueryResults.report(results, writer);
    return out.toString("UTF-8");
}
Also used : TupleQueryResultWriter(org.eclipse.rdf4j.query.resultio.TupleQueryResultWriter) TupleQueryResultFormat(org.eclipse.rdf4j.query.resultio.TupleQueryResultFormat) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 TupleQueryResultFormat (org.eclipse.rdf4j.query.resultio.TupleQueryResultFormat)10 TupleQueryResultWriter (org.eclipse.rdf4j.query.resultio.TupleQueryResultWriter)10 AbstractQueryResultIOTupleTest (org.eclipse.rdf4j.query.resultio.AbstractQueryResultIOTupleTest)8 Test (org.junit.Test)8