Search in sources :

Example 1 with WriterConfig

use of org.openrdf.rio.WriterConfig in project incubator-rya by apache.

the class QueryResultsOutputUtil method toBindingSetJSONFile.

/**
 * Writes the results of a {@link QueryResultStream} to the output stream as JSON until the
 * shutdown signal is set.
 *
 * @param out - The stream the JSON will be written to. (not null)
 * @param query - The parsed SPARQL Query whose results are being output. This
 *   object is used to figure out which bindings may appear. (not null)
 * @param resultsStream - The results stream that will be polled for results to
 *   write to {@code out}. (not null)
 * @param shutdownSignal - Setting this signal will cause the thread that
 *   is processing this function to finish and leave. (not null)
 * @throws TupleQueryResultHandlerException A problem was encountered while
 *   writing the JSON to the output stream.
 * @throws IllegalStateException The {@code resultsStream} is closed.
 * @throws RyaStreamsException Could not fetch the next set of results.
 */
public static void toBindingSetJSONFile(final OutputStream out, final TupleExpr query, final QueryResultStream<VisibilityBindingSet> resultsStream, final AtomicBoolean shutdownSignal) throws TupleQueryResultHandlerException, IllegalStateException, RyaStreamsException {
    requireNonNull(out);
    requireNonNull(query);
    requireNonNull(resultsStream);
    requireNonNull(shutdownSignal);
    // Create a writer that does not pretty print.
    final SPARQLResultsJSONWriter writer = new SPARQLResultsJSONWriter(out);
    final WriterConfig config = writer.getWriterConfig();
    config.set(BasicWriterSettings.PRETTY_PRINT, false);
    // Start the JSON and enumerate the possible binding names.
    writer.startQueryResult(Lists.newArrayList(query.getBindingNames()));
    while (!shutdownSignal.get()) {
        for (final VisibilityBindingSet result : resultsStream.poll(1000)) {
            writer.handleSolution(result);
        }
    }
    writer.endQueryResult();
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) SPARQLResultsJSONWriter(org.openrdf.query.resultio.sparqljson.SPARQLResultsJSONWriter) WriterConfig(org.openrdf.rio.WriterConfig)

Aggregations

VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)1 SPARQLResultsJSONWriter (org.openrdf.query.resultio.sparqljson.SPARQLResultsJSONWriter)1 WriterConfig (org.openrdf.rio.WriterConfig)1