Class ForwardSeekableStream

  • All Implemented Interfaces:
    Closeable, DataInput, AutoCloseable

    public class ForwardSeekableStream
    extends SeekableStream
    A subclass of SeekableStream that may be used to wrap a regular InputStream efficiently. Seeking backwards is not supported.
    • Constructor Detail

      • ForwardSeekableStream

        public ForwardSeekableStream​(InputStream src)
        Constructs a InputStreamForwardSeekableStream from a regular InputStream.
    • Method Detail

      • read

        public final int read()
                       throws IOException
        Forwards the request to the real InputStream.
        Specified by:
        read in class SeekableStream
        Returns:
        the next byte of data, or -1 if the end of the stream is reached.
        Throws:
        IOException - if an I/O error occurs.
      • read

        public final int read​(byte[] b,
                              int off,
                              int len)
                       throws IOException
        Forwards the request to the real InputStream.
        Specified by:
        read in class SeekableStream
        Parameters:
        b - the buffer into which the data is read.
        off - the start offset in array b at which the data is written.
        len - the maximum number of bytes to read.
        Returns:
        the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
        Throws:
        IOException - if an I/O error occurs.
      • markSupported

        public boolean markSupported()
        Forwards the request to the real InputStream.
        Overrides:
        markSupported in class SeekableStream
      • canSeekBackwards

        public final boolean canSeekBackwards()
        Returns false since seking backwards is not supported.
        Overrides:
        canSeekBackwards in class SeekableStream
      • getFilePointer

        public final long getFilePointer()
        Returns the current position in the stream (bytes read).
        Specified by:
        getFilePointer in class SeekableStream
        Returns:
        the offset from the beginning of the stream, in bytes, at which the next read occurs.
      • seek

        public final void seek​(long pos)
                        throws IOException
        Seeks forward to the given position in the stream. If pos is smaller than the current position as returned by getFilePointer(), nothing happens.
        Specified by:
        seek in class SeekableStream
        Parameters:
        pos - the offset position, measured in bytes from the beginning of the stream, at which to set the stream pointer.
        Throws:
        IOException - if pos is less than 0 or if an I/O error occurs.