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 |
Constructor and Description |
---|
ObservableInputStream(java.io.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, skip
public ObservableInputStream(java.io.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 java.io.IOException
ProxyInputStream
read()
method.read
in class ProxyInputStream
java.io.IOException
- if an I/O error occurspublic int read(byte[] pBuffer) throws java.io.IOException
ProxyInputStream
read(byte[])
method.read
in class ProxyInputStream
pBuffer
- the buffer to read the bytes intojava.io.IOException
- if an I/O error occurspublic int read(byte[] pBuffer, int pOffset, int pLength) throws java.io.IOException
ProxyInputStream
read(byte[], int, int)
method.read
in class ProxyInputStream
pBuffer
- the buffer to read the bytes intopOffset
- The start offsetpLength
- The number of bytes to readjava.io.IOException
- if an I/O error occurspublic void close() throws java.io.IOException
ProxyInputStream
close()
method.close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class ProxyInputStream
java.io.IOException
- if an I/O error occurspublic void consume() throws java.io.IOException
InputStream
, while notifying the
observers.java.io.IOException
- The underlying InputStream
, or either of the
observers has thrown an exception.Copyright © 2010 - 2020 Adobe. All Rights Reserved