codecamp

鸿蒙OS PipedOutputStream

PipedOutputStream

java.lang.Object

|---java.io.OutputStream

|---|---java.io.PipedOutputStream

public class PipedOutputStream
extends OutputStream

管道输出流可以连接到管道输入流以创建通信管道。 管道输出流是管道的发送端。 通常,数据由一个线程写入 PipedOutputStream 对象,数据由其他线程从连接的 PipedInputStream 读取。 不建议尝试从单个线程中使用这两个对象,因为它可能会使线程死锁。 如果从连接的管道输入流中读取数据字节的线程不再活动,则称该管道已损坏。

Since:

JDK1.0

构造函数摘要

构造函数 描述
PipedOutputStream() 创建尚未连接到管道输入流的管道输出流。
PipedOutputStream(PipedInputStream snk) 创建连接到指定管道输入流的管道输出流。

方法总结

修饰符和类型 方法 描述
void close() 关闭此管道输出流并释放与此流关联的任何系统资源。
void connect(PipedInputStream snk) 将此管道输出流连接到接收器。
void flush() 刷新此输出流并强制写出任何缓冲的输出字节。
void write(byte[] b, int off, int len) 将指定字节数组中的 len 个字节从偏移量 off 处开始写入此管道输出流。
void write(int b) 将指定的字节写入管道输出流。
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
从类 java.io.OutputStream 继承的方法
write

构造函数详细信息

PipedOutputStream

public PipedOutputStream(PipedInputStream snk) throws IOException

创建连接到指定管道输入流的管道输出流。 写入此流的数据字节将作为 snk 的输入提供。

参数:

参数名称 参数描述
snk 要连接的管道输入流。

Throws:

Throw名称 Throw描述
IOException 如果发生 I/O 错误。

PipedOutputStream

public PipedOutputStream()

创建尚未连接到管道输入流的管道输出流。 在使用之前,它必须由接收方或发送方连接到管道输入流。

方法详情

connect

public void connect(PipedInputStream snk) throws IOException

将此管道输出流连接到接收器。 如果此对象已连接到其他管道输入流,则会引发 IOException。

如果 snk 是未连接的管道输入流并且 src 是未连接的管道输出流,则它们可以通过以下任一调用连接:

 src.connect(snk)

或调用:

 snk.connect(src)

这两个调用具有相同的效果。

参数:

参数名称 参数描述
snk 要连接的管道输入流。

Throws:

Throw名称 Throw描述
IOException 如果发生 I/O 错误。

write

public void write(int b) throws IOException

将指定的字节写入管道输出流。

实现OutputStream的write方法。

指定者:

写在类 OutputStream

参数:

参数名称 参数描述
b 要写入的字节。

Throws:

Throw名称 Throw描述
IOException 如果管道损坏、未连接、关闭或发生 I/O 错误。

write

public void write(byte[] b, int off, int len) throws IOException

将指定字节数组中的 len 个字节从偏移量 off 处开始写入此管道输出流。 此方法阻塞,直到所有字节都写入输出流。

覆盖:

写在类 OutputStream

参数:

参数名称 参数描述
b 数据。
off 数据中的起始偏移量。
len 要写入的字节数。

Throws:

Throw名称 Throw描述
IOException 如果管道损坏、未连接、关闭或发生 I/O 错误。

flush

public void flush() throws IOException

刷新此输出流并强制写出任何缓冲的输出字节。 这将通知任何读者字节正在管道中等待。

指定者:

在接口 Flushable 中刷新

覆盖:

类 OutputStream 中的刷新

Throws:

Throw名称 Throw描述
IOException 如果发生 I/O 错误。

close

public void close() throws IOException

关闭此管道输出流并释放与此流关联的任何系统资源。 此流可能不再用于写入字节。

指定者:

在接口 AutoCloseable 中关闭

指定者:

在接口Closeable中关闭

覆盖:

在类 OutputStream 中关闭

Throws:

Throw名称 Throw描述
IOException 如果发生 I/O 错误。
鸿蒙OS PipedInputStream
鸿蒙OS PipedReader
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

鸿蒙OS 开发

鸿蒙OS 术语

鸿蒙OS Java API参考

鸿蒙OS ohos.aafwk.ability

鸿蒙OS ohos.aafwk.abilityjet.activedata

鸿蒙OS ohos.aafwk.content

鸿蒙OS java.lang

鸿蒙OS java.Util

鸿蒙OS java.Util class

鸿蒙OS ohos.data.dataability

鸿蒙OS ohos.data.dataability class

鸿蒙OS ohos.agp.components

鸿蒙OS ohos.agp.components interface

鸿蒙OS ohos.agp.components class

鸿蒙OS ohos.global.configuration

鸿蒙OS java.io

鸿蒙OS ohos.data.resultset

鸿蒙OS ohos.data.resultset interface

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }