? ObservableInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.apache.commons.io.input.ProxyInputStream
org.apache.commons.io.input.ObservableInputStream
- ????????:
Closeable
,AutoCloseable
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.
-
?????
????????????static class
Abstracts observer callback forObservableInputStream
s. -
????
??????? java.io.FilterInputStream
in
-
?????
????????ObservableInputStream
(InputStream inputStream) Creates a new ObservableInputStream for the given InputStream.ObservableInputStream
(InputStream inputStream, ObservableInputStream.Observer... observers) Creates a new ObservableInputStream for the given InputStream. -
????
??????????void
add
(ObservableInputStream.Observer observer) Adds an Observer.void
close()
Invokes the delegate'sclose()
method.void
consume()
Reads all data from the underlyingInputStream
, while notifying the observers.Gets all currently registered observers.protected void
Notifies the observers by invokingObservableInputStream.Observer.finished()
.protected void
noteDataByte
(int value) Notifies the observers by invokingObservableInputStream.Observer.data(int)
with the given arguments.protected void
noteDataBytes
(byte[] buffer, int offset, int length) Notifies the observers by invokingObservableInputStream.Observer.data(byte[],int,int)
with the given arguments.protected void
noteError
(IOException exception) Notifies the observers by invokingObservableInputStream.Observer.error(IOException)
with the given argument.protected void
Notifies the observers by invokingObservableInputStream.Observer.finished()
.int
read()
Invokes the delegate'sread()
method.int
read
(byte[] buffer) Invokes the delegate'sread(byte[])
method.int
read
(byte[] buffer, int offset, int length) Invokes the delegate'sread(byte[], int, int)
method.void
remove
(ObservableInputStream.Observer observer) Removes an Observer.void
Removes all Observers.??????? org.apache.commons.io.input.ProxyInputStream
afterRead, available, beforeRead, handleIOException, mark, markSupported, reset, skip
??????? java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
???????
-
ObservableInputStream
Creates a new ObservableInputStream for the given InputStream.- ??:
inputStream
- the input stream to observe.
-
ObservableInputStream
Creates a new ObservableInputStream for the given InputStream.- ??:
inputStream
- the input stream to observe.observers
- List of observer callbacks.- ???????:
- 2.9.0
-
-
??????
-
add
Adds an Observer.- ??:
observer
- the observer to add.
-
close
???????:ProxyInputStream
Invokes the delegate'sclose()
method.- ???:
close
????AutoCloseable
- ???:
close
????Closeable
- ??:
close
???ProxyInputStream
- ??:
IOException
- if an I/O error occurs.
-
consume
Reads all data from the underlyingInputStream
, while notifying the observers.- ??:
IOException
- The underlyingInputStream
, or either of the observers has thrown an exception.
-
getObservers
Gets all currently registered observers.- ??:
- a list of the currently registered observers.
- ???????:
- 2.9.0
-
noteClosed
Notifies the observers by invokingObservableInputStream.Observer.finished()
.- ??:
IOException
- Some observer has thrown an exception, which is being passed down.
-
noteDataByte
Notifies the observers by invokingObservableInputStream.Observer.data(int)
with the given arguments.- ??:
value
- Passed to the observers.- ??:
IOException
- Some observer has thrown an exception, which is being passed down.
-
noteDataBytes
Notifies the observers by invokingObservableInputStream.Observer.data(byte[],int,int)
with the given arguments.- ??:
buffer
- Passed to the observers.offset
- Passed to the observers.length
- Passed to the observers.- ??:
IOException
- Some observer has thrown an exception, which is being passed down.
-
noteError
Notifies the observers by invokingObservableInputStream.Observer.error(IOException)
with the given argument.- ??:
exception
- Passed to the observers.- ??:
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
Notifies the observers by invokingObservableInputStream.Observer.finished()
.- ??:
IOException
- Some observer has thrown an exception, which is being passed down.
-
read
???????:ProxyInputStream
Invokes the delegate'sread()
method.- ??:
read
???ProxyInputStream
- ??:
- the byte read or -1 if the end of stream
- ??:
IOException
- if an I/O error occurs.
-
read
???????:ProxyInputStream
Invokes the delegate'sread(byte[])
method.- ??:
read
???ProxyInputStream
- ??:
buffer
- the buffer to read the bytes into- ??:
- the number of bytes read or EOF if the end of stream
- ??:
IOException
- if an I/O error occurs.
-
read
???????:ProxyInputStream
Invokes the delegate'sread(byte[], int, int)
method.- ??:
read
???ProxyInputStream
- ??:
buffer
- the buffer to read the bytes intooffset
- The start offsetlength
- The number of bytes to read- ??:
- the number of bytes read or -1 if the end of stream
- ??:
IOException
- if an I/O error occurs.
-
remove
Removes an Observer.- ??:
observer
- the observer to remove
-
removeAllObservers
Removes all Observers.
-