public class DeleteOnCloseFileInputStream extends FileInputStream
FileInputStream
which (optionally) deletes the underlying file when the stream is closed.
A modified version of the class implemented by BJ in his blog, ref http://bimalesh.blogspot.com/2010/02/auto-deleting-fileinputstream.htmlModifier and Type | Field and Description |
---|---|
protected Logger |
logger
Logger if defined
|
Constructor and Description |
---|
DeleteOnCloseFileInputStream(File file)
Creates a fileInputStream wrapped around the given file and deletes the file when the FileInputStream is closed.
|
DeleteOnCloseFileInputStream(File file,
boolean deleteOnClose)
Creates a fileInputStream wrapped around the given file.
|
DeleteOnCloseFileInputStream(String name)
Creates a fileInputStream for the given file name and deletes the file when the FileInputStream is closed.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the underlying FileInputStream and also deletes the file object from disk if the isDeleteOnClose() is set to true.
|
protected void |
finalize()
Ensures that the
close method of this file input stream is called when there are no more references to it. |
boolean |
isDeleteOnClose() |
void |
setLogger(Logger logger)
Set logger.
|
available, getChannel, getFD, read, read, read, skip
mark, markSupported, reset
protected Logger logger
public DeleteOnCloseFileInputStream(File file) throws FileNotFoundException
file
- an opened fileFileNotFoundException
public DeleteOnCloseFileInputStream(File file, boolean deleteOnClose) throws FileNotFoundException
file
- the filename that will be opened for inputdeleteOnClose
- set to true for activating deletion on closeFileNotFoundException
public DeleteOnCloseFileInputStream(String name) throws FileNotFoundException
name
- the filename that will be opened for inputFileNotFoundException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class FileInputStream
IOException
FileInputStream.close()
public final boolean isDeleteOnClose()
public void setLogger(Logger logger)
logger
- logger to useprotected void finalize() throws IOException
close
method of this file input stream is called when there are no more references to it.finalize
in class FileInputStream
IOException
- if an I/O error occurs.Copyright © 2004-2021. All Rights Reserved.