public class EofSensorInputStream extends InputStream implements ConnectionReleaseTrigger
close()和EOF上的动作。
主要用于在响应主体消耗或不再需要时自动释放底层受管连接。
EofSensorWatcher
| Modifier and Type | Field and Description |
|---|---|
protected InputStream |
wrappedStream
包装的输入流,同时可访问。
|
| Constructor and Description |
|---|
EofSensorInputStream(InputStream in, EofSensorWatcher watcher)
创建一个新的EOF传感器。
|
| Modifier and Type | Method and Description |
|---|---|
void |
abortConnection()
中止此流。
|
int |
available() |
protected void |
checkAbort()
检测流中止并通知观察者。
|
protected void |
checkClose()
检测流关闭并通知观察者。
|
protected void |
checkEOF(int eof)
检测EOF并通知观察者。
|
void |
close() |
protected boolean |
isReadAllowed()
检查底层流是否可以读取。
|
int |
read() |
int |
read(byte[] b) |
int |
read(byte[] b, int off, int len) |
void |
releaseConnection()
与
close()相同。
|
mark, markSupported, reset, skipprotected InputStream wrappedStream
null 。
public EofSensorInputStream(InputStream in, EofSensorWatcher watcher)
in - 包裹流
watcher - 事件的观察者,或
null自动关闭行为,不通知
protected boolean isReadAllowed()
throws IOException
true如果底层流是可访问的,
false如果这个流是处于EOF模式,并从底层流分离
IOException - 如果此流已关闭
public int read()
throws IOException
read在
InputStream
IOException
public int read(byte[] b,
int off,
int len)
throws IOException
read在
InputStream
IOException
public int read(byte[] b)
throws IOException
read在
InputStream
IOException
public int available()
throws IOException
available在
InputStream
IOException
public void close()
throws IOException
close在接口
Closeable
close在接口
AutoCloseable
close在
InputStream
IOException
protected void checkEOF(int eof)
throws IOException
isReadAllowed检查该条件。
如果检测到EOF,则将通知观察者,并将该流与基础流分离。 这可以防止来自此流的多个通知。
eof - 调用读操作的结果。
负值表示达到了EOF。
IOException - 关闭底层流时出现IO问题
protected void checkClose()
throws IOException
IOException - 关闭底层流时出现IO问题
protected void checkAbort()
throws IOException
abortConnection调用 。
观察者只有在第一次中止此流,并且在检测到EOF或流优化closed之前才会被通知。
此流将与基础流分离,以防止对观察者发送多次通知。
IOException - 关闭底层流时出现IO问题
public void releaseConnection()
throws IOException
close()相同。
releaseConnection在界面
ConnectionReleaseTrigger
IOException - 在IO问题的情况下。
连接将会被释放。
public void abortConnection()
throws IOException
abortConnection在接口
ConnectionReleaseTrigger
IOException - 在出现IO问题的情况下。
连接将会被释放。
Copyright © 1999–2017 The Apache Software Foundation. All rights reserved.