Class RestartableInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public final class RestartableInputStream
    extends java.io.InputStream
    Buffers an input stream to disk.
    • Constructor Summary

      Constructors 
      Constructor Description
      RestartableInputStream​(java.io.InputStream stream)
      Uses the default tmp directory.
      RestartableInputStream​(java.io.InputStream stream, java.io.File tempDirectory)
      Wrap an input stream, adding logic for mark(int) and reset() if necessary via temp files.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()
      void cleanup()
      Cleanup the underlying temp file.
      void close()
      Closed the wrapped stream and cleanup any temp files created
      protected void finalize()
      Cleanup any
      java.io.File getTempFile()  
      static RestartableInputStream makeRestartable​(java.io.InputStream stream)
      Makes a RestartableInputStream from stream, using (if necessary) temporary disk storage.
      static RestartableInputStream makeRestartable​(java.io.InputStream stream, java.io.File tempDirectory)
      Makes a RestartableInputStream from stream, using (if necessary) temporary disk storage.
      void mark​(int readLimit)
      boolean markSupported()
      Returns true
      int read()
      int read​(byte[] b)
      int read​(byte[] b, int off, int len)
      void reset()
      void restart()
      Restart the input stream from the beginning.
      long skip​(long n)
      • Methods inherited from class java.io.InputStream

        nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RestartableInputStream

        public RestartableInputStream​(java.io.InputStream stream)
                               throws java.io.IOException
        Uses the default tmp directory.
        Throws:
        java.io.IOException
      • RestartableInputStream

        public RestartableInputStream​(java.io.InputStream stream,
                                      java.io.File tempDirectory)
                               throws java.io.IOException
        Wrap an input stream, adding logic for mark(int) and reset() if necessary via temp files.
        Throws:
        java.io.IOException
    • Method Detail

      • cleanup

        public void cleanup()
                     throws java.io.IOException
        Cleanup the underlying temp file.
        Throws:
        java.io.IOException
      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • available

        public int available()
                      throws java.io.IOException
        Overrides:
        available in class java.io.InputStream
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Closed the wrapped stream and cleanup any temp files created
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.InputStream
        Throws:
        java.io.IOException
      • mark

        public void mark​(int readLimit)
        Overrides:
        mark in class java.io.InputStream
      • markSupported

        public boolean markSupported()
        Returns true
        Overrides:
        markSupported in class java.io.InputStream
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • reset

        public void reset()
                   throws java.io.IOException
        Overrides:
        reset in class java.io.InputStream
        Throws:
        java.io.IOException
      • skip

        public long skip​(long n)
                  throws java.io.IOException
        Overrides:
        skip in class java.io.InputStream
        Throws:
        java.io.IOException
      • finalize

        protected void finalize()
                         throws java.io.IOException
        Cleanup any
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.io.IOException
      • getTempFile

        public java.io.File getTempFile()
      • restart

        public void restart()
                     throws java.io.IOException
        Restart the input stream from the beginning.
        Throws:
        java.io.IOException
      • makeRestartable

        public static RestartableInputStream makeRestartable​(java.io.InputStream stream,
                                                             java.io.File tempDirectory)
                                                      throws java.io.IOException
        Makes a RestartableInputStream from stream, using (if necessary) temporary disk storage.
        Parameters:
        stream -
        tempDirectory -
        Returns:
        the input stream wrapped by a RestartableInputStream
        Throws:
        java.io.IOException
      • makeRestartable

        public static RestartableInputStream makeRestartable​(java.io.InputStream stream)
                                                      throws java.io.IOException
        Makes a RestartableInputStream from stream, using (if necessary) temporary disk storage.
        Parameters:
        stream -
        Returns:
        the input stream wrapped by a RestartableInputStream
        Throws:
        java.io.IOException