Class SubInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.DataInput, java.lang.AutoCloseable, javax.imageio.stream.ImageInputStream

    public class SubInputStream
    extends javax.imageio.stream.ImageInputStreamImpl
    A wrapper for an ImageInputStream which is able to provide a view of a specific part of the wrapped stream. Read accesses to the wrapped stream are synchronized, so that users of this stream need to deal with synchronization against other users of the same instance, but not against other users of the wrapped stream.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private byte[] buffer
      A buffer which is used to improve read performance.
      (package private) long bufferBase
      Location of the first byte in the buffer with respect to the start of the stream.
      (package private) long bufferTop
      Location of the last byte in the buffer with respect to the start of the stream.
      protected long length
      The length of the window.
      protected long offset
      The position in the wrapped stream at which the window starts.
      protected javax.imageio.stream.ImageInputStream wrappedStream  
      • Fields inherited from class javax.imageio.stream.ImageInputStreamImpl

        bitOffset, byteOrder, flushedPos, streamPos
    • Constructor Summary

      Constructors 
      Constructor Description
      SubInputStream​(javax.imageio.stream.ImageInputStream iis, long offset, long length)
      Construct a new SubInputStream which provides a view of the wrapped stream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private boolean fillBuffer()
      Fill the buffer at the current stream position.
      long length()  
      int read()  
      int read​(byte[] b, int off, int len)  
      void skipBits()
      Skips remaining bits in the current byte.
      • Methods inherited from class javax.imageio.stream.ImageInputStreamImpl

        checkClosed, close, finalize, flush, flushBefore, getBitOffset, getByteOrder, getFlushedPosition, getStreamPosition, isCached, isCachedFile, isCachedMemory, mark, read, readBit, readBits, readBoolean, readByte, readBytes, readChar, readDouble, readFloat, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedInt, readUnsignedShort, readUTF, reset, seek, setBitOffset, setByteOrder, skipBytes, skipBytes
      • Methods inherited from class java.lang.Object

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

      • wrappedStream

        protected final javax.imageio.stream.ImageInputStream wrappedStream
      • offset

        protected final long offset
        The position in the wrapped stream at which the window starts. Offset is an absolut value.
      • length

        protected final long length
        The length of the window. Length is an relative value.
      • buffer

        private final byte[] buffer
        A buffer which is used to improve read performance.
      • bufferBase

        long bufferBase
        Location of the first byte in the buffer with respect to the start of the stream.
      • bufferTop

        long bufferTop
        Location of the last byte in the buffer with respect to the start of the stream.
    • Constructor Detail

      • SubInputStream

        public SubInputStream​(javax.imageio.stream.ImageInputStream iis,
                              long offset,
                              long length)
        Construct a new SubInputStream which provides a view of the wrapped stream.
        Parameters:
        iis - - The stream to be wrapped.
        offset - - The absolute position in the wrapped stream at which the sub-stream starts.
        length - - The length of the sub-stream.
    • Method Detail

      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read in interface javax.imageio.stream.ImageInputStream
        Specified by:
        read in class javax.imageio.stream.ImageInputStreamImpl
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Specified by:
        read in interface javax.imageio.stream.ImageInputStream
        Specified by:
        read in class javax.imageio.stream.ImageInputStreamImpl
        Throws:
        java.io.IOException
      • fillBuffer

        private boolean fillBuffer()
                            throws java.io.IOException
        Fill the buffer at the current stream position.
        Returns:
        Boolean flag. true if successful, false if not.
        Throws:
        java.io.IOException
      • length

        public long length()
        Specified by:
        length in interface javax.imageio.stream.ImageInputStream
        Overrides:
        length in class javax.imageio.stream.ImageInputStreamImpl
      • skipBits

        public void skipBits()
        Skips remaining bits in the current byte.