Github user ejwhite922 commented on a diff in the pull request:
https://github.com/apache/incubator-rya/pull/275#discussion_r170336740
--- Diff:
extras/rya.streams/client/src/main/java/org/apache/rya/streams/client/command/StreamResultsCommand.java
---
@@ -167,17 +182,38 @@ public void run() {
throw new ExecutionException("Could not parse the SPARQL for
the query: " + sparql, e);
}
- // Iterate through the results and print them to the console until
the program or the stream ends.
- try (final QueryResultStream<?> stream =
getQueryResultStream.fromStart(queryId)) {
- while(!finished.get()) {
- for(final Object result : stream.poll(1000)) {
- System.out.println(result);
+ // Iterate through the results and print them to the configured
output mechanism.
+ try (final QueryResultStream<?> resultsStream =
getQueryResultStream.fromStart(queryId)) {
+ final TupleExpr tupleExpr = new
SPARQLParser().parseQuery(sparql, null).getTupleExpr();
+ if(params.outputPath != null) {
+ final Path file = Paths.get(params.outputPath);
+ try(OutputStream out = Files.newOutputStream(file)) {
+ if(isStatementResults) {
+ final QueryResultStream<VisibilityStatement>
stmtStream = (QueryResultStream<VisibilityStatement>) resultsStream;
+ QueryResultsOutputUtil.toNtriplesFile(out,
stmtStream, finished);
+ } else {
+ final QueryResultStream<VisibilityBindingSet>
bsStream = (QueryResultStream<VisibilityBindingSet>) resultsStream;
+ QueryResultsOutputUtil.toBindingSetJSONFile(out,
tupleExpr, bsStream, finished);
+ }
}
+ } else {
+ streamToSystemOut(resultsStream, finished);
}
} catch (final Exception e) {
System.err.println("Error while reading the results from the
stream.");
e.printStackTrace();
System.exit(1);
}
}
+
+ private void streamToSystemOut(final QueryResultStream<?> stream,
final AtomicBoolean shutdownSignal) throws Exception {
--- End diff --
make static
---