Class LazyFileInputStream

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class LazyFileInputStream
    extends org.apache.commons.io.input.AutoCloseInputStream
    This input stream delays opening the file until the first byte is read, and closes and discards the underlying stream as soon as the end of input has been reached or when the stream is explicitly closed.
    • Field Detail

      • file

        protected final File file
        The file to read from.
      • opened

        protected boolean opened
        True if the input stream was opened. It is also set to true if the stream was closed without reading (to avoid opening the file after the stream was closed).
    • Constructor Detail

      • LazyFileInputStream

        public LazyFileInputStream​(File file)
                            throws FileNotFoundException
        Creates a new LazyFileInputStream for the given file. If the file is unreadable, a FileNotFoundException is thrown. The file is not opened until the first byte is read from the stream.
        Parameters:
        file - the file
        Throws:
        FileNotFoundException
      • LazyFileInputStream

        public LazyFileInputStream​(FileDescriptor fd)
        Creates a new LazyFileInputStream for the given file descriptor. The file is not opened until the first byte is read from the stream.
        Parameters:
        fd -
      • LazyFileInputStream

        public LazyFileInputStream​(String name)
                            throws FileNotFoundException
        Creates a new LazyFileInputStream for the given file. If the file is unreadable, a FileNotFoundException is thrown.
        Parameters:
        name -
        Throws:
        FileNotFoundException
    • Method Detail

      • read

        public int read()
                 throws IOException
        Overrides:
        read in class org.apache.commons.io.input.ProxyInputStream
        Throws:
        IOException
      • available

        public int available()
                      throws IOException
        Overrides:
        available in class org.apache.commons.io.input.ProxyInputStream
        Throws:
        IOException
      • reset

        public void reset()
                   throws IOException
        Overrides:
        reset in class org.apache.commons.io.input.ProxyInputStream
        Throws:
        IOException
      • markSupported

        public boolean markSupported()
        Overrides:
        markSupported in class org.apache.commons.io.input.ProxyInputStream
      • mark

        public void mark​(int readlimit)
        Overrides:
        mark in class org.apache.commons.io.input.ProxyInputStream
      • skip

        public long skip​(long n)
                  throws IOException
        Overrides:
        skip in class org.apache.commons.io.input.ProxyInputStream
        Throws:
        IOException
      • read

        public int read​(byte[] b)
                 throws IOException
        Overrides:
        read in class org.apache.commons.io.input.ProxyInputStream
        Throws:
        IOException
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws IOException
        Overrides:
        read in class org.apache.commons.io.input.ProxyInputStream
        Throws:
        IOException