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 void
close()
-
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
FileInputStream
by opening a connection to an actual file, the file named by theFile
objectfile
in the file system. A newFileDescriptor
object is created to represent this file connection.First, if there is a security manager, its
checkRead
method is called with the path represented by thefile
argument 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
FileNotFoundException
is 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 itscheckRead
method 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
mark
orreset
methods. 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
options
parameter determines how the file is opened. If no options are present then it is equivalent to opening the file with theREAD
option. In addition to theREAD
option, 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, thecheckRead
method is invoked to check read access to the file.
-
-
Method Detail
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterInputStream
- Throws:
IOException
-
-