java.lang.Object | ||
↳ | java.io.InputStream | |
↳ | org.apache.http.conn.EofSensorInputStream |
A stream wrapper that triggers actions on close()
and EOF.
Primarily used to auto-release an underlying
connection
when the response body is consumed or no longer needed.
This class is based on AutoCloseInputStream
in HttpClient 3.1,
but has notable differences. It does not allow mark/reset, distinguishes
different kinds of event, and does not always close the underlying stream
on EOF. That decision is left to the watcher
.
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
wrappedStream | The wrapped input stream, while accessible. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a new EOF sensor.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Aborts this stream.
| |||||||||||
Returns the number of bytes that are available before this stream will
block.
| |||||||||||
Closes this stream.
| |||||||||||
Reads at most
length bytes from this stream and stores them in
the byte array b starting at offset . | |||||||||||
Reads bytes from this stream and stores them in the byte array
b . | |||||||||||
Reads a single byte from this stream and returns it as an integer in the
range from 0 to 255.
| |||||||||||
Same as
close() . |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Detects stream abort and notifies the watcher.
| |||||||||||
Detects stream close and notifies the watcher.
| |||||||||||
Detects EOF and notifies the watcher.
| |||||||||||
Checks whether the underlying stream can be read from.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.io.InputStream
| |||||||||||
From class java.lang.Object
| |||||||||||
From interface java.io.Closeable
| |||||||||||
From interface org.apache.http.conn.ConnectionReleaseTrigger
|
The wrapped input stream, while accessible.
The value changes to null
when the wrapped stream
becomes inaccessible.
Creates a new EOF sensor.
If no watcher is passed, the underlying stream will simply be
closed when EOF is detected or close
is called.
Otherwise, the watcher decides whether the underlying stream
should be closed before detaching from it.
in | the wrapped stream |
---|---|
watcher | the watcher for events, or null for
auto-close behavior without notification
|
Aborts this stream.
This is a special version of close()
which prevents
re-use of the underlying connection, if any. Calling this method
indicates that there should be no attempt to read until the end of
the stream.
IOException |
---|
Returns the number of bytes that are available before this stream will block. This implementation always returns 0. Subclasses should override and indicate the correct number of bytes available.
IOException |
---|
Closes this stream. Concrete implementations of this class should free any resources during close. This implementation does nothing.
IOException |
---|
Reads at most length
bytes from this stream and stores them in
the byte array b
starting at offset
.
b | the byte array in which to store the bytes read. |
---|---|
off | the initial position in buffer to store the bytes read
from this stream. |
len | the maximum number of bytes to store in b . |
IOException |
---|
Reads bytes from this stream and stores them in the byte array b
.
b | the byte array in which to store the bytes read. |
---|
IOException |
---|
Reads a single byte from this stream and returns it as an integer in the range from 0 to 255. Returns -1 if the end of the stream has been reached. Blocks until one byte has been read, the end of the source stream is detected or an exception is thrown.
IOException |
---|
Detects stream abort and notifies the watcher.
There's not much to detect since this is called by
abortConnection
.
The watcher will only be notified if this stream is aborted
for the first time and before EOF has been detected or the
stream has been closed
gracefully.
This stream will be detached from the underlying stream to prevent
multiple notifications to the watcher.
IOException | in case of an IO problem on closing the underlying stream |
---|
Detects stream close and notifies the watcher.
There's not much to detect since this is called by close
.
The watcher will only be notified if this stream is closed
for the first time and before EOF has been detected.
This stream will be detached from the underlying stream to prevent
multiple notifications to the watcher.
IOException | in case of an IO problem on closing the underlying stream |
---|
Detects EOF and notifies the watcher.
This method should only be called while the underlying stream is
still accessible. Use isReadAllowed
to
check that condition.
If EOF is detected, the watcher will be notified and this stream
is detached from the underlying stream. This prevents multiple
notifications from this stream.
eof | the result of the calling read operation. A negative value indicates that EOF is reached. |
---|
IOException | in case of an IO problem on closing the underlying stream |
---|
Checks whether the underlying stream can be read from.
true
if the underlying stream is accessible,
false
if this stream is in EOF mode and
detached from the underlying streamIOException | if this stream is already closed |
---|