Search in sources :

Example 26 with StreamRDF

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

the class REST_Quads_RW method doPutPostNonTxn.

private void doPutPostNonTxn(HttpAction action, boolean clearFirst) {
    DatasetGraph dsgTmp = DatasetGraphFactory.create();
    StreamRDF dest = StreamRDFLib.dataset(dsgTmp);
    UploadDetails details;
    try {
        details = Upload.incomingData(action, dest);
    } catch (RiotException ex) {
        ServletOps.errorBadRequest(ex.getMessage());
        return;
    }
    // Now insert into dataset
    action.beginWrite();
    try {
        DatasetGraph dsg = action.getActiveDSG();
        if (clearFirst)
            dsg.clear();
        FusekiLib.addDataInto(dsgTmp, dsg);
        action.commit();
        ServletOps.success(action);
    } catch (Exception ex) {
        // but it might and there is no harm safely trying.
        try {
            action.abort();
        } catch (Exception ex2) {
        }
        ServletOps.errorOccurred(ex.getMessage());
    } finally {
        action.endWrite();
    }
    ServletOps.uploadResponse(action, details);
}
Also used : RiotException(org.apache.jena.riot.RiotException) StreamRDF(org.apache.jena.riot.system.StreamRDF) RiotException(org.apache.jena.riot.RiotException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 27 with StreamRDF

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

the class GraphLoadUtils method readUtil.

// ** Worker.
private static void readUtil(Graph graph, String uri, int limit) {
    StreamRDF sink = StreamRDFLib.graph(graph);
    sink = new StreamRDFLimited(sink, limit);
    RDFParser.source(uri).streamManager(Fuseki.webStreamManager).parse(sink);
}
Also used : StreamRDF(org.apache.jena.riot.system.StreamRDF)

Example 28 with StreamRDF

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

the class SPARQL_GSP_RW method addDataIntoNonTxn.

/** Add data where the destination does not support full transactions.
     *  In particular, with no abort, and actions probably going to the real storage
     *  parse errors can lead to partial updates.  Instead, parse to a temporary
     *  graph, then insert that data.  
     * @param action
     * @param cleanDest Whether to remove data first (true = PUT, false = POST)
     * @return whether the target existed beforehand.
     */
protected static UploadDetails addDataIntoNonTxn(HttpAction action, boolean overwrite) {
    Graph graphTmp = GraphFactory.createGraphMem();
    StreamRDF dest = StreamRDFLib.graph(graphTmp);
    UploadDetails details;
    try {
        details = Upload.incomingData(action, dest);
    } catch (RiotException ex) {
        ServletOps.errorBadRequest(ex.getMessage());
        return null;
    }
    // Now insert into dataset
    action.beginWrite();
    Target target = determineTarget(action);
    boolean existedBefore = false;
    try {
        if (action.log.isDebugEnabled())
            action.log.debug("  ->" + target);
        existedBefore = target.exists();
        if (overwrite && existedBefore)
            clearGraph(target);
        FusekiLib.addDataInto(graphTmp, target.dsg, target.graphName);
        details.setExistedBefore(existedBefore);
        action.commit();
        return details;
    } catch (Exception ex) {
        // but it might and there is no harm safely trying. 
        try {
            action.abort();
        } catch (Exception ex2) {
        }
        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 29 with StreamRDF

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

the class infer method exec.

@Override
protected void exec() {
    StreamRDF sink = StreamRDFLib.writer(System.out);
    sink = InfFactory.inf(sink, vocab);
    List<String> files = getPositionalOrStdin();
    if (files.isEmpty())
        files.add("-");
    for (String fn : files) processFile(fn, sink);
    IO.flush(System.out);
}
Also used : StreamRDF(org.apache.jena.riot.system.StreamRDF)

Example 30 with StreamRDF

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

the class ParserTestBaseLib method parseDataset.

/** Parse for a language - convert errors and warning to ErrorHandlerEx */
static DatasetGraph parseDataset(Lang lang, String... strings) {
    DatasetGraph dsg = DatasetGraphFactory.create();
    StreamRDF dest = StreamRDFLib.dataset(dsg);
    parse(lang, dest, strings);
    return dsg;
}
Also used : StreamRDF(org.apache.jena.riot.system.StreamRDF) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

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