Class AutoPositioningStream

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

    final class AutoPositioningStream
    extends BinaryToRawStream
    This Stream is a wrapper for PositionedStoreStream to set the position correctly before performing any operation on it. All the read and skip methods ensure that the PositionedStoreStream is set to right position before actually performing these operations. PositionedStoreStream is accessed within synchronized block to ensure exclusive access to it. This class must be constructed while synchronizing on ConnectionChild.getConnectionSynchronization
    • Constructor Summary

      Constructors 
      Constructor Description
      AutoPositioningStream​(ConnectionChild conChild, java.io.InputStream in, java.lang.Object parent)
      Constructs AutoPositioningStream object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int read()
      Reads a single byte from the underlying stream.
      int read​(byte[] b)
      Reads a number of bytes from the underlying stream and stores them in the specified byte array.
      int read​(byte[] b, int off, int len)
      Reads a number of bytes from the underlying stream and stores them in the specified byte array at the specified offset.
      private void setPosition()
      Checks if positionedStream's position was changed since last used, sets the position to right position if its changed.
      long skip​(long n)
      Skips up to the specified number of bytes from the underlying stream.
      • Methods inherited from class java.io.FilterInputStream

        available, close, mark, markSupported, reset
      • Methods inherited from class java.io.InputStream

        nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
      • Methods inherited from class java.lang.Object

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

      • conChild

        private final ConnectionChild conChild
        ConnectionChild to get synchronizion object
      • pos

        private long pos
    • Constructor Detail

      • AutoPositioningStream

        AutoPositioningStream​(ConnectionChild conChild,
                              java.io.InputStream in,
                              java.lang.Object parent)
                       throws java.io.IOException
        Constructs AutoPositioningStream object. This constructor must be called from block synchronized on conChild.getConnectionSynchronization.
        Parameters:
        conChild - ConnectionChild to get synchronization object before accessing PositionedStoreStream
        in - InputStream
        parent - Parent of the stream to prevent it from being gc.
        Throws:
        java.io.IOException - if an I/O error occurs
    • Method Detail

      • read

        public int read()
                 throws java.io.IOException
        Reads a single byte from the underlying stream.
        Overrides:
        read in class java.io.FilterInputStream
        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 int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Reads a number of bytes from the underlying stream and stores them in the specified byte array at the specified offset.
        Overrides:
        read in class java.io.FilterInputStream
        Returns:
        The actual number of bytes read, or -1 if the end of the stream is reached.
        Throws:
        java.io.IOException - if an I/O error occurs
      • skip

        public long skip​(long n)
                  throws java.io.IOException
        Skips up to the specified number of bytes from the underlying stream.
        Overrides:
        skip in class java.io.FilterInputStream
        Returns:
        The actual number of bytes skipped.
        Throws:
        java.io.IOException - if an I/O error occurs
      • read

        public int read​(byte[] b)
                 throws java.io.IOException
        Reads a number of bytes from the underlying stream and stores them in the specified byte array.
        Overrides:
        read in class java.io.FilterInputStream
        Returns:
        The actual number of bytes read, or -1 if the end of the stream is reached.
        Throws:
        java.io.IOException - if an I/O error occurs
      • setPosition

        private void setPosition()
                          throws java.io.IOException
        Checks if positionedStream's position was changed since last used, sets the position to right position if its changed.
        Throws:
        java.io.IOException