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);
}
}
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();
}
}
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();
}
}
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;
}
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();
}
Aggregations