Search in sources :

Example 1 with RDFWriter

use of org.eclipse.rdf4j.rio.RDFWriter in project opentheso by miledrousset.

the class WriteRdfFileTest method writeRio.

@Test
public void writeRio() {
    FileOutputStream out = null;
    try {
        // a collection of several RDF statements
        Graph myGraph = null;
        out = new FileOutputStream("test_unesco2.rdf");
        try {
            RDFWriter writer = Rio.createWriter(RDFFormat.RDFXML, out);
            writer.startRDF();
            for (Statement st : myGraph) {
                writer.handleStatement(st);
            }
            writer.endRDF();
        } catch (RDFHandlerException e) {
        // oh no, do something!
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(WriteRdfFileTest.class.getName()).log(Level.SEVERE, null, ex);
    // oh no, do something!
    } finally {
        try {
            out.close();
        } catch (IOException ex) {
            Logger.getLogger(WriteRdfFileTest.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
Also used : Graph(org.eclipse.rdf4j.model.Graph) RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) Statement(org.eclipse.rdf4j.model.Statement) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) RDFWriter(org.eclipse.rdf4j.rio.RDFWriter) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 Graph (org.eclipse.rdf4j.model.Graph)1 Statement (org.eclipse.rdf4j.model.Statement)1 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)1 RDFWriter (org.eclipse.rdf4j.rio.RDFWriter)1 Test (org.junit.Test)1