use of org.apache.jena.riot.WriterDatasetRIOT in project jena by apache.
the class ExJsonLD method write.
/**
* Write RDF data as JSON-LD.
*
* To get more control about the output,
* we have to use a mechanism provided by jena to pass information
* to the writing process (cf. org.apache.jena.riot.WriterDatasetRIOT and the "Context" mechanism).
* For that, we have to create a WriterDatasetRIOT (a one-time use object)
* and we pass a "Context" object (not to be confused with the "@context" in JSON-LD) as argument to its write method
*
* @param out
* @param f RDFFormat of the output, eg. RDFFormat.JSONLD_COMPACT_PRETTY
* @param g the data that we want to output as JSON-LD
* @param ctx the object that allows to control the writing process (a set of parameters)
*/
void write(OutputStream out, DatasetGraph g, RDFFormat f, Context ctx) {
// create a WriterDatasetRIOT with the RDFFormat
WriterDatasetRIOT w = RDFDataMgr.createDatasetWriter(f);
PrefixMap pm = RiotLib.prefixMap(g);
String base = null;
w.write(out, g, pm, base, ctx);
}
use of org.apache.jena.riot.WriterDatasetRIOT in project jena by apache.
the class TestJsonLDWriter method toString.
//
// some utilities
//
private String toString(Model m, RDFFormat f, Context jenaContext) {
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
WriterDatasetRIOT w = RDFDataMgr.createDatasetWriter(f);
DatasetGraph g = DatasetFactory.create(m).asDatasetGraph();
PrefixMap pm = RiotLib.prefixMap(g);
String base = null;
w.write(out, g, pm, base, jenaContext);
out.flush();
return out.toString("UTF-8");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations