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.html| Modifier 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, skipmark, markSupported, resetprotected Logger logger
public DeleteOnCloseFileInputStream(File file) throws FileNotFoundException
file - an opened fileFileNotFoundExceptionpublic DeleteOnCloseFileInputStream(File file, boolean deleteOnClose) throws FileNotFoundException
file - the filename that will be opened for inputdeleteOnClose - set to true for activating deletion on closeFileNotFoundExceptionpublic DeleteOnCloseFileInputStream(String name) throws FileNotFoundException
name - the filename that will be opened for inputFileNotFoundExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class FileInputStreamIOExceptionFileInputStream.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 FileInputStreamIOException - if an I/O error occurs.Copyright © 2004-2021. All Rights Reserved.