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

fi.evolver.utils.stream.FinishingInputStream Maven / Gradle / Ivy

There is a newer version: 3.5.0
Show newest version
package fi.evolver.utils.stream;

import java.io.IOException;
import java.io.InputStream;


/**
 * InputStream which reads any left-over bytes on close.
 *
 * @author Paavo Koskinen
 */
public class FinishingInputStream extends InputStream {
	private final InputStream in;
	private boolean closed = false;

	public FinishingInputStream(InputStream in) {
		this.in = in;
	}

	@Override
	public int read() throws IOException {
		return in.read();
	}

	@Override
	public int read(byte[] b) throws IOException {
		return in.read(b);
	}

	@Override
	public int read(byte[] b, int off, int len) throws IOException {
		return in.read(b, off, len);
	}

	@Override
	public void close() throws IOException {
		if (closed)
			return;

		closed = true;
		while (skip(2048) == 2048) { /* Nothing to do */ }
		in.close();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy