public Stream stream()

in commons-rdf-rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/RepositoryGraphImpl.java [167:191]


    public Stream<RDF4JTriple> stream(final BlankNodeOrIRI subject, final IRI predicate, final RDFTerm object) {
        final Resource subj = (Resource) getRdf4jTermFactory().asValue(subject);
        final org.eclipse.rdf4j.model.IRI pred = (org.eclipse.rdf4j.model.IRI) getRdf4jTermFactory().asValue(predicate);
        final Value obj = getRdf4jTermFactory().asValue(object);

        // 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<RDF4JTriple> stream = null;
        try {
            final RepositoryResult<Statement> statements = conn.getStatements(subj, pred, obj, getIncludeInferred(), contextMask);
            // NOTE: Iterations.stream should close RepositoryResult as long as
            // our caller closes the stream
            stream = Iterations.stream(statements).map(this::asTripleLike);
        } 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);
    }