in commons-rdf-rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryDatasetImpl.java [148:175]
public Stream<RDF4JQuad> stream(final Optional<BlankNodeOrIRI> graphName, final BlankNodeOrIRI subject, final IRI predicate,
final RDFTerm object) {
final Resource subj = (Resource) rdf4jTermFactory.asValue(subject);
final org.eclipse.rdf4j.model.IRI pred = (org.eclipse.rdf4j.model.IRI) rdf4jTermFactory.asValue(predicate);
final Value obj = rdf4jTermFactory.asValue(object);
final Resource[] contexts = asContexts(graphName);
// NOTE: We can't do the usual try..with closing of the
// RepositoryConnection here as it will have to be closed outside
// by the user of the returned stream
final RepositoryConnection conn = getRepositoryConnection();
Stream<RDF4JQuad> stream = null;
try {
final RepositoryResult<Statement> statements = conn.getStatements(subj, pred, obj, includeInferred, contexts);
// NOTE: Iterations.stream should close RepositoryResult as long as
// our caller closes the stream
stream = Iterations.stream(statements).map(rdf4jTermFactory::asQuad);
} finally {
if (stream == null) {
// Some exception before we made the stream, close connection
// here
conn.close();
}
}
// Make sure the RepositoryConnection is closed
return stream == null ? null : stream.onClose(conn::close);
}