public class PipedInputStream extends InputStream
PipedInputStream对象由一个线程并且数据被写入到对应的PipedOutputStream通过一些其它线程。
不建议尝试从单个线程使用这两个对象,因为它可能会使线程死锁。
管道输入流包含一个缓冲区,在读取操作中将读取操作与限制内的操作相分离。
的管道被认为是broken如果正在提供的数据字节到连接的管道输出流中的线程不再存活。
PipedOutputStream
| Modifier and Type | Field and Description |
|---|---|
protected byte[] |
buffer
传入数据的循环缓冲区。
|
protected int |
in
在从连接的管道输出流接收到的数据的下一个字节将被存储的循环缓冲区中的位置的索引。
|
protected int |
out
循环缓冲区中的位置的索引,在该缓冲区中下一个字节的数据将被该管道输入流读取。
|
protected static int |
PIPE_SIZE
管道循环输入缓冲区的默认大小。
|
| Constructor and Description |
|---|
PipedInputStream()
创建一个
PipedInputStream ,所以它还不是
connected 。
|
PipedInputStream(int pipeSize)
创建一个
PipedInputStream ,使其尚未
connected ,并使用指定的管道大小作为管道的缓冲区。
|
PipedInputStream(PipedOutputStream src)
创建一个
PipedInputStream ,使其连接到管道输出流
src 。
|
PipedInputStream(PipedOutputStream src, int pipeSize)
创建一个
PipedInputStream ,使其连接到管道输出流
src ,并为管道缓冲区使用指定的管道大小。
|
| Modifier and Type | Method and Description |
|---|---|
int |
available()
返回可以从该输入流读取而不阻塞的字节数。
|
void |
close()
关闭此管道输入流,并释放与流相关联的任何系统资源。
|
void |
connect(PipedOutputStream src)
使此管道输入流连接到管道输出流
src 。
|
int |
read()
从这个管道输入流读取数据的下一个字节。
|
int |
read(byte[] b, int off, int len)
从这个管道输入流读取最多
len个字节的数据到字节数组。
|
protected void |
receive(int b)
接收一个字节的数据。
|
mark, markSupported, read, reset, skipprotected static final int PIPE_SIZE
protected byte[] buffer
protected int in
in<0意味着缓冲区为空, in==out意味着缓冲区已满
protected int out
public PipedInputStream(PipedOutputStream src) throws IOException
PipedInputStream ,使其连接到管道输出流src 。
写入src数据字节将作为此流的输入。
src - 要连接的流。
IOException - 如果发生I / O错误。
public PipedInputStream(PipedOutputStream src, int pipeSize) throws IOException
PipedInputStream ,使其连接到管道输出流src ,并为管道缓冲区使用指定的管道大小。
写入src数据字节将作为此流的输入。
src - 要连接的流。
pipeSize - 管道缓冲区的大小。
IOException - 如果发生I / O错误。
IllegalArgumentException - 如果
pipeSize <= 0 。
public PipedInputStream()
public PipedInputStream(int pipeSize)
pipeSize - 管道缓冲区的大小。
IllegalArgumentException - 如果
pipeSize <= 0 。
public void connect(PipedOutputStream src) throws IOException
src 。
如果此对象已连接到其他管道输出流,则抛出IOException 。
如果src是未连接的管道输出流,并且snk是未连接的管道输入流,则可以通过以下任一方式连接它们:
snk.connect(src)
或电话:
src.connect(snk)
两个电话有相同的效果。
src - 连接到管道输出流。
IOException - 如果发生I / O错误。
protected void receive(int b)
throws IOException
b - 正在接收的字节
IOException -如果管道是
broken ,
unconnected ,关闭,或者如果发生I / O错误。
public int read()
throws IOException
int ,范围为0至255 。
该方法阻塞直到输入数据可用,检测到流的结尾,或抛出异常。
read在
InputStream
-1 。
IOException -如果管道是
unconnected ,
broken ,关闭,或者如果发生I / O错误。
public int read(byte[] b,
int off,
int len)
throws IOException
len字节的数据到字节数组。
如果达到数据流的结尾或len超过管道的缓冲区大小,则读取少于len字节。
如果len为零,则不读取字节并返回0;
否则,该方法将阻塞,直到输入的至少1个字节可用,已经检测到流的结尾,或抛出异常。
read在
InputStream
b - 读取数据的缓冲区。
off - 目标数组
b的起始偏移量
len - 读取的最大字节数。
-1 。
NullPointerException - 如果
b是
null 。
IndexOutOfBoundsException - 如果
off为负,则
len为负数,或
len大于
b.length - off
IOException -如果管道是
broken ,
unconnected ,关闭,或者如果发生I / O错误。
InputStream.read()
public int available()
throws IOException
available在类别
InputStream
0该输入流是否已调用它的关闭
close()方法,或者如果管道是
unconnected ,或
broken 。
IOException - 如果发生I / O错误。
public void close()
throws IOException
close在界面
Closeable
close在界面
AutoCloseable
close在类别
InputStream
IOException - 如果发生I / O错误。
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.