|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.InputStream
org.apache.http.conn.EofSensorInputStream
public class 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.
EofSensorWatcher| Field Summary | |
|---|---|
protected InputStream |
wrappedStream
The wrapped input stream, while accessible. |
| Constructor Summary | |
|---|---|
EofSensorInputStream(InputStream in,
EofSensorWatcher watcher)
Creates a new EOF sensor. |
|
| Method Summary | |
|---|---|
void |
abortConnection()
Aborts this stream. |
int |
available()
Returns a int representing then number of bytes that are available before this InputStream will block. |
protected void |
checkAbort()
Detects stream abort and notifies the watcher. |
protected void |
checkClose()
Detects stream close and notifies the watcher. |
protected void |
checkEOF(int eof)
Detects EOF and notifies the watcher. |
void |
close()
Close the InputStream. |
protected boolean |
isReadAllowed()
Checks whether the underlying stream can be read from. |
int |
read()
Reads a single byte from this InputStream and returns the result as an int. |
int |
read(byte[] b)
Reads bytes from the Stream and stores them in byte array b. |
int |
read(byte[] b,
int off,
int len)
Reads at most length bytes from the Stream and stores them
in byte array b starting at offset. |
void |
releaseConnection()
Same as close(). |
| Methods inherited from class java.io.InputStream |
|---|
mark, markSupported, reset, skip |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected InputStream wrappedStream
null when the wrapped stream
becomes inaccessible.
| Constructor Detail |
|---|
public EofSensorInputStream(InputStream in,
EofSensorWatcher watcher)
close is called.
Otherwise, the watcher decides whether the underlying stream
should be closed before detaching from it.
in - the wrapped streamwatcher - the watcher for events, or null for
auto-close behavior without notification| Method Detail |
|---|
protected boolean isReadAllowed()
throws IOException
true if the underlying stream is accessible,
false if this stream is in EOF mode and
detached from the underlying stream
IOException - if this stream is already closed
public int read()
throws IOException
InputStream
read in class InputStreamIOException - If the stream is already closed or another IOException
occurs.
public int read(byte[] b,
int off,
int len)
throws IOException
InputStreamlength bytes from the Stream and stores them
in byte array b starting at offset. Answer
the number of bytes actually read or -1 if no bytes were read and end of
stream was encountered.
read in class InputStreamb - the byte array in which to store the read bytes.off - the offset in b to store the read bytes.len - the maximum number of bytes to store in b.
IOException - If the stream is already closed or another IOException
occurs.
public int read(byte[] b)
throws IOException
InputStreamb.
Answer the number of bytes actually read or -1 if no bytes were read and
end of stream was encountered.
read in class InputStreamb - the byte array in which to store the read bytes.
IOException - If the stream is already closed or another IOException
occurs.
public int available()
throws IOException
InputStream
available in class InputStreamIOException - If an error occurs in this InputStream.
public void close()
throws IOException
InputStream
close in interface Closeableclose in class InputStreamIOException - If an error occurs attempting to close this InputStream.
protected void checkEOF(int eof)
throws IOException
isReadAllowed to
check that condition.
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
protected void checkClose()
throws IOException
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
protected void checkAbort()
throws IOException
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
public void releaseConnection()
throws IOException
close().
releaseConnection in interface ConnectionReleaseTriggerIOException - in case of an IO problem. The connection will be released
anyway.
public void abortConnection()
throws IOException
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.
abortConnection in interface ConnectionReleaseTriggerIOException - in case of an IO problem.
The connection will be released anyway.
|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||