Search in sources :

Example 16 with StreamRDF

use of org.apache.jena.riot.system.StreamRDF in project jena by apache.

the class SPARQL_GSP_RW method addDataIntoTxn.

/** Directly add data in a transaction.
     * Assumes recovery from parse errors by transaction abort.
     * Return whether the target existed before.
     * @param action
     * @param cleanDest Whether to remove data first (true = PUT, false = POST)
     * @return whether the target existed beforehand
     */
protected static UploadDetails addDataIntoTxn(HttpAction action, boolean overwrite) {
    action.beginWrite();
    try {
        Target target = determineTarget(action);
        if (action.log.isDebugEnabled())
            action.log.debug(action.request.getMethod().toUpperCase() + "->" + target);
        boolean existedBefore = target.exists();
        Graph g = target.graph();
        if (overwrite && existedBefore)
            clearGraph(target);
        StreamRDF sink = StreamRDFLib.graph(g);
        UploadDetails upload = Upload.incomingData(action, sink);
        upload.setExistedBefore(existedBefore);
        action.commit();
        return upload;
    } catch (RiotException ex) {
        // Parse error
        action.abort();
        ServletOps.errorBadRequest(ex.getMessage());
        return null;
    } catch (Exception ex) {
        // Something else went wrong.  Backout.
        action.abort();
        ServletOps.errorOccurred(ex.getMessage());
        return null;
    } finally {
        action.endWrite();
    }
}
Also used : Graph(org.apache.jena.graph.Graph) RiotException(org.apache.jena.riot.RiotException) StreamRDF(org.apache.jena.riot.system.StreamRDF) RiotException(org.apache.jena.riot.RiotException)

Example 17 with StreamRDF

use of org.apache.jena.riot.system.StreamRDF in project jena by apache.

the class ExRIOT_2 method main.

public static void main(String... argv) throws IOException {
    // ---- Parse to a Sink.
    StreamRDF noWhere = StreamRDFLib.sinkNull();
    // --- Or create a parser and do the parsing with detailed setup.
    String baseURI = "http://example/base";
    // The parsers will do the necessary character set conversion.  
    try (InputStream in = new FileInputStream("data.trig")) {
        RDFParser.create().source(in).lang(RDFLanguages.TRIG).errorHandler(ErrorHandlerFactory.errorHandlerStrict).base("http://example/base").parse(noWhere);
    }
}
Also used : StreamRDF(org.apache.jena.riot.system.StreamRDF) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileInputStream(java.io.FileInputStream)

Example 18 with StreamRDF

use of org.apache.jena.riot.system.StreamRDF in project jena by apache.

the class ExRIOT_4 method main.

public static void main(String... argv) {
    String filename = "data.ttl";
    // This is the heart of N-triples printing ... outoput is heavily buffered
    // so the FilterSinkRDF called flush at the end of parsing.
    Sink<Triple> output = new SinkTripleOutput(System.out, null, SyntaxLabels.createNodeToLabel());
    StreamRDF filtered = new FilterSinkRDF(output, FOAF.name, FOAF.knows);
    // Call the parsing process.
    RDFParser.source(filename).parse(filtered);
}
Also used : Triple(org.apache.jena.graph.Triple) SinkTripleOutput(org.apache.jena.riot.out.SinkTripleOutput) StreamRDF(org.apache.jena.riot.system.StreamRDF)

Example 19 with StreamRDF

use of org.apache.jena.riot.system.StreamRDF in project jena by apache.

the class WriterGraphThrift method write.

@Override
public void write(OutputStream out, Graph graph, PrefixMap prefixMap, String baseURI, Context context) {
    StreamRDF stream = BinRDF.streamToOutputStream(out, withValues);
    stream.start();
    StreamOps.graphToStream(graph, stream);
    stream.finish();
}
Also used : StreamRDF(org.apache.jena.riot.system.StreamRDF)

Example 20 with StreamRDF

use of org.apache.jena.riot.system.StreamRDF in project jena by apache.

the class NTriplesWriter method write.

@Override
public void write(Writer out, Graph graph, PrefixMap prefixMap, String baseURI, Context context) {
    Iterator<Triple> iter = graph.find(null, null, null);
    if (charSpace == UTF8)
        write(out, iter);
    else {
        StreamRDF s = new WriterStreamRDFPlain(IO.wrap(out), ASCII);
        write$(s, iter);
    }
}
Also used : Triple(org.apache.jena.graph.Triple) StreamRDF(org.apache.jena.riot.system.StreamRDF)

Aggregations

StreamRDF (org.apache.jena.riot.system.StreamRDF)34 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)9 Graph (org.apache.jena.graph.Graph)7 RiotException (org.apache.jena.riot.RiotException)7 Test (org.junit.Test)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 BaseTest (org.apache.jena.atlas.junit.BaseTest)3 Node (org.apache.jena.graph.Node)3 Triple (org.apache.jena.graph.Triple)3 Lang (org.apache.jena.riot.Lang)3 ContentType (org.apache.jena.atlas.web.ContentType)2 FileInputStream (java.io.FileInputStream)1 OutputStream (java.io.OutputStream)1 StringReader (java.io.StringReader)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 CmdException (jena.cmd.CmdException)1