
fi.evolver.utils.stream.FinishingInputStream Maven / Gradle / Ivy
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