public class ObservableInputStream extends ProxyInputStream
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.MessageDigestCalculatingInputStream| Modifier and Type | Class and Description |
|---|---|
static class |
ObservableInputStream.Observer
Abstracts observer callback for
ObservableInputStreams. |
| Constructor and Description |
|---|
ObservableInputStream(InputStream pProxy)
Creates a new ObservableInputStream for the given InputStream.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(ObservableInputStream.Observer pObserver)
Adds an Observer.
|
void |
close()
Invokes the delegate's
close() method. |
void |
consume()
Reads all data from the underlying
InputStream, while notifying the
observers. |
int |
read()
Invokes the delegate's
read() method. |
int |
read(byte[] pBuffer)
Invokes the delegate's
read(byte[]) method. |
int |
read(byte[] pBuffer,
int pOffset,
int pLength)
Invokes the delegate's
read(byte[], int, int) method. |
void |
remove(ObservableInputStream.Observer pObserver)
Removes an Observer.
|
void |
removeAllObservers()
Removes all Observers.
|
available, mark, markSupported, reset, skippublic ObservableInputStream(InputStream pProxy)
pProxy - the input stream to proxypublic void add(ObservableInputStream.Observer pObserver)
pObserver - the observer to addpublic void remove(ObservableInputStream.Observer pObserver)
pObserver - the observer to removepublic void removeAllObservers()
public int read()
throws IOException
ProxyInputStreamread() method.read in class ProxyInputStreamIOException - if an I/O error occurspublic int read(byte[] pBuffer)
throws IOException
ProxyInputStreamread(byte[]) method.read in class ProxyInputStreampBuffer - the buffer to read the bytes intoIOException - if an I/O error occurspublic int read(byte[] pBuffer,
int pOffset,
int pLength)
throws IOException
ProxyInputStreamread(byte[], int, int) method.read in class ProxyInputStreampBuffer - the buffer to read the bytes intopOffset - The start offsetpLength - The number of bytes to readIOException - if an I/O error occurspublic void close()
throws IOException
ProxyInputStreamclose() method.close in interface Closeableclose in interface AutoCloseableclose in class ProxyInputStreamIOException - if an I/O error occurspublic void consume()
throws IOException
InputStream, while notifying the
observers.IOException - The underlying InputStream, or either of the
observers has thrown an exception.Jas4pp 1.5 © Java Analysis Studio for Particle Physics