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