if ( ( multithreaded ) && ( ! pool.isShutdown() ) ) {
pool.shutdown() ;
try {
pool.awaitTermination(10, TimeUnit.MINUTES) ;
} catch (InterruptedException e) {
throw new AtlasException(e) ;
}
}
List<Iterator<E>> inputs = new ArrayList<Iterator<E>>(size + (memSize > 0 ? 1 : 0));
if (memSize > 0)
{
inputs.add(memory.iterator());
}
for ( int i = 0; i < size; i++ )
{
File spillFile = getSpillFiles().get(i);
try
{
InputStream in = new BufferedInputStream(new FileInputStream(spillFile));
Iterator<E> deserializer = serializationFactory.createDeserializer(in) ;
IteratorResourceClosing<E> irc = new IteratorResourceClosing<E>(deserializer, in);
inputs.add(irc);
}
catch (FileNotFoundException e)
{
// Close any open streams before we throw an exception
for (Iterator<E> it : inputs)
{
Iter.close(it);
}
throw new AtlasException("Cannot find one of the spill files", e);
}
}
SpillSortIterator<E> ssi = new SpillSortIterator<E>(inputs, comparator);
registerCloseableIterator(ssi);