|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjava.io.InputStream
java.io.PipedInputStream
public class PipedInputStream
管道输入流应该连接到管道输出流;管道输入流提供要写入管道输出流的所有数据字节。通常,数据由某个线程从
PipedInputStream 对象读取,并由其他线程将其写入到相应的 PipedOutputStream。不建议对这两个对象尝试使用单个线程,因为这样可能死锁线程。管道输入流包含一个缓冲区,可在缓冲区限定的范围内将读操作和写操作分离开。
如果向连接管道输出流提供数据字节的线程不再存在,则认为该管道已损坏。
PipedOutputStream
| 字段摘要 | |
|---|---|
protected byte[] |
buffer
放置传入数据的循环缓冲区。 |
protected int |
in
循环缓冲区中位置的索引,当从连接的管道输出流中接收到下一个数据字节时,会将其存储到该位置。 |
protected int |
out
循环缓冲区中位置的索引,此管道输入流将从该位置读取下一个数据字节。 |
protected static int |
PIPE_SIZE
管道循环输入缓冲区的默认大小。 |
| 构造方法摘要 | |
|---|---|
PipedInputStream()
创建尚未连接的 PipedInputStream。 |
|
PipedInputStream(int pipeSize)
创建一个尚未连接的 PipedInputStream,并对管道缓冲区使用指定的管道大小。 |
|
PipedInputStream(PipedOutputStream src)
创建 PipedInputStream,使其连接到管道输出流 src。 |
|
PipedInputStream(PipedOutputStream src,
int pipeSize)
创建一个 PipedInputStream,使其连接到管道输出流 src,并对管道缓冲区使用指定的管道大小。 |
|
| 方法摘要 | |
|---|---|
int |
available()
返回可以不受阻塞地从此输入流中读取的字节数。 |
void |
close()
关闭此管道输入流并释放与该流相关的所有系统资源。 |
void |
connect(PipedOutputStream src)
使此管道输入流连接到管道输出流 src。 |
int |
read()
读取此管道输入流中的下一个数据字节。 |
int |
read(byte[] b,
int off,
int len)
将最多 len 个数据字节从此管道输入流读入 byte 数组。 |
protected void |
receive(int b)
接收数据字节。 |
| 从类 java.io.InputStream 继承的方法 |
|---|
mark, markSupported, read, reset, skip |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 字段详细信息 |
|---|
protected 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()
PipedInputStream。在使用前必须将其连接到 PipedOutputStream。
public PipedInputStream(int pipeSize)
PipedInputStream,并对管道缓冲区使用指定的管道大小。在使用前必须将其连接到 PipedOutputStream。
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 - 如果管道损坏、未连接、关闭,或者发生 I/O 错误。
public int read()
throws IOException
0 到 255 范围内的 int 字节值。在输入数据可用、检测到流的末尾或者抛出异常前,此方法一直阻塞。
InputStream 中的 read-1。
IOException - 如果管道未连接、损坏、关闭,或者发生 I/O 错误。
public int read(byte[] b,
int off,
int len)
throws IOException
len 个数据字节从此管道输入流读入 byte 数组。如果已到达数据流的末尾,或者 len 超出管道缓冲区大小,则读取的字节数将少于 len。如果 len 为 0,则不读取任何字节并返回 0;否则,在至少 1 个输入字节可用、检测到流末尾、抛出异常前,该方法将一直阻塞。
InputStream 中的 readb - 读入数据的缓冲区。off - 目标数组 b 中的初始偏移量。len - 读取的最多字节数。
-1。
NullPointerException - 如果 b 为 null。
IndexOutOfBoundsException - 如果 off 为负,len 为负,或者 len 大于 b.length - off
IOException - 如果管道损坏、未连接、关闭,或者发生 I/O 错误。InputStream.read()
public int available()
throws IOException
InputStream 中的 availableclose() 方法关闭此输入流、管道未连接或已损坏,则返回 0。
IOException - 如果发生 I/O 错误。
public void close()
throws IOException
Closeable 中的 closeInputStream 中的 closeIOException - 如果发生 I/O 错误。
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。