panda.io.stream.AutoDeleteInputStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of panda-core Show documentation
Show all versions of panda-core Show documentation
Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.
package panda.io.stream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FilterInputStream;
import java.io.IOException;
/**
* automatically delete file when the input stream is closed.
*/
public class AutoDeleteInputStream extends FilterInputStream {
private File file;
protected AutoDeleteInputStream(File f) throws FileNotFoundException {
super(new FileInputStream(f));
this.file = f;
}
public int read() throws IOException {
return super.read();
}
public int read(byte[] b) throws IOException {
return super.read(b);
}
public int read(byte[] b, int off, int len) throws IOException {
return super.read(b, off, len);
}
public void close() throws IOException {
super.close();
file.delete();
}
protected void finalize() throws Throwable {
file.delete();
super.finalize();
}
}