Search in sources :

Example 1 with RDFWriter

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);
}
Also used : RDFWriterFactory(org.openrdf.rio.RDFWriterFactory) N3WriterFactory(org.openrdf.rio.n3.N3WriterFactory) RDFWriter(org.openrdf.rio.RDFWriter)

Example 2 with RDFWriter

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);
}
Also used : RDFWriterFactory(org.openrdf.rio.RDFWriterFactory) RDFXMLWriterFactory(org.openrdf.rio.rdfxml.RDFXMLWriterFactory) RDFWriter(org.openrdf.rio.RDFWriter)

Example 3 with RDFWriter

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();
    }
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) SailRepository(org.openrdf.repository.sail.SailRepository) Repository(org.openrdf.repository.Repository) SailRepository(org.openrdf.repository.sail.SailRepository) RDFWriter(org.openrdf.rio.RDFWriter) Test(org.junit.Test)

Example 4 with RDFWriter

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();
}
Also used : RDFWriterFactory(org.openrdf.rio.RDFWriterFactory) Statement(org.openrdf.model.Statement) RDFWriter(org.openrdf.rio.RDFWriter)

Example 5 with RDFWriter

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);
    }
}
Also used : SailConnection(org.openrdf.sail.SailConnection) RDFWriter(org.openrdf.rio.RDFWriter) SailException(org.openrdf.sail.SailException) SailException(org.openrdf.sail.SailException) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) RDFHandlerException(org.openrdf.rio.RDFHandlerException)

Aggregations

RDFWriter (org.openrdf.rio.RDFWriter)5 RDFWriterFactory (org.openrdf.rio.RDFWriterFactory)3 Test (org.junit.Test)1 Statement (org.openrdf.model.Statement)1 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)1 Repository (org.openrdf.repository.Repository)1 RepositoryConnection (org.openrdf.repository.RepositoryConnection)1 SailRepository (org.openrdf.repository.sail.SailRepository)1 RDFHandlerException (org.openrdf.rio.RDFHandlerException)1 N3WriterFactory (org.openrdf.rio.n3.N3WriterFactory)1 RDFXMLWriterFactory (org.openrdf.rio.rdfxml.RDFXMLWriterFactory)1 SailConnection (org.openrdf.sail.SailConnection)1 SailException (org.openrdf.sail.SailException)1