Search in sources :

Example 1 with StreamRDF

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

the class TestTriXBad method trix_bad.

@Test(expected = RiotException.class)
public void trix_bad() {
    ErrorHandler err = ErrorHandlerFactory.getDefaultErrorHandler();
    try {
        ErrorHandlerFactory.setDefaultErrorHandler(ErrorHandlerFactory.errorHandlerSimple());
        InputStream in = IO.openFile(fInput);
        StreamRDF sink = StreamRDFLib.sinkNull();
        RDFParser.source(in).lang(Lang.TRIX).parse(sink);
    } finally {
        ErrorHandlerFactory.setDefaultErrorHandler(err);
    }
}
Also used : ErrorHandler(org.apache.jena.riot.system.ErrorHandler) StreamRDF(org.apache.jena.riot.system.StreamRDF) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 2 with StreamRDF

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

the class SPARQL_REST_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 boolean addDataIntoTxn(HttpAction action, boolean overwrite) {
    action.beginWrite();
    Target target = determineTarget(action);
    boolean existedBefore = false;
    try {
        if (log.isDebugEnabled())
            log.debug("  ->" + target);
        existedBefore = target.exists();
        Graph g = target.graph();
        if (overwrite && existedBefore)
            clearGraph(target);
        StreamRDF sink = StreamRDFLib.graph(g);
        incomingData(action, sink);
        action.commit();
        return existedBefore;
    } catch (RiotException ex) {
        // Parse error
        action.abort();
        errorBadRequest(ex.getMessage());
        return existedBefore;
    } catch (Exception ex) {
        // Something else went wrong.  Backout.
        action.abort();
        errorOccurred(ex.getMessage());
        return existedBefore;
    } 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) IOException(java.io.IOException)

Example 3 with StreamRDF

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

the class sdbload method loadOne.

private void loadOne(String filename, boolean replace) {
    Model model = null;
    Dataset dataset = null;
    PrefixMapping pmap;
    Lang lang = RDFLanguages.filenameToLang(filename);
    if (lang == null)
        throw new CmdException("Data syntax not recognized: " + filename);
    // --graph or not
    if (modGraph.getGraphName() != null) {
        model = modGraph.getModel(getStore());
        pmap = model;
    } else {
        dataset = SDBFactory.connectDataset(getStore());
        pmap = dataset.asDatasetGraph().getDefaultGraph().getPrefixMapping();
    }
    // For monitoring only.
    Graph monitorGraph = (model == null) ? null : model.getGraph();
    if (replace) {
        if (model != null)
            model.removeAll();
        else
            dataset.asDatasetGraph().clear();
    }
    boolean showProgress = isVerbose() || getModTime().timingEnabled();
    if (showProgress)
        output.print("Start load: %s", filename);
    StreamRDF stream = streamToStore(pmap, getStore());
    if (modGraph.getGraphName() != null) {
        Node gn = NodeFactory.createURI(modGraph.getGraphName());
        stream = StreamRDFLib.extendTriplesToQuads(gn, stream);
    }
    ProgressMonitor progress = null;
    if (showProgress) {
        progress = new ProgressMonitor(filename, 100_000, 10, output);
        stream = new ProgressStreamRDF(stream, progress);
    }
    if (progress != null)
        progress.start();
    // Load!
    RDFDataMgr.parse(stream, filename, lang);
    if (progress != null) {
        progress.finish();
        progress.finishMessage();
    }
}
Also used : ProgressMonitor(org.apache.jena.atlas.lib.ProgressMonitor) PrefixMapping(org.apache.jena.shared.PrefixMapping) Graph(org.apache.jena.graph.Graph) ModGraph(sdb.cmd.ModGraph) ProgressStreamRDF(org.apache.jena.riot.system.ProgressStreamRDF) CmdException(jena.cmd.CmdException) ProgressStreamRDF(org.apache.jena.riot.system.ProgressStreamRDF) StreamRDF(org.apache.jena.riot.system.StreamRDF) Dataset(org.apache.jena.query.Dataset) Node(org.apache.jena.graph.Node) Model(org.apache.jena.rdf.model.Model) Lang(org.apache.jena.riot.Lang)

Example 4 with StreamRDF

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

the class ParserTestBaseLib method parseGraph.

/** Parse for a language - convert errors.wranigns to ErrorHandlerEx */
static Graph parseGraph(Lang lang, String... strings) {
    Graph graph = GraphFactory.createDefaultGraph();
    StreamRDF dest = StreamRDFLib.graph(graph);
    parse(lang, dest, strings);
    return graph;
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) StreamRDF(org.apache.jena.riot.system.StreamRDF)

Example 5 with StreamRDF

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

the class TurtleWriterBlocks method output.

@Override
protected void output(IndentedWriter out, Graph graph, PrefixMap prefixMap, String baseURI, Context context) {
    StreamRDF dest = new WriterStreamRDFBlocks(out);
    dest.start();
    dest.base(baseURI);
    StreamOps.sendGraphToStream(graph, dest, prefixMap);
    dest.finish();
}
Also used : 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