Search in sources :

Example 1 with TurtleWriter

use of org.eclipse.rdf4j.rio.turtle.TurtleWriter in project rdf4j by eclipse.

the class TurtleHandlingTest method writeTurtle.

/**
 * Helper method to write the given model to Turtle and return an InputStream containing the results.
 *
 * @param statements
 * @return An {@link InputStream} containing the results.
 * @throws RDFHandlerException
 */
private InputStream writeTurtle(Model statements) throws RDFHandlerException {
    StringWriter writer = new StringWriter();
    RDFWriter turtleWriter = new TurtleWriter(writer);
    turtleWriter.startRDF();
    for (Statement nextStatement : statements) {
        turtleWriter.handleStatement(nextStatement);
    }
    turtleWriter.endRDF();
    return new ByteArrayInputStream(writer.toString().getBytes(Charset.forName("UTF-8")));
}
Also used : StringWriter(java.io.StringWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) Statement(org.eclipse.rdf4j.model.Statement) TurtleWriter(org.eclipse.rdf4j.rio.turtle.TurtleWriter) RDFWriter(org.eclipse.rdf4j.rio.RDFWriter)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 StringWriter (java.io.StringWriter)1 Statement (org.eclipse.rdf4j.model.Statement)1 RDFWriter (org.eclipse.rdf4j.rio.RDFWriter)1 TurtleWriter (org.eclipse.rdf4j.rio.turtle.TurtleWriter)1