Search in sources :

Example 1 with IteratorResourceClosing

use of org.apache.jena.atlas.iterator.IteratorResourceClosing in project jena by apache.

the class DefaultDataBag method iterator.

@Override
public Iterator<E> iterator() {
    Iterator<E> toReturn;
    checkClosed();
    // Close the writer
    closeWriter();
    // Create a new reader
    if (policy.isThresholdExceeded()) {
        File spillFile = getSpillFiles().get(0);
        InputStream in;
        try {
            in = new BufferedInputStream(new FileInputStream(spillFile));
        } catch (FileNotFoundException ex) {
            throw new AtlasException(ex);
        }
        Iterator<E> deserializer = serializationFactory.createDeserializer(in);
        IteratorResourceClosing<E> irc = new IteratorResourceClosing<>(deserializer, in);
        registerCloseableIterator(irc);
        toReturn = irc;
    } else {
        toReturn = memory.iterator();
    }
    return toReturn;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IteratorResourceClosing(org.apache.jena.atlas.iterator.IteratorResourceClosing) FileNotFoundException(java.io.FileNotFoundException) AtlasException(org.apache.jena.atlas.AtlasException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with IteratorResourceClosing

use of org.apache.jena.atlas.iterator.IteratorResourceClosing in project jena by apache.

the class SortedDataBag method getInputIterator.

protected Iterator<E> getInputIterator(File spillFile) throws FileNotFoundException {
    InputStream in = getInputStream(spillFile);
    Iterator<E> deserializer = serializationFactory.createDeserializer(in);
    return new IteratorResourceClosing<>(deserializer, in);
}
Also used : InputStream(java.io.InputStream) IteratorResourceClosing(org.apache.jena.atlas.iterator.IteratorResourceClosing)

Example 3 with IteratorResourceClosing

use of org.apache.jena.atlas.iterator.IteratorResourceClosing in project jena by apache.

the class RDFDataMgr method createIteratorQuads.

/**
     * Creates an iterator over parsing of quads
     * @param input Input Stream
     * @param lang Language
     * @param baseIRI Base IRI
     * @return Iterator over the quads
     */
public static Iterator<Quad> createIteratorQuads(InputStream input, Lang lang, String baseIRI) {
    // Special case N-Quads, because the RIOT reader has a pull interface
    if (RDFLanguages.sameLang(RDFLanguages.NQUADS, lang)) {
        return new IteratorResourceClosing<>(RiotParsers.createIteratorNQuads(input, null, RiotLib.dftProfile()), input);
    }
    // Otherwise, we have to spin up a thread to deal with it
    final PipedRDFIterator<Quad> it = new PipedRDFIterator<>();
    final PipedQuadsStream out = new PipedQuadsStream(it);
    Thread t = new Thread(() -> parseFromInputStream(out, input, baseIRI, lang, null));
    t.start();
    return it;
}
Also used : Quad(org.apache.jena.sparql.core.Quad) IteratorResourceClosing(org.apache.jena.atlas.iterator.IteratorResourceClosing) PipedRDFIterator(org.apache.jena.riot.lang.PipedRDFIterator) PipedQuadsStream(org.apache.jena.riot.lang.PipedQuadsStream)

Aggregations

IteratorResourceClosing (org.apache.jena.atlas.iterator.IteratorResourceClosing)3 InputStream (java.io.InputStream)2 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 AtlasException (org.apache.jena.atlas.AtlasException)1 PipedQuadsStream (org.apache.jena.riot.lang.PipedQuadsStream)1 PipedRDFIterator (org.apache.jena.riot.lang.PipedRDFIterator)1 Quad (org.apache.jena.sparql.core.Quad)1