org.apache.jena.riot.lang.PipedRDFStream Java Examples

The following examples show how to use org.apache.jena.riot.lang.PipedRDFStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NtripleUtil.java    From NLIWOD with GNU Affero General Public License v3.0 6 votes vote down vote up
private static PipedRDFIterator<Triple> fileToStreamIterator(String filename) {
	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() {
			RDFDataMgr.parse(inputStream, filename);
		}
	};

	// Start the parser on another thread
	executor.submit(parser);
	// We will consume the input on the main thread here
	// We can now iterate over data as it is parsed, parsing only runs as
	// far ahead of our consumption as the buffer size allows
	return iter;
}
 
Example #2
Source File: ExRIOT_6.java    From xcurator with Apache License 2.0 5 votes vote down vote up
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<Triple>();
    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() {
            // Call the parsing process.
            RDFDataMgr.parse(inputStream, filename);
        }
    };

    // Start the parser on another thread
    executor.submit(parser);

    // We will consume the input on the main thread here

    // We can now iterate over data as it is parsed, parsing only runs as
    // far ahead of our consumption as the buffer size allows
    while (iter.hasNext()) {
        Triple next = iter.next();
        // Do something with each triple
    }
}