博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java PipedInputStream receive()方法与示例
阅读量:2527 次
发布时间:2019-05-11

本文共 2401 字,大约阅读时间需要 8 分钟。

PipedInputStream类的receive()方法 (PipedInputStream Class receive() method)

  • receive() method is available in java.io package.

    receive()方法在java.io包中可用。

  • receive() method is used to receive a byte of content and it will block when no more input remains.

    receive()方法用于接收内容的一个字节,当不再有剩余输入时它将阻塞。

  • receive() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    receive()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • receive() method may throw an exception at the time of receiving a byte of data.

    receive()方法在接收到一个字节数据时可能会引发异常。

    IOException: This exception may throw when getting any input/output error or pipe not connected properly, or stream closed.

    IOException :当出现任何输入/输出错误或管道未正确连接或流关闭时,可能引发此异常。

Syntax:

句法:

protected void receive(int byt);

Parameter(s):

参数:

  • int byt – represents the byte getting received.

    int byt –表示要接收的字节。

Return value:

返回值:

The return type of the method is void, it returns nothing.

该方法的返回类型为void ,不返回任何内容。

Example:

例:

// Java program to demonstrate the example // of receive(int byt) method of PipedInputStreamimport java.io.*;public class ReceiveOfPIS extends PipedInputStream {
public static void main(String[] args) throws Exception {
int val = 65; try {
// Instantiates ReceiveOfPIS and // PipedOutputStream ReceiveOfPIS pipe_in = new ReceiveOfPIS(); PipedOutputStream pipe_out = new PipedOutputStream(); // By using connect() method is to // connect this pipe_in to the given pipe_out pipe_in.connect(pipe_out); for (int i = 0; i < 3; ++i) {
// By using write() method is to // write the val to the stream pipe_out pipe_out.write(val); val++; } for (int i = 1; i < 4; ++i) {
// By using receive() method is to // receive a byte pipe_in.receive(val); System.out.println(i + " " + "Byte Received "); } // By using close() method is to close // the stream pipe_in.close(); pipe_out.close(); } catch (Exception ex) {
System.out.println(ex.toString()); } }}

Output

输出量

1 Byte Received 2 Byte Received 3 Byte Received

翻译自:

转载地址:http://eftzd.baihongyu.com/

你可能感兴趣的文章
Go 结构体
查看>>
LINQ巩固
查看>>
观看杨老师(杨旭)Asp.Net Core MVC入门教程记录
查看>>
UIDynamic(物理仿真)
查看>>
P2731 骑马修栅栏 欧拉函数
查看>>
sort函数
查看>>
CentOS-6.3安装配置Nginx
查看>>
女陔说"你不懂我", 到底什么意思
查看>>
uva11149
查看>>
Windows下安装Redis
查看>>
20155339 《信息安全系统设计基础》课程总结
查看>>
javascript 正则表达式学习
查看>>
ASCII代码 简介
查看>>
SSL协议之数据加密过程详解
查看>>
详解C# 匿名对象(匿名类型)、var、动态类型 dynamic
查看>>
centos7 开放端口
查看>>
迷宫实现
查看>>
如何使用Transact-SQL进行事务处理[示例]
查看>>
选择JSF不选Struts的十大理由
查看>>
01-编写CMS注意事项
查看>>