Class DeleteFileOnCloseInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- de.xima.fc.common.io.DeleteFileOnCloseInputStream
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public final class DeleteFileOnCloseInputStream extends FilterInputStream
Similar to aFileInputStream, but deletes the file when the stream is closed.- Since:
- 8.2.0
-
-
Field Summary
-
Fields inherited from class java.io.FilterInputStream
in
-
-
Constructor Summary
Constructors Constructor Description DeleteFileOnCloseInputStream(File file)Creates a new input stream that deletes the file when closed.DeleteFileOnCloseInputStream(Path file, OpenOption... options)Creates a new input stream that deletes the file when closed.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()-
Methods inherited from class java.io.FilterInputStream
available, mark, markSupported, read, read, read, reset, skip
-
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
-
-
-
-
Constructor Detail
-
DeleteFileOnCloseInputStream
public DeleteFileOnCloseInputStream(File file) throws FileNotFoundException
Creates a new input stream that deletes the file when closed.Creates a
FileInputStreamby opening a connection to an actual file, the file named by theFileobjectfilein the file system. A newFileDescriptorobject is created to represent this file connection.First, if there is a security manager, its
checkReadmethod is called with the path represented by thefileargument as its argument.If the named file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading then a
FileNotFoundExceptionis thrown.- Parameters:
file- The file to read from.- Throws:
FileNotFoundException- if the file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading.SecurityException- if a security manager exists and itscheckReadmethod denies read access to the file.
-
DeleteFileOnCloseInputStream
public DeleteFileOnCloseInputStream(Path file, OpenOption... options) throws IOException
Creates a new input stream that deletes the file when closed.Opens a file, returning an input stream to read from the file. The stream will not be buffered, and is not required to support the
markorresetmethods. The stream will be safe for access by multiple concurrent threads. Reading commences at the beginning of the file. Whether the returned stream is asynchronously closeable and/or interruptible is highly file system provider specific and therefore not specified.The
optionsparameter determines how the file is opened. If no options are present then it is equivalent to opening the file with theREADoption. In addition to theREADoption, an implementation may also support additional implementation specific options.- Parameters:
file- The file to read from.options- Options specifying how the file is opened.- Throws:
IllegalArgumentException- if an invalid combination of options is specifiedUnsupportedOperationException- if an unsupported option is specifiedIOException- if an I/O error occursSecurityException- In the case of the default provider, and a security manager is installed, thecheckReadmethod is invoked to check read access to the file.
-
-
Method Detail
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterInputStream- Throws:
IOException
-
-