Class ObservableInputStream

All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
MessageDigestCalculatingInputStream

public class ObservableInputStream extends ProxyInputStream
The ObservableInputStream allows, that an InputStream may be consumed by other receivers, apart from the thread, which is reading it. The other consumers are implemented as instances of ObservableInputStream.Observer.

A typical application may be the generation of a MessageDigest on the fly.

Note: The ObservableInputStream is not thread safe, as instances of InputStream usually aren't. If you must access the stream from multiple threads, then synchronization, locking, or a similar means must be used.

See Also:
  • Field Details

  • Constructor Details

    • ObservableInputStream

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

      private ObservableInputStream(InputStream inputStream, List<ObservableInputStream.Observer> observers)
      Creates a new ObservableInputStream for the given InputStream.
      Parameters:
      inputStream - the input stream to observe.
      observers - List of observer callbacks.
    • ObservableInputStream

      public ObservableInputStream(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 Details