public class PipedReader
extends Reader
| java.lang.Object | ||
| ↳ | java.io.Reader | |
| ↳ | java.io.PipedReader | |
管道字符输入流。
Inherited fields |
|---|
java.io.Reader
|
Public constructors |
|
|---|---|
PipedReader(PipedWriter src) 创建一个 |
|
PipedReader(PipedWriter src, int pipeSize) 创建一个 |
|
PipedReader() 创建一个 |
|
PipedReader(int pipeSize) 创建一个 |
|
Public methods |
|
|---|---|
void |
close() 关闭此管道流并释放与该流关联的所有系统资源。 |
void |
connect(PipedWriter src) 导致此管道读取器连接到管道 |
int |
read() 从此管道流读取数据的下一个字符。 |
int |
read(char[] cbuf, int off, int len) 将最多 |
boolean |
ready() 判断这个流是否准备好被读取。 |
Inherited methods |
|
|---|---|
java.io.Reader
|
|
java.lang.Object
|
|
java.lang.Readable
|
|
java.io.Closeable
|
|
java.lang.AutoCloseable
|
|
PipedReader (PipedWriter src)
创建一个PipedReader以便它连接到管道src 。 写入src数据将作为此流的输入。
| Parameters | |
|---|---|
src |
PipedWriter: the stream to connect to. |
| Throws | |
|---|---|
IOException |
if an I/O error occurs. |
PipedReader (PipedWriter src, int pipeSize)
创建一个PipedReader以便它连接到管道src并使用管道缓冲区的指定管道大小。 写入src数据将作为此流的输入。
| Parameters | |
|---|---|
src |
PipedWriter: the stream to connect to. |
pipeSize |
int: the size of the pipe's buffer. |
| Throws | |
|---|---|
IOException |
if an I/O error occurs. |
IllegalArgumentException |
if pipeSize <= 0. |
PipedReader ()
创建一个PipedReader以便它尚未connected 。 在使用之前,它必须是connected到PipedWriter 。
PipedReader (int pipeSize)
创建一个PipedReader以便它尚未connected并使用管道缓冲区的指定管道大小。 在使用之前,它必须是connected到PipedWriter 。
| Parameters | |
|---|---|
pipeSize |
int: the size of the pipe's buffer. |
| Throws | |
|---|---|
IllegalArgumentException |
if pipeSize <= 0. |
void close ()
关闭此管道流并释放与该流关联的所有系统资源。
| Throws | |
|---|---|
IOException |
if an I/O error occurs. |
void connect (PipedWriter src)
导致此管道读取器连接到管道src 。 如果此对象已连接到某个其他管道作家, IOException抛出IOException 。
如果 src是未连接的管道 snk器,并且 snk是未连接的管道读取器,则可以通过以下任一方式连接它们:
snk.connect(src)
或电话:
src.connect(snk)
这两个调用具有相同的效果。
| Parameters | |
|---|---|
src |
PipedWriter: The piped writer to connect to. |
| Throws | |
|---|---|
IOException |
if an I/O error occurs. |
int read ()
从此管道流读取数据的下一个字符。 如果由于已到达流的末尾而没有字符可用,则返回值-1 。 此方法阻塞直到输入数据可用,流的末尾被检测到,或抛出异常。
| Returns | |
|---|---|
int |
the next character of data, or -1 if the end of the stream is reached. |
| Throws | |
|---|---|
IOException |
if the pipe is broken, unconnected, closed, or an I/O error occurs. |
int read (char[] cbuf,
int off,
int len)
将最多len字符的数据从此管道流读取到字符数组中。 如果数据流的末尾已达到或者len超过管道的缓冲区大小,将读取少于len字符。 此方法阻塞,直到至少有一个输入字符可用。
| Parameters | |
|---|---|
cbuf |
char: the buffer into which the data is read. |
off |
int: the start offset of the data. |
len |
int: the maximum number of characters read. |
| Returns | |
|---|---|
int |
the total number of characters read into the buffer, or -1 if there is no more data because the end of the stream has been reached. |
| Throws | |
|---|---|
IOException |
if the pipe is broken, unconnected, closed, or an I/O error occurs. |
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. |
| Throws | |
|---|---|
IOException |
if the pipe is broken, unconnected, or closed. |