PushbackReader
public class PushbackReader
extends FilterReader
字符流阅读器,允许将字符推回到流中。
Summary
Public methods |
void |
close() 关闭流并释放与其关联的所有系统资源。 |
void |
mark(int readAheadLimit) 标记流中的当前位置。 |
boolean |
markSupported() 告诉这个流是否支持mark()操作,而不支持。 |
int |
read() 读取一个字符。 |
int |
read(char[] cbuf, int off, int len) 将字符读入数组的一部分。 |
boolean |
ready() 告诉这个流是否准备好被读取。 |
void |
reset() 重置流。 |
long |
skip(long n) 跳过字符。 |
void |
unread(char[] cbuf, int off, int len) 通过将字符数组的一部分复制到推回缓冲区的前面来推回部分字符。 |
void |
unread(char[] cbuf) 通过将字符数组复制到推回缓冲区的前面来推回字符数组。 |
void |
unread(int c) 通过将单个字符复制到推回缓冲区的前面来推回单个字符。 |
Public constructors
PushbackReader
PushbackReader (Reader in,
int size)
使用给定大小的推送缓冲区创建新的推回阅读器。
Parameters |
in |
Reader : The reader from which characters will be read |
size |
int : The size of the pushback buffer |
PushbackReader
PushbackReader (Reader in)
使用单字符后推缓冲区创建新的推回式阅读器。
Parameters |
in |
Reader : The reader from which characters will be read |
Public methods
close
void close ()
关闭流并释放与其关联的所有系统资源。 一旦流被关闭,进一步的read(),unread(),ready()或skip()调用将抛出IOException异常。 关闭以前关闭的流不起作用。
mark
void mark (int readAheadLimit)
标记流中的当前位置。 该mark
类PushbackReader
总是抛出异常。
Parameters |
readAheadLimit |
int : Limit on the number of characters that may be read while still preserving the mark. After reading this many characters, attempting to reset the stream may fail. |
markSupported
boolean markSupported ()
告诉这个流是否支持mark()操作,而不支持。
Returns |
boolean |
true if and only if this stream supports the mark operation. |
read
int read ()
读取一个字符。
Returns |
int |
The character read, or -1 if the end of the stream has been reached |
read
int read (char[] cbuf,
int off,
int len)
将字符读入数组的一部分。
Parameters |
cbuf |
char : Destination buffer |
off |
int : Offset at which to start writing characters |
len |
int : Maximum number of characters to read |
Returns |
int |
The number of characters read, or -1 if the end of the stream has been reached |
ready
boolean ready ()
告诉这个流是否准备好被读取。
Returns |
boolean |
True if the next read() is guaranteed not to block for input, false otherwise. Note that returning false does not guarantee that the next read will block. |
reset
void reset ()
重置流。 该reset
的方法PushbackReader
总是抛出异常。
Throws |
IOException |
Always, since reset is not supported |
skip
long skip (long n)
跳过字符。 此方法将阻塞,直到某些字符可用,发生I / O错误或到达流的末尾。
Parameters |
n |
long : The number of characters to skip |
Returns |
long |
The number of characters actually skipped |
unread
void unread (char[] cbuf,
int off,
int len)
通过将字符数组的一部分复制到推回缓冲区的前面来推回部分字符。 在此方法返回后,要读取的下一个字符将具有值cbuf[off]
,之后的字符将具有值cbuf[off+1]
,等等。
Parameters |
cbuf |
char : Character array |
off |
int : Offset of first character to push back |
len |
int : Number of characters to push back |
Throws |
IOException |
If there is insufficient room in the pushback buffer, or if some other I/O error occurs |
unread
void unread (char[] cbuf)
通过将字符数组复制到推回缓冲区的前面来推回字符数组。 在此方法返回后,要读取的下一个字符将具有值cbuf[0]
,之后的字符将具有值cbuf[1]
,等等。
Parameters |
cbuf |
char : Character array to push back |
Throws |
IOException |
If there is insufficient room in the pushback buffer, or if some other I/O error occurs |
unread
void unread (int c)
通过将单个字符复制到推回缓冲区的前面来推回单个字符。 此方法返回后,要读取的下一个字符将具有值(char)c
。
Parameters |
c |
int : The int value representing a character to be pushed back |
Throws |
IOException |
If the pushback buffer is full, or if some other I/O error occurs |