public class PushbackInputStream extends FilterInputStream
PushbackInputStream
添加功能到另一个输入流,即能够“推”或“未读”一个字节。这是非常有用的,它的代码片段阅读,是由一个特定的字节值分隔符的数据字节的数量方便情况;阅读后终止的字节代码片段可以“未读”,这样在输入流中的下一个读操作将重读字节被推了回来。例如,代表构成标识符的字符的字节可以由一个表示操作符的字节终止;一种方法,其工作是只读一个标识符,直到它看到操作符,然后再将操作人员重新读取。
Modifier and Type | Field and Description |
---|---|
protected byte[] |
buf
回退缓冲区。
|
protected int |
pos
位置在后推缓冲,下一个字节将被读取。
|
in
Constructor and Description |
---|
PushbackInputStream(InputStream in)
创建一个
PushbackInputStream 和保存它的参数,输入流
in ,供以后使用。
|
PushbackInputStream(InputStream in, int size)
创建一个指定的缓冲区
PushbackInputStream
size 一推,并保存它的参数,输入流
in ,供以后使用。
|
Modifier and Type | Method and Description |
---|---|
int |
available()
返回一个可以从这个输入流读取(或跳过)的字节数的估计值,而不阻塞该输入流的下一个方法的调用。
|
void |
close()
关闭此输入流并释放与流关联的任何系统资源。
|
void |
mark(int readlimit)
标记此输入流中的当前位置。
|
boolean |
markSupported()
如果输入流的支持
mark 和
reset 方法,它不。
|
int |
read()
从这个输入流读取下一个数据字节。
|
int |
read(byte[] b, int off, int len)
读到
len 字节从输入流到字节数组数据。
|
void |
reset()
重新定位该流在时间的
mark 方法的位置上呼吁这个输入流。
|
long |
skip(long n)
跳过并丢弃
n 字节从输入流中的数据。
|
void |
unread(byte[] b)
将字节数组复制到缓冲区的推前。
|
void |
unread(byte[] b, int off, int len)
把后面的字节数组的一部分复制到缓冲区的推前。
|
void |
unread(int b)
掀开一个字节复制到缓冲区的推前。
|
read
protected byte[] buf
protected int pos
pos
等于
buf.length
;当缓冲区已满,
pos
等于零。
public PushbackInputStream(InputStream in, int size)
PushbackInputStream
size
一推,并保存它的参数,输入流
in
,供以后使用。最初,没有推字节(现场
pushBack
初始化为
-1
)。
in
-输入流的字节将被读取。
size
-回退缓冲区的大小。
size <= 0
IllegalArgumentException
public PushbackInputStream(InputStream in)
PushbackInputStream
和保存它的参数,输入流
in
,供以后使用。最初,没有推字节(现场
pushBack
初始化为
-1
)。
in
-输入流的字节将被读取。
public int read() throws IOException
0
一
int
到
255
返回。如果没有可用的字节,因为已到达流的末尾,则返回值
-1
。此方法块,直到输入数据可用,流的结束被检测到,或抛出异常。
此方法返回最近推的字节,如果有一个,否则调用其数据输入流和返回任何值,方法返回read
方法。
read
方法重写,继承类
FilterInputStream
-1
如果已到达流的末尾。
IOException
如果输入流被调用其
close()
方法关闭,或发生I/O错误。
InputStream.read()
public int read(byte[] b, int off, int len) throws IOException
len
从输入流到字节数组数据字节。该方法首先读取任何推字节;之后,如果少于
len
字节被读取然后读取数据输入流。如果
len
不为零,法块直到至少1字节的输入是有效的;否则,没有字节读取和
0
返回。
read
方法重写,继承类
FilterInputStream
b
-缓冲区中读取数据。
off
-开始抵消目标数组
b
len
-的最大字节数读。
-1
如果没有更多的数据,因为已到达流的末尾。
null
b
NullPointerException
。
IndexOutOfBoundsException
-如果
off
是负的,
len
是负的,或
len
大于
b.length - off
IOException
如果输入流被调用其
close()
方法关闭,或发生I/O错误。
InputStream.read(byte[], int, int)
public void unread(int b) throws IOException
(byte)b
。
b
-
int
值的低位字节是被推了回来。
IOException
-如果没有足够的空间在后推缓冲字节输入流,或被调用其
close()
方法封闭。
public void unread(byte[] b, int off, int len) throws IOException
b[off]
,字节后,将有价值
b[off+1]
,等等。
b
-推后的字节数组。
off
的起始偏移量的数据。
len
-字节数推回去。
IOException
-如果没有足够的空间在后推缓冲区指定的字节数,或输入流被调用方法的
close()
封闭。
public void unread(byte[] b) throws IOException
b[0]
,字节后,将有价值
b[1]
,等等。
b
-推后的字节数组
IOException
-如果没有足够的空间在后推缓冲区指定的字节数,或输入流被调用方法的
close()
封闭。
public int available() throws IOException
该方法返回的已推后,返回的值available
字节数的总和。
available
方法重写,继承类
FilterInputStream
IOException
如果输入流被调用其
close()
方法关闭,或发生I/O错误。
FilterInputStream.in
,
InputStream.available()
public long skip(long n) throws IOException
n
字节从输入流中的数据。
skip
方法的可能,因为种种原因,最终跳过一些较小的字节数,可能为零。如果
n
是负的,没有跳过的字节。
在后推缓冲字节PushbackInputStream
第一跳skip
方法,如果任何。然后调用底层输入流的skip
方法如果需要跳过的字节。跳过的字节数实际返回。
skip
方法重写,继承类
FilterInputStream
n
-字节数被跳过。
IOException
如果流不支持查找,或流已经通过调用其
close()
方法关闭,或发生I/O错误。
FilterInputStream.in
,
InputStream.skip(long n)
public boolean markSupported()
mark
和
reset
方法,它不。
markSupported
方法重写,继承类
FilterInputStream
false
,由于这类不支持
mark
和
reset
方法。
InputStream.mark(int)
,
InputStream.reset()
public void mark(int readlimit)
对PushbackInputStream
的mark
方法不。
mark
方法重写,继承类
FilterInputStream
readlimit
-字节可以在标记位置无效阅读最大限度。
InputStream.reset()
public void reset() throws IOException
mark
方法的位置上呼吁这个输入流。
类的方法PushbackInputStream
reset
仅仅抛出一个IOException
。
reset
方法重写,继承类
FilterInputStream
IOException
。
InputStream.mark(int)
,
IOException
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.