|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjava.io.InputStream
java.io.FilterInputStream
java.io.BufferedInputStream
public class BufferedInputStream
BufferedInputStream 为另一个输入流添加一些功能,即缓冲输入以及支持 mark 和 reset 方法的能力。在创建 BufferedInputStream 时,会创建一个内部缓冲区数组。在读取或跳过流中的字节时,可根据需要从包含的输入流再次填充该内部缓冲区,一次填充多个字节。mark 操作记录输入流中的某个点,reset 操作使得在从包含的输入流中获取新字节之前,再次读取自最后一次 mark 操作后读取的所有字节。
| 字段摘要 | |
|---|---|
protected byte[] |
buf
存储数据的内部缓冲区数组。 |
protected int |
count
比缓冲区中最后一个有效字节的索引大 1 的索引。 |
protected int |
marklimit
调用 mark 方法后,在后续调用 reset 方法失败之前所允许的最大提前读取量。 |
protected int |
markpos
最后一次调用 mark 方法时 pos 字段的值。 |
protected int |
pos
缓冲区中的当前位置。 |
| 从类 java.io.FilterInputStream 继承的字段 |
|---|
in |
| 构造方法摘要 | |
|---|---|
BufferedInputStream(InputStream in)
创建一个 BufferedInputStream 并保存其参数,即输入流 in,以便将来使用。 |
|
BufferedInputStream(InputStream in,
int size)
创建具有指定缓冲区大小的 BufferedInputStream 并保存其参数,即输入流 in,以便将来使用。 |
|
| 方法摘要 | |
|---|---|
int |
available()
返回可以从此输入流读取(或跳过)、且不受此输入流接下来的方法调用阻塞的估计字节数。 |
void |
close()
关闭此输入流并释放与该流关联的所有系统资源。 |
void |
mark(int readlimit)
参见 InputStream 的 mark 方法的常规协定。 |
boolean |
markSupported()
测试此输入流是否支持 mark 和 reset 方法。 |
int |
read()
参见 InputStream 的 read 方法的常规协定。 |
int |
read(byte[] b,
int off,
int len)
从此字节输入流中给定偏移量处开始将各字节读取到指定的 byte 数组中。 |
void |
reset()
参见 InputStream 的 reset 方法的常规协定。 |
long |
skip(long n)
参见 InputStream 的 skip 方法的常规协定。 |
| 从类 java.io.FilterInputStream 继承的方法 |
|---|
read |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 字段详细信息 |
|---|
protected volatile byte[] buf
protected int count
0 到 buf.length 的范围内;从 buf[0] 到 buf[count-1] 的元素包含从底层输入流中获取的缓冲输入数据。
protected int pos
buf 数组中读取的下一个字符的索引。
此值始终处于 0 到 count 的范围内。如果此值小于 count,则 buf[pos] 将作为下一个输入字节;如果此值等于 count,则下一次 read 或 skip 操作需要从包含的输入流中读取更多的字节。
bufprotected int markpos
mark 方法时 pos 字段的值。
此值始终处于 -1 到 pos 的范围内。如果输入流中没有被标记的位置,则此字段为 -1。如果输入流中有被标记的位置,则 buf[markpos] 将用作 reset 操作后的第一个输入字节。如果 markpos 不是 -1,则从位置 buf[markpos] 到 buf[pos-1] 之间的所有字节都必须保留在缓冲区数组中(尽管对 count、pos 和 markpos 的值进行适当调整后,这些字节可能移动到缓冲区数组中的其他位置);除非 pos 与 markpos 的差超过 marklimit,否则不能将其丢弃。
mark(int),
posprotected int marklimit
mark 方法后,在后续调用 reset 方法失败之前所允许的最大提前读取量。只要 pos 与 markpos 之差超过 marklimit,就可以通过将 markpos 设置为 -1 来删除该标记。
mark(int),
reset()| 构造方法详细信息 |
|---|
public BufferedInputStream(InputStream in)
BufferedInputStream 并保存其参数,即输入流 in,以便将来使用。创建一个内部缓冲区数组并将其存储在 buf 中。
in - 底层输入流。
public BufferedInputStream(InputStream in,
int size)
BufferedInputStream 并保存其参数,即输入流 in,以便将来使用。创建一个长度为 size 的内部缓冲区数组并将其存储在 buf 中。
in - 底层输入流。size - 缓冲区大小。
IllegalArgumentException - 如果 size <= 0| 方法详细信息 |
|---|
public int read()
throws IOException
InputStream 的 read 方法的常规协定。
FilterInputStream 中的 read-1。
IOException - 如果已经调用其 close() 方法关闭了此输入流,或者发生 I/O 错误。FilterInputStream.in
public int read(byte[] b,
int off,
int len)
throws IOException
此方法实现了 类相应 InputStream 方法的常规协定。另一个便捷之处在于,它将通过重复地调用底层流的 readread 方法,尝试读取尽可能多的字节。这种迭代的 read 会一直继续下去,直到满足以下条件之一:
read 方法返回 -1,指示文件末尾(end-of-file),或者
available 方法返回 0,指示将阻塞后续的输入请求。
read 返回 -1(指示文件末尾),则此方法返回 -1。否则此方法返回实际读取的字节数。
鼓励(但不是必须)此类的各个子类以相同的方式尝试读取尽可能多的字节。
FilterInputStream 中的 readb - 目标缓冲区。off - 开始存储字节处的偏移量。len - 要读取的最大字节数。
-1。
IOException - 如果已经调用其 close() 方法关闭了此输入流,或者发生 I/O 错误。FilterInputStream.in
public long skip(long n)
throws IOException
InputStream 的 skip 方法的常规协定。
FilterInputStream 中的 skipn - 要跳过的字节数。
IOException - 如果流不支持查找操作;或者已经调用其 close() 方法关闭了此输入流;或者发生 I/O 错误。
public int available()
throws IOException
此方法返回缓冲区中剩余的待读取字节数 (count - pos) 与调用 in.available() 的结果之和。
FilterInputStream 中的 availableIOException - 如果已经调用其 close() 方法关闭了此输入流,或者发生 I/O 错误。public void mark(int readlimit)
InputStream 的 mark 方法的常规协定。
FilterInputStream 中的 markreadlimit - 在标记位置变为无效之前可以读取字节的最大限制。reset()
public void reset()
throws IOException
InputStream 的 reset 方法的常规协定。
如果 markpos 为 -1(尚未设置标记,或者标记已失效),则抛出 IOException。否则将 pos 设置为与 markpos 相等。
FilterInputStream 中的 resetIOException - 如果尚未标记此流;或者标记已失效;或者已经调用其 close() 方法关闭了此输入流;或者发生 I/O 错误。mark(int)public boolean markSupported()
mark 和 reset 方法。BufferedInputStream 的 markSupported 方法返回 true。
FilterInputStream 中的 markSupportedboolean 值,指示此流类型是否支持 mark 和 reset 方法。InputStream.mark(int),
InputStream.reset()
public void close()
throws IOException
Closeable 中的 closeFilterInputStream 中的 closeIOException - 如果发生 I/O 错误。FilterInputStream.in
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。