org.apache.xmlgraphics.image.codec.util

## Class ForwardSeekableStream

- java.lang.Object
- - java.io.InputStream
  - - org.apache.xmlgraphics.image.codec.util.SeekableStream
    - - org.apache.xmlgraphics.image.codec.util.ForwardSeekableStream

- All Implemented Interfaces:
    java.io.Closeable, java.io.DataInput, java.lang.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.

- - ### Field Summary

    - ### Fields inherited from class org.apache.xmlgraphics.image.codec.util.SeekableStream

      `markPos`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ForwardSeekableStream(java.io.InputStream src)` Constructs a `InputStreamForwardSeekableStream` from a regular `InputStream`.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `available()` Forwards the request to the real `InputStream`.
    `boolean` | `canSeekBackwards()` Returns `false` since seking backwards is not supported.
    `void` | `close()` Forwards the request to the real `InputStream`.
    `long` | `getFilePointer()` Returns the current position in the stream (bytes read).
    `void` | `mark(int readLimit)` Forwards the request to the real `InputStream`.
    `boolean` | `markSupported()` Forwards the request to the real `InputStream`.
    `int` | `read()` Forwards the request to the real `InputStream`.
    `int` | `read(byte[] b, int off, int len)` Forwards the request to the real `InputStream`.
    `void` | `reset()` Forwards the request to the real `InputStream`.
    `void` | `seek(long pos)` Seeks forward to the given position in the stream.
    `long` | `skip(long n)` Forwards the request to the real `InputStream`.

    - ### Methods inherited from class org.apache.xmlgraphics.image.codec.util.SeekableStream

      `finalize, readBoolean, readByte, readChar, readCharLE, readDouble, readDoubleLE, readFloat, readFloatLE, readFully, readFully, readInt, readIntLE, readLine, readLong, readLongLE, readShort, readShortLE, readUnsignedByte, readUnsignedInt, readUnsignedIntLE, readUnsignedShort, readUnsignedShortLE, readUTF, skipBytes, wrapInputStream`

    - ### Methods inherited from class java.io.InputStream

      `read`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ForwardSeekableStream

          public ForwardSeekableStream(java.io.InputStream src)

      Constructs a `InputStreamForwardSeekableStream` from a regular `InputStream`.

  - ### Method Detail

    - #### read

          public final int read()
                         throws java.io.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:
        `java.io.IOException` - if an I/O error occurs.

    - #### read

          public final int read(byte[] b,
                                int off,
                                int len)
                         throws java.io.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:
        `java.io.IOException` - if an I/O error occurs.

    - #### skip

          public final long skip(long n)
                          throws java.io.IOException

      Forwards the request to the real `InputStream`.
      Overrides:
        `skip` in class `java.io.InputStream`
      Throws:
        `java.io.IOException`

    - #### available

          public final int available()
                              throws java.io.IOException

      Forwards the request to the real `InputStream`.
      Overrides:
        `available` in class `java.io.InputStream`
      Throws:
        `java.io.IOException`

    - #### close

          public final void close()
                           throws java.io.IOException

      Forwards the request to the real `InputStream`.
      Specified by:
        `close` in interface `java.io.Closeable`
      Specified by:
        `close` in interface `java.lang.AutoCloseable`
      Overrides:
        `close` in class `java.io.InputStream`
      Throws:
        `java.io.IOException`

    - #### mark

          public final void mark(int readLimit)

      Forwards the request to the real `InputStream`. We use `SeekableStream.markPos`
      Overrides:
        `mark` in class `SeekableStream`

    - #### reset

          public final void reset()
                           throws java.io.IOException

      Forwards the request to the real `InputStream`. We use `SeekableStream.markPos`
      Overrides:
        `reset` in class `SeekableStream`
      Throws:
        `java.io.IOException`

    - #### 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 java.io.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:
        `java.io.IOException` - if `pos` is less than `0` or if an I/O error occurs.

Copyright 1999-2025 The Apache Software Foundation. All Rights Reserved.