public class FilterInputStream extends InputStream
FilterInputStream包含一些其他输入流,它用作其基本的数据源,可能会沿途转换数据或提供附加功能。
FilterInputStream本身简单地覆盖了所有InputStream的方法, InputStream版本将所有请求传递给包含的输入流。
FilterInputStream的FilterInputStream可以进一步覆盖这些方法中的一些,并且还可以提供附加的方法和领域。
| Modifier and Type | Field and Description |
|---|---|
protected InputStream |
in
要过滤的输入流。
|
| Modifier | Constructor and Description |
|---|---|
protected |
FilterInputStream(InputStream in)
通过将参数
in到字段
this.in创建一个
FilterInputStream ,以便将其记住以供以后使用。
|
| Modifier and Type | Method and Description |
|---|---|
int |
available()
返回从该输入流中可以读取(或跳过)的字节数的估计,而不会被下一个调用者阻塞该输入流的方法。
|
void |
close()
关闭此输入流并释放与流相关联的任何系统资源。
|
void |
mark(int readlimit)
标记此输入流中的当前位置。
|
boolean |
markSupported()
测试这个输入流是否支持
mark和
reset方法。
|
int |
read()
从该输入流读取下一个数据字节。
|
int |
read(byte[] b)
从该输入流读取最多
byte.length个字节的数据到字节数组。
|
int |
read(byte[] b, int off, int len)
从该输入流读取最多
len字节的数据到字节数组。
|
void |
reset()
将此流重新定位到上次在此输入流上调用
mark方法时的位置。
|
long |
skip(long n)
跳过并从输入流中丢弃
n个字节的数据。
|
protected volatile InputStream in
protected FilterInputStream(InputStream in)
in给字段
this.in创建一个
FilterInputStream ,以便记住它以供以后使用。
in - 底层输入流,或
null如果此实例要创建而没有底层流。
public int read()
throws IOException
int返回为0到255 。
如果没有字节可用,因为流已经到达,则返回值-1 。
该方法阻塞直到输入数据可用,检测到流的结尾,或抛出异常。
该方法简单地执行in.read()并返回结果。
read在
InputStream
-1 。
IOException - 如果发生I / O错误。
in
public int read(byte[] b)
throws IOException
byte.length字节的数据到字节数组。
此方法将阻塞,直到某些输入可用。
此方法只需执行调用read(b, 0, b.length)并返回结果。 重要的是不要做in.read(b) ; FilterInputStream的某些子FilterInputStream取决于实际使用的实现策略。
read在
InputStream
b - 读取数据的缓冲区。
-1 。
IOException - 如果发生I / O错误。
read(byte[], int, int)
public int read(byte[] b,
int off,
int len)
throws IOException
len字节的数据到字节数组。
如果len不为零,则该方法将阻塞,直到某些输入可用;
否则,不会读取字节,并返回0 。
该方法简单地执行in.read(b, off, len)并返回结果。
read在
InputStream
b - 读取数据的缓冲区。
off - 目标数组
b的起始偏移量
len - 读取的最大字节数。
-1 。
NullPointerException - 如果
b是
null 。
IndexOutOfBoundsException - 如果
off为负数,
len为负数,或
len为大于
b.length - off
IOException - 如果发生I / O错误。
in
public long skip(long n)
throws IOException
n个字节的数据。
由于各种原因, skip方法可能会跳过一些较小数量的字节,可能是0 。
返回实际跳过的字节数。
该方法简单执行in.skip(n) 。
skip在
InputStream类
n - 要跳过的字节数。
IOException - 如果流不支持查询,或者发生其他I / O错误。
public int available()
throws IOException
此方法返回in .available()的结果。
available在
InputStream
IOException - 如果发生I / O错误。
public void close()
throws IOException
in.close() 。
close在界面
Closeable
close在接口
AutoCloseable
close在
InputStream类
IOException - 如果发生I / O错误。
in
public void mark(int readlimit)
reset方法的调用会将该流重新定位在最后一个标记的位置,以便后续读取重新读取相同的字节。
readlimit参数指示此输入流允许在标记位置无效之前读取许多字节。
该方法简单地执行in.mark(readlimit) 。
mark在
InputStream
readlimit - 在标记位置无效之前可以读取的最大字节数限制。
in ,
reset()
public void reset()
throws IOException
mark方法时的位置。
该方法简单地执行in.reset() 。
流标记旨在用于您需要先阅读一下以查看流中的内容的情况。 通常这通过调用一些一般的解析器来最容易地完成。 如果流是由解析器处理的类型,那么它就可以快乐地拥抱。 如果流不是该类型,解析器应该在失败时抛出异常。 如果在readlimit字节中发生这种情况,它允许外部代码重置流并尝试另一个解析器。
reset在
InputStream
IOException - 如果流未标记或标记已被无效。
in ,
mark(int)
public boolean markSupported()
mark和reset方法。
该方法简单执行in.markSupported() 。
markSupported在
InputStream类
true如果这种流类型支持mark和reset方法;
false否则。
in ,
InputStream.mark(int) ,
InputStream.reset()
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.