Class SavedHeadSeekableInputStream

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

    public class SavedHeadSeekableInputStream
    extends SeekableInputStream
    A wrapper around a seekable input stream which saves the beginning of the stream into a buffer. Seeking within the saved beginning does not cause any IO to be done on the underlying input stream.
    • Constructor Detail

      • SavedHeadSeekableInputStream

        public SavedHeadSeekableInputStream​(SeekableInputStream delegate,
                                            int savedSize)
        Parameters:
        delegate - The seekable stream to delegate reading to
        savedSize - Number of bytes to buffer
    • Method Detail

      • setAllowDirectReads

        public void setAllowDirectReads​(boolean allowDirectReads)
      • loadHead

        public void loadHead()
                      throws java.io.IOException
        Load the number of bytes specified in the constructor into the saved buffer.
        Throws:
        java.io.IOException - On IO error
      • seekHard

        protected void seekHard​(long position)
                         throws java.io.IOException
        Specified by:
        seekHard in class SeekableInputStream
        Throws:
        java.io.IOException
      • canSeekHard

        public boolean canSeekHard()
        Specified by:
        canSeekHard in class SeekableInputStream
        Returns:
        true if it is possible to seek to an arbitrary position in this stream, even when it is behind the current position.
      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • 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
      • skip

        public long skip​(long n)
                  throws java.io.IOException
        Overrides:
        skip 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
        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
      • markSupported

        public boolean markSupported()
        Overrides:
        markSupported in class java.io.InputStream