QueryResultsOutputUtil { public static void toNtriplesFile( final OutputStream out, final QueryResultStream<VisibilityStatement> resultsStream, final AtomicBoolean shutdownSignal) throws RDFHandlerException, IllegalStateException, RyaStreamsException { requireNonNull(out); requireNonNull(resultsStream); requireNonNull(shutdownSignal); final RDFWriter writer = Rio.createWriter(RDFFormat.NTRIPLES, out); writer.startRDF(); while(!shutdownSignal.get()) { final Iterable<VisibilityStatement> it = resultsStream.poll(1000); for(final VisibilityStatement result : it) { writer.handleStatement(result); } } writer.endRDF(); } private  QueryResultsOutputUtil(); static void toNtriplesFile(
            final OutputStream out,
            final QueryResultStream<VisibilityStatement> resultsStream,
            final AtomicBoolean shutdownSignal); static void toBindingSetJSONFile(
            final OutputStream out,
            final TupleExpr query,
            final QueryResultStream<VisibilityBindingSet> resultsStream,
            final AtomicBoolean shutdownSignal);  }
@Test public void toNtriplesFile() throws Exception { final AtomicBoolean shutdownSignal = new AtomicBoolean(false); final QueryResultStream<VisibilityStatement> resultsStream = mock(QueryResultStream.class); when(resultsStream.poll(anyLong())).thenAnswer(invocation -> { shutdownSignal.set(true); final List<VisibilityStatement> results = new ArrayList<>(); Statement stmt = VF.createStatement(VF.createIRI("urn:alice"), VF.createIRI("urn:age"), VF.createLiteral(23)); results.add( new VisibilityStatement(stmt) ); stmt = VF.createStatement(VF.createIRI("urn:bob"), VF.createIRI("urn:worksAt"), VF.createLiteral("Taco Shop")); results.add( new VisibilityStatement(stmt) ); return results; }); final ByteArrayOutputStream out = new ByteArrayOutputStream(); QueryResultsOutputUtil.toNtriplesFile(out, resultsStream, shutdownSignal); final String expected = "<urn:alice> <urn:age> \"23\"^^<http: "<urn:bob> <urn:worksAt> \"Taco Shop\" .\n"; final String nTriples = new String(out.toByteArray(), Charsets.UTF_8); assertEquals(expected, nTriples); }