public class BufferedInputStream extends FilterInputStream
BufferedInputStream添加功能到另一个输入流,即缓冲输入和支持
mark和
reset方法的能力。当
BufferedInputStream创建,内部缓冲区创建数组。从流中读取字节或跳过,内部缓冲区填充为必要从包含输入流,同时许多字节。的
mark操作记得输入流中的一个点和
reset操作使所有字节读因为最近的
mark操作要重读前新的字节是从包含输入流。
| Modifier and Type | Field and Description |
|---|---|
protected byte[] |
buf
存储数据的内部缓冲区阵列。
|
protected int |
count
在缓冲区中的最后一个有效字节的索引大于一个索引。
|
protected int |
marklimit
最大允许读之前调用的方法的后续调用
mark之前的
reset方法失败之后。
|
protected int |
markpos
当时称为“最后的
mark方法的
pos字段的值。
|
protected int |
pos
缓冲区中的当前位置。
|
in| Constructor and Description |
|---|
BufferedInputStream(InputStream in)
创建一个
BufferedInputStream和保存它的参数,输入流
in,供以后使用。
|
BufferedInputStream(InputStream in, int size)
创建一个具有指定的缓冲区大小
BufferedInputStream,并保存它的参数,输入流
in,供以后使用。
|
| Modifier and Type | Method and Description |
|---|---|
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)
从这个字节的输入流读取到指定的字节数组中的字节,从给定的偏移量开始。
|
void |
reset()
看到的
InputStream的
reset方法一般合同。
|
long |
skip(long n)
看到的
InputStream的
skip方法一般合同。
|
readprotected volatile byte[] buf
protected int count
0通过
buf.length;元素
buf[0]通过
buf[count-1] contain缓冲输入数据从底层输入流中获取。
protected int pos
buf阵列读取索引。
这个值总是在范围0通过count。如果它小于count,然后buf[pos]是提供作为输入的下一个字节;如果它等于count,那么下一read或skip操作将需要更多的数据被从输入流中读取包含。
buf
protected int markpos
mark方法的
pos字段的值。
这个值总是在范围-1通过pos。如果输入流中的无标记的位置,这场-1。如果输入流中的一个标记的位置,然后buf[markpos]是提供作为reset运行后输入的第一个字节。如果markpos不-1,那么所有的字节位置buf[markpos]通过buf[pos-1]必须保留在缓冲数组(尽管他们可能会搬到另一个地方在缓冲数组,用适当的调整值count,pos,和markpos);他们可能不被丢弃,除非pos和markpos之间的差异超过marklimit。
public BufferedInputStream(InputStream in)
BufferedInputStream和保存它的参数,输入流
in,供以后使用。一个内部缓冲数组创建并存储在
buf。
in -数据输入流。
public BufferedInputStream(InputStream in, int size)
BufferedInputStream,并保存它的参数,输入流
in,供以后使用。长
size内部缓冲区数组创建并存储在
buf。
in -数据输入流。
size -缓冲区大小。
size <= 0
IllegalArgumentException。
public int read()
throws IOException
InputStream的
read方法一般合同。
read 方法重写,继承类
FilterInputStream
-1如果到达流的末尾。
IOException如果输入流被调用其
close()方法关闭,或发生I/O错误。
FilterInputStream.in
public int read(byte[] b,
int off,
int len)
throws IOException
该方法实现了对类相应的InputStream方法一般合同。作为一个额外的便利,它试图读尽可能多的字节通过反复调用的底层流readread方法。这read迭代直至下列条件之一为真:
-1的read方法,表示文件结束,或available方法返回零,表明进一步的输入请求块。read返回
-1表示文件结束之后这个方法返回
-1。否则,此方法返回实际读取的字节数。
这个类的子类是鼓励的,但不是必需的,试图以相同的方式读取尽可能多的字节数。
read 方法重写,继承类
FilterInputStream
b -目的缓冲区。
off偏移,开始存储字节。
len -最大字节数读。
-1如果已到达流的末尾。
IOException如果输入流被调用其
close()方法关闭,或发生I/O错误。
FilterInputStream.in
public long skip(long n)
throws IOException
InputStream的
skip方法一般合同。
skip 方法重写,继承类
FilterInputStream
n -字节数被跳过。
IOException如果流不支持查找,如果输入流被调用其
close()方法关闭,或发生I/O错误。
public int available()
throws IOException
此方法返回剩余是在缓冲区中读取的字节数的总和(count - pos)和in available()调用的结果。
available 方法重写,继承类
FilterInputStream
IOException如果输入流被调用其
close()方法关闭,或发生I/O错误。
public void mark(int readlimit)
InputStream的
mark方法一般合同。
mark 方法重写,继承类
FilterInputStream
readlimit -字节可以在标记位置无效阅读最大限度。
reset()
public void reset()
throws IOException
InputStream的
reset方法一般合同。
如果markpos是-1(没有设置标记或商标已失效),一个IOException抛出。否则,pos等于markpos。
reset 方法重写,继承类
FilterInputStream
IOException -如果这流未标记的或,如果商标已无效,或流已经通过调用其
close()方法关闭,或发生I/O错误。
mark(int)
public boolean markSupported()
mark和
reset方法。对
BufferedInputStream返回
true的
markSupported方法。
markSupported 方法重写,继承类
FilterInputStream
boolean表示如果这流类型支持
mark和
reset方法。
InputStream.mark(int),
InputStream.reset()
public void close()
throws IOException
close 接口
Closeable
close 接口
AutoCloseable
close 方法重写,继承类
FilterInputStream
IOException如果I/O错误发生。
FilterInputStream.in
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.