Class SeekableInputStream

All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
ASMemoryInStream, InternalInputStream

public abstract class SeekableInputStream extends ASInputStream
Represents stream in which seek for a particular byte offset can be performed. On creation, contents of this stream should be written into file or memory buffer.
Author:
Sergey Shemyakov
  • Constructor Details

    • SeekableInputStream

      public SeekableInputStream()
  • Method Details

    • seek

      public abstract void seek(long offset) throws IOException
      Goes to a particular byte in stream.
      Parameters:
      offset - is offset of a byte to go to.
      Throws:
      IOException
    • getOffset

      public abstract long getOffset() throws IOException
      Gets offset of current byte.
      Returns:
      offset of byte to be read next.
      Throws:
      IOException
    • getStreamLength

      public abstract long getStreamLength() throws IOException
      Gets total length of stream.
      Returns:
      length of stream in bytes.
      Throws:
      IOException
    • peek

      public abstract int peek() throws IOException
      Gets next byte without reading it.
      Returns:
      next byte.
      Throws:
      IOException
    • getStream

      public abstract ASInputStream getStream(long startOffset, long length) throws IOException
      Gets substream of this stream that starts at given offset and has given length.
      Parameters:
      startOffset - is starting offset of substream.
      length - is length of substream.
      Throws:
      IOException
    • incrementResourceUsers

      public void incrementResourceUsers()
      Method increments number of resource users.
      Specified by:
      incrementResourceUsers in class ASInputStream
    • decrementResourceUsers

      public void decrementResourceUsers()
      Description copied from class: ASInputStream
      Method decrements number of resource users.
      Specified by:
      decrementResourceUsers in class ASInputStream
    • isEOF

      public boolean isEOF() throws IOException
      Returns:
      true if end of stream is reached.
      Throws:
      IOException
    • unread

      public void unread() throws IOException
      Resets reading pointer one byte backwards.
      Throws:
      IOException
    • unread

      public void unread(int count) throws IOException
      Resets reading pointer several bytes backwards.
      Parameters:
      count - is number of bytes to unread.
      Throws:
      IOException
    • seekFromCurrentPosition

      public void seekFromCurrentPosition(long pos) throws IOException
      Sets reading pointer several bytes forward.
      Parameters:
      pos - is amount of bytes to skip.
      Throws:
      IOException
    • seekFromEnd

      public void seekFromEnd(long pos) throws IOException
      Seeks given number of bytes from the end of stream.
      Parameters:
      pos - is a number of bytes to seek from the end of stream.
      Throws:
      IOException
    • readByte

      public byte readByte() throws IOException
      Reads next byte from stream.
      Returns:
      the byte read.
      Throws:
      IOException
    • getSeekableStream

      public static SeekableInputStream getSeekableStream(InputStream stream) throws IOException
      Returns InternalInputStream or ASMemoryInStream constructed from given stream depending on stream length.
      Parameters:
      stream - is stream to turn into seekable stream.
      Returns:
      SeekableStream that contains data of passed stream.
      Throws:
      IOException