Search in sources :

Example 1 with BinaryRDFWriter

use of org.eclipse.rdf4j.rio.binary.BinaryRDFWriter in project rdf4j by eclipse.

the class BinaryHandlingTest method writeBinary.

/**
 * 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 writeBinary(Model statements) throws RDFHandlerException {
    ByteArrayOutputStream output = new ByteArrayOutputStream(8096);
    RDFWriter binaryWriter = new BinaryRDFWriter(output);
    binaryWriter.startRDF();
    for (Statement nextStatement : statements) {
        binaryWriter.handleStatement(nextStatement);
    }
    binaryWriter.endRDF();
    return new ByteArrayInputStream(output.toByteArray());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BinaryRDFWriter(org.eclipse.rdf4j.rio.binary.BinaryRDFWriter) Statement(org.eclipse.rdf4j.model.Statement) BinaryRDFWriter(org.eclipse.rdf4j.rio.binary.BinaryRDFWriter) RDFWriter(org.eclipse.rdf4j.rio.RDFWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Statement (org.eclipse.rdf4j.model.Statement)1 RDFWriter (org.eclipse.rdf4j.rio.RDFWriter)1 BinaryRDFWriter (org.eclipse.rdf4j.rio.binary.BinaryRDFWriter)1