Search in sources :

Example 1 with NTriplesWriter

use of org.eclipse.rdf4j.rio.ntriples.NTriplesWriter in project rdf4j by eclipse.

the class NTriplesHandlingTest method writeNTriples.

/**
 * Helper method to write the given model to N-Triples and return an InputStream containing the results.
 *
 * @param statements
 * @return An {@link InputStream} containing the results.
 * @throws RDFHandlerException
 */
private InputStream writeNTriples(Model statements) throws RDFHandlerException {
    StringWriter writer = new StringWriter();
    RDFWriter nTriplesWriter = new NTriplesWriter(writer);
    nTriplesWriter.startRDF();
    for (Statement nextStatement : statements) {
        nTriplesWriter.handleStatement(nextStatement);
    }
    nTriplesWriter.endRDF();
    return new ByteArrayInputStream(writer.toString().getBytes(Charset.forName("UTF-8")));
}
Also used : NTriplesWriter(org.eclipse.rdf4j.rio.ntriples.NTriplesWriter) StringWriter(java.io.StringWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) Statement(org.eclipse.rdf4j.model.Statement) 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 NTriplesWriter (org.eclipse.rdf4j.rio.ntriples.NTriplesWriter)1