public class PipedOutputStream
extends OutputStream
| java.lang.Object | ||
| ↳ | java.io.OutputStream | |
| ↳ | java.io.PipedOutputStream | |
管道输出流可以连接到管道输入流以创建通信管道。 管道输出流是管道的发送端。 通常,数据通过一个线程写入PipedOutputStream对象,并通过其他线程从连接的PipedInputStream读取数据。 不建议尝试使用来自单个线程的两个对象,因为它可能导致线程死锁。 如果从连接的管道输入流中读取数据字节的线程不再有效,则该管道被称为broken 。
也可以看看:
Public constructors |
|
|---|---|
PipedOutputStream(PipedInputStream snk) 创建连接到指定的管道输入流的管道输出流。 |
|
PipedOutputStream() 创建尚未连接到管道输入流的管道输出流。 |
|
Public methods |
|
|---|---|
void |
close() 关闭此管道输出流并释放与此流关联的所有系统资源。 |
void |
connect(PipedInputStream snk) 将此管道输出流连接到接收器。 |
void |
flush() 刷新此输出流并强制写出所有缓冲的输出字节。 |
void |
write(byte[] b, int off, int len) 将 |
void |
write(int b) 将指定的 |
Inherited methods |
|
|---|---|
java.io.OutputStream
|
|
java.lang.Object
|
|
java.io.Closeable
|
|
java.io.Flushable
|
|
java.lang.AutoCloseable
|
|
PipedOutputStream (PipedInputStream snk)
创建连接到指定的管道输入流的管道输出流。 写入该流的数据字节将作为snk输入snk 。
| Parameters | |
|---|---|
snk |
PipedInputStream: The piped input stream to connect to. |
| Throws | |
|---|---|
IOException |
if an I/O error occurs. |
PipedOutputStream ()
创建尚未连接到管道输入流的管道输出流。 在使用之前,它必须连接到接收器或发送器的管道输入流。
void close ()
关闭此管道输出流并释放与此流关联的所有系统资源。 此流可能不再用于写入字节。
| Throws | |
|---|---|
IOException |
if an I/O error occurs. |
void connect (PipedInputStream snk)
将此管道输出流连接到接收器。 如果此对象已连接到某个其他管道输入流, IOException引发IOException 。
如果 snk是未连接的管道输入流,并且 src是未连接的管道输出流,则它们可以通过以下任一方式进行连接:
or the call:src.connect(snk)
The two calls have the same effect.snk.connect(src)
| Parameters | |
|---|---|
snk |
PipedInputStream: the piped input stream to connect to. |
| Throws | |
|---|---|
IOException |
if an I/O error occurs. |
void flush ()
刷新此输出流并强制写出所有缓冲的输出字节。 这将通知任何阅读器字节在管道中等待。
| Throws | |
|---|---|
IOException |
if an I/O error occurs. |
void write (byte[] b,
int off,
int len)
将从偏移量off开始的指定字节数组中的len个字节写入此管道输出流。 此方法阻塞,直到所有字节写入输出流。
| Parameters | |
|---|---|
b |
byte: the data. |
off |
int: the start offset in the data. |
len |
int: the number of bytes to write. |
| Throws | |
|---|---|
IOException |
if the pipe is broken, unconnected, closed, or if an I/O error occurs. |
void write (int b)
将指定的 byte写入管道输出流。
实现 write方法 OutputStream 。
| Parameters | |
|---|---|
b |
int: the byte to be written. |
| Throws | |
|---|---|
IOException |
if the pipe is broken, unconnected, closed, or if an I/O error occurs. |