|
JavaTM 2 Platform Standard Ed. 5.0 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
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(PipedOutputStream src)
创建 PipedInputStream,以使其连接到传送输出流 src。 |
|
| 方法摘要 | |
|---|---|
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)
接收数据字节。 |
| 从类 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()
PipedInputStream。必须在使用之前将其连接到 PipedOutputStream。
connect(java.io.PipedOutputStream),
PipedOutputStream.connect(java.io.PipedInputStream)| 方法详细信息 |
|---|
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 - 如果传送管道损坏。
public int read()
throws IOException
0 到 255 范围内的 int 字节值。如果因流的末尾已到达而没有可用的字节,则返回值 -1。在输入数据可用、检测到流的末尾或者抛出异常前,此方法一直阻塞。如果某个线程正向连接的传送输出流提供数据字节,但该线程不再处于活动状态,则抛出 IOException。
InputStream 中的 read-1。
IOException - 如果传输管道损坏。
public int read(byte[] b,
int off,
int len)
throws IOException
len 个数据字节从此传送输入流读入字节数组。如果已到达数据流的末尾,则读取的字节数少于 len。在至少一个输入字节可用前,此方法一直阻塞。如果某个线程正向连接的传送输出流提供数据字节,但该线程不再处于活动状态,则抛出 IOException。
InputStream 中的 readb - 读入数据的缓冲区。off - 数据的初始偏移量。len - 读取的最多字节数。
-1。
IOException - 如果发生 I/O 错误。InputStream.read()
public int available()
throws IOException
available 方法。
InputStream 中的 availableIOException - 如果发生 I/O 错误。
public void close()
throws IOException
Closeable 中的 closeInputStream 中的 closeIOException - 如果发生 I/O 错误。
|
JavaTM 2 Platform Standard Ed. 5.0 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2004 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。