package org.archive.format.gzip.zipnum;

import java.io.IOException;
import java.util.logging.Logger;

import org.archive.util.binsearch.SeekableLineReader;
import org.archive.util.iterator.AbstractPeekableIterator;
import org.archive.util.iterator.CloseableIterator;

/**
 * @author brad, ilya
 *
 */
public class MultiBlockIterator extends AbstractPeekableIterator<String> {
	private static final Logger LOGGER = Logger.getLogger(
			MultiBlockIterator.class.getName());

	private SeekableLineReader currLoader = null;
	private CloseableIterator<SeekableLineReader> blockItr = null;

	/**
	 * @param blocks which should be fetched and unzipped, one after another
	 */
	public MultiBlockIterator(CloseableIterator<SeekableLineReader> blockItr) {
		this.blockItr = blockItr;
	}
	
	@Override
	public String getNextInner() {
				
		try {
			while (true) {
				if (currLoader == null) {
					if (blockItr.hasNext()) {
						currLoader = blockItr.next();
					} else {
						return null;
					}
				}
				
				// attempt to read the next line from this:
				String next = currLoader.readLine();
				
				if (next != null) {
					return next;
				}
		
				currLoader.close();
				currLoader = null;
			}
		} catch (IOException io) {
			LOGGER.warning(io.toString());
			try {
				close();
			} catch (IOException exc) {
				LOGGER.warning(exc.toString());				
			}
			return null;
		}
	}

	@Override
	public void close() throws IOException {
		if (currLoader != null) {
			try {
				close();
			} catch (IOException exc) {
				LOGGER.warning(exc.toString());				
			}
			currLoader = null;
		}
		
		if (blockItr != null) {
			blockItr.close();
			blockItr = null;
		}
	}
}

@@ -1463,32 +1463,43 @@
  %7B%0A%09%09%09try %7B%0A%09%09%09%09
+currLoader.
 close();%0A%09%09%09%7D ca

fix typo