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错误发生。
pipeSize <= 0
IllegalArgumentException。
public PipedInputStream()
public PipedInputStream(int pipeSize)
pipeSize -管道的缓冲区的大小。
pipeSize <= 0
IllegalArgumentException。
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
0一
int到
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如果没有更多的数据,因为已到达流的末尾。
null
b
NullPointerException。
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.