use of org.apache.jena.riot.lang.PipedRDFIterator in project jena by apache.
the class ExRIOT_6 method main.
public static void main(String... argv) {
final String filename = "data.ttl";
// Create a PipedRDFStream to accept input and a PipedRDFIterator to
// consume it
// You can optionally supply a buffer size here for the
// PipedRDFIterator, see the documentation for details about recommended
// buffer sizes
PipedRDFIterator<Triple> iter = new PipedRDFIterator<>();
final PipedRDFStream<Triple> inputStream = new PipedTriplesStream(iter);
// PipedRDFStream and PipedRDFIterator need to be on different threads
ExecutorService executor = Executors.newSingleThreadExecutor();
// Create a runnable for our parser thread
Runnable parser = new Runnable() {
@Override
public void run() {
RDFParser.source(filename).parse(inputStream);
}
};
// Start the parser on another thread
executor.submit(parser);
// far ahead of our consumption as the buffer size allows
while (iter.hasNext()) {
Triple next = iter.next();
// Do something with each triple
}
}
use of org.apache.jena.riot.lang.PipedRDFIterator in project jena by apache.
the class RDFDataMgr method createIteratorQuads.
/**
* Creates an iterator over parsing of quads
* @param input Input Stream
* @param lang Language
* @param baseIRI Base IRI
* @return Iterator over the quads
*/
public static Iterator<Quad> createIteratorQuads(InputStream input, Lang lang, String baseIRI) {
// Special case N-Quads, because the RIOT reader has a pull interface
if (RDFLanguages.sameLang(RDFLanguages.NQUADS, lang)) {
return new IteratorResourceClosing<>(RiotParsers.createIteratorNQuads(input, null, RiotLib.dftProfile()), input);
}
// Otherwise, we have to spin up a thread to deal with it
final PipedRDFIterator<Quad> it = new PipedRDFIterator<>();
final PipedQuadsStream out = new PipedQuadsStream(it);
Thread t = new Thread(() -> parseFromInputStream(out, input, baseIRI, lang, null));
t.start();
return it;
}
use of org.apache.jena.riot.lang.PipedRDFIterator in project jena by apache.
the class RDFDataMgr method createIteratorTriples.
/**
* Create an iterator over parsing of triples
* @param input Input Stream
* @param lang Language
* @param baseIRI Base IRI
* @return Iterator over the triples
*/
public static Iterator<Triple> createIteratorTriples(InputStream input, Lang lang, String baseIRI) {
// Special case N-Triples, because the RIOT reader has a pull interface
if (RDFLanguages.sameLang(RDFLanguages.NTRIPLES, lang))
return new IteratorResourceClosing<>(RiotParsers.createIteratorNTriples(input, null), input);
// Otherwise, we have to spin up a thread to deal with it
PipedRDFIterator<Triple> it = new PipedRDFIterator<>();
PipedTriplesStream out = new PipedTriplesStream(it);
Thread t = new Thread(() -> parseFromInputStream(out, input, baseIRI, lang, null));
t.start();
return it;
}
Aggregations