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 a FileInputStream, but deletes the file when the stream is closed.
Since:
8.2.0
  • Constructor Details

    • 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 the File object file in the file system. A new FileDescriptor 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 the file 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 its checkRead 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 or reset 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 the READ option. In addition to the READ 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 specified
      UnsupportedOperationException - if an unsupported option is specified
      IOException - if an I/O error occurs
      SecurityException - In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the file.
  • Method Details