All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.archive.util.binsearch.SeekableLineReaderIterator Maven / Gradle / Ivy

There is a newer version: 1.1.9
Show newest version
package org.archive.util.binsearch;

import java.io.IOException;

import org.archive.util.io.RuntimeIOException;
import org.archive.util.iterator.AbstractPeekableIterator;

public class SeekableLineReaderIterator extends AbstractPeekableIterator {
	protected SeekableLineReader slr;
	protected boolean propagateException;
	
	public SeekableLineReaderIterator(SeekableLineReader slr) {
		this(slr, true);
	}
	
	public SeekableLineReaderIterator(SeekableLineReader slr, boolean propagateException) {
		this.slr = slr;
		this.propagateException = propagateException;
	}
	
	@Override
	public String getNextInner() {
		String next = null;
		if (slr != null) {
			try {
				next = slr.readLine();
			} catch (IOException e) {
				if (propagateException) {
					throw new RuntimeIOException(e.toString());
				}
			}
		}
		return next;
	}
	@Override
	public void close() throws IOException {
		if (slr != null) {
			slr.close();
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy