use of org.eclipse.rdf4j.rio.jsonld.JSONLDWriter in project rdf4j by eclipse.
the class JSONLDParserHandlerTest method writeJSONLD.
/**
* Helper method to write the given model to JSON-LD and return an InputStream containing the results.
*
* @param statements
* @return An {@link InputStream} containing the results.
* @throws RDFHandlerException
*/
private InputStream writeJSONLD(Model statements) throws RDFHandlerException {
final StringWriter writer = new StringWriter();
final RDFWriter jsonldWriter = new JSONLDWriter(writer);
jsonldWriter.startRDF();
for (final Namespace prefix : statements.getNamespaces()) {
jsonldWriter.handleNamespace(prefix.getPrefix(), prefix.getName());
}
for (final Statement nextStatement : statements) {
jsonldWriter.handleStatement(nextStatement);
}
jsonldWriter.endRDF();
return new ByteArrayInputStream(writer.toString().getBytes(Charset.forName("UTF-8")));
}
Aggregations