Class ObservableInputStream

    • Constructor Detail

      • ObservableInputStream

        public ObservableInputStream​(java.io.InputStream inputStream)
        Creates a new ObservableInputStream for the given InputStream.
        Parameters:
        inputStream - the input stream to observe.
      • ObservableInputStream

        public ObservableInputStream​(java.io.InputStream inputStream,
                                     ObservableInputStream.Observer... observers)
        Creates a new ObservableInputStream for the given InputStream.
        Parameters:
        inputStream - the input stream to observe.
        observers - List of observer callbacks.
        Since:
        2.9.0
    • Method Detail

      • close

        public void close()
                   throws java.io.IOException
        Description copied from class: ProxyInputStream
        Invokes the delegate's close() method.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class ProxyInputStream
        Throws:
        java.io.IOException - if an I/O error occurs.
      • consume

        public void consume()
                     throws java.io.IOException
        Reads all data from the underlying InputStream, while notifying the observers.
        Throws:
        java.io.IOException - The underlying InputStream, or either of the observers has thrown an exception.
      • getObservers

        public java.util.List<ObservableInputStream.Observer> getObservers()
        Gets all currently registered observers.
        Returns:
        a list of the currently registered observers.
        Since:
        2.9.0
      • noteClosed

        protected void noteClosed()
                           throws java.io.IOException
        Notifies the observers by invoking ObservableInputStream.Observer.finished().
        Throws:
        java.io.IOException - Some observer has thrown an exception, which is being passed down.
      • noteDataByte

        protected void noteDataByte​(int value)
                             throws java.io.IOException
        Notifies the observers by invoking ObservableInputStream.Observer.data(int) with the given arguments.
        Parameters:
        value - Passed to the observers.
        Throws:
        java.io.IOException - Some observer has thrown an exception, which is being passed down.
      • noteDataBytes

        protected void noteDataBytes​(byte[] buffer,
                                     int offset,
                                     int length)
                              throws java.io.IOException
        Notifies the observers by invoking ObservableInputStream.Observer.data(byte[],int,int) with the given arguments.
        Parameters:
        buffer - Passed to the observers.
        offset - Passed to the observers.
        length - Passed to the observers.
        Throws:
        java.io.IOException - Some observer has thrown an exception, which is being passed down.
      • noteError

        protected void noteError​(java.io.IOException exception)
                          throws java.io.IOException
        Notifies the observers by invoking ObservableInputStream.Observer.error(IOException) with the given argument.
        Parameters:
        exception - Passed to the observers.
        Throws:
        java.io.IOException - Some observer has thrown an exception, which is being passed down. This may be the same exception, which has been passed as an argument.
      • noteFinished

        protected void noteFinished()
                             throws java.io.IOException
        Notifies the observers by invoking ObservableInputStream.Observer.finished().
        Throws:
        java.io.IOException - Some observer has thrown an exception, which is being passed down.
      • read

        public int read()
                 throws java.io.IOException
        Description copied from class: ProxyInputStream
        Invokes the delegate's read() method.
        Overrides:
        read in class ProxyInputStream
        Returns:
        the byte read or -1 if the end of stream
        Throws:
        java.io.IOException - if an I/O error occurs.
      • read

        public int read​(byte[] buffer)
                 throws java.io.IOException
        Description copied from class: ProxyInputStream
        Invokes the delegate's read(byte[]) method.
        Overrides:
        read in class ProxyInputStream
        Parameters:
        buffer - the buffer to read the bytes into
        Returns:
        the number of bytes read or EOF if the end of stream
        Throws:
        java.io.IOException - if an I/O error occurs.
      • read

        public int read​(byte[] buffer,
                        int offset,
                        int length)
                 throws java.io.IOException
        Description copied from class: ProxyInputStream
        Invokes the delegate's read(byte[], int, int) method.
        Overrides:
        read in class ProxyInputStream
        Parameters:
        buffer - the buffer to read the bytes into
        offset - The start offset
        length - The number of bytes to read
        Returns:
        the number of bytes read or -1 if the end of stream
        Throws:
        java.io.IOException - if an I/O error occurs.
      • removeAllObservers

        public void removeAllObservers()
        Removes all Observers.