use of org.openrdf.rio.RDFWriter in project qi4j-sdk by Qi4j.
the class ApplicationXmlTest method writeN3.
private void writeN3(Iterable<Statement> graph) throws RDFHandlerException, IOException {
RDFWriterFactory writerFactory = new N3WriterFactory();
RDFWriter writer = writerFactory.getWriter(System.out);
writeOutput(writer, graph);
}
use of org.openrdf.rio.RDFWriter in project qi4j-sdk by Qi4j.
the class ApplicationXmlTest method writeXml.
private void writeXml(Iterable<Statement> graph) throws RDFHandlerException, IOException {
RDFWriterFactory writerFactory = new RDFXMLWriterFactory();
RDFWriter writer = writerFactory.getWriter(System.out);
writeOutput(writer, graph);
}
use of org.openrdf.rio.RDFWriter in project blueprints by tinkerpop.
the class PropertyGraphSailTest method testRDFDump.
@Test
public void testRDFDump() throws Exception {
Repository repo = new SailRepository(sail);
RepositoryConnection rc = repo.getConnection();
try {
RDFWriter w = Rio.createWriter(RDFFormat.TURTLE, System.out);
rc.export(w);
} finally {
rc.close();
}
}
use of org.openrdf.rio.RDFWriter in project qi4j-sdk by Qi4j.
the class AbstractSerializer method serialize.
@Override
public void serialize(Iterable<Statement> graph, Writer out, String[] namespacePrefixes, String[] namespaces) throws RDFHandlerException {
RDFWriterFactory writerFactory;
try {
writerFactory = writerFactoryClass.newInstance();
} catch (InstantiationException e) {
throw new InternalError();
} catch (IllegalAccessException e) {
throw new InternalError();
}
RDFWriter writer = writerFactory.getWriter(out);
writer.startRDF();
for (int i = 0; i < namespacePrefixes.length; i++) {
String namespacePrefix = namespacePrefixes[i];
String namespace = namespaces[i];
writer.handleNamespace(namespacePrefix, namespace);
}
for (Statement st : graph) {
writer.handleStatement(st);
}
writer.endRDF();
}
use of org.openrdf.rio.RDFWriter in project blueprints by tinkerpop.
the class SailGraph method saveRDF.
/**
* Save RDF data from the SailGraph.
* Supported formats include rdf-xml, n-triples, turtle, n3, trix, or trig.
*
* @param output the OutputStream to which to write RDF data
* @param format supported formats include rdf-xml, n-triples, turtle, n3, trix, or trig
*/
public void saveRDF(final OutputStream output, final String format) {
try {
this.commit();
final SailConnection c = this.rawGraph.getConnection();
try {
c.begin();
RDFWriter w = Rio.createWriter(getFormat(format), output);
w.startRDF();
CloseableIteration<? extends Statement, SailException> iter = c.getStatements(null, null, null, false);
try {
while (iter.hasNext()) {
w.handleStatement(iter.next());
}
} finally {
iter.close();
}
w.endRDF();
} finally {
c.rollback();
c.close();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations