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;
}
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);
}
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;
}
Aggregations