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

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

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

  • available() method is used to return the number of available bytes left that can be read from this PipedInputStream without blocking.

    available()方法用于返回可以从此PipedInputStream读取而不会阻塞的剩余可用字节数。

  • available() 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.

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

  • available() method may throw an exception at the time of returning the available bytes left.

    在返回剩余的可用字节时, available()方法可能会引发异常。

    IOException: This exception may throw when getting any input/output error while performing.

    IOException :在执行过程中遇到任何输入/输出错误时,可能引发此异常。

Syntax:

句法:

    public int available();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of the method is int, it returns the number of available bytes that can be read without blocking as it may return 0 when this stream closed by using the close() method.

方法的返回类型为int ,它返回可以读取而不会阻塞的可用字节数,因为当使用close()方法关闭此流时,它可能返回0。

Example:

例:

// Java program to demonstrate the example
// of int available() method
// of PipedInputStream
import java.io.*;
public class AvailableOfPIS {public static void main(String[] args) throws Exception {int val = 65;
try {// Instantiates PipedInputStream and
// PipedOutputStream
PipedInputStream pipe_in = new PipedInputStream();
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++;
}
// By using available() method is to return
// the available bytes to be read
int avail_bytes = pipe_in.available();
System.out.println("pipe_in.available(): " + avail_bytes);
for (int i = 0; i < 3; ++i) {// By using read() method is to
// read the integer and convert it into
// char
char ch = (char) pipe_in.read();
System.out.println("pipe_in.read(): " + ch);
}
// By using close() method is to close
// the stream
pipe_in.close();
pipe_out.close();
} catch (Exception ex) {System.out.println(ex.toString());
}
}
}

Output

输出量

pipe_in.available(): 3
pipe_in.read(): A
pipe_in.read(): B
pipe_in.read(): C

翻译自: https://www.includehelp.com/java/pipedinputstream-available-method-with-example.aspx

Java PipedInputStream available()方法与示例相关推荐

  1. Java IOUtils.copy方法代码示例(亲测)

    本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...

  2. java receive_Java PipedInputStream receive()方法与示例

    PipedInputStream类receive()方法receive()方法在java.io包中可用. receive()方法用于接收内容的一个字节,当不再有剩余输入时它将阻塞. receive() ...

  3. java user directory,Java ProcessBuilder directory()方法与示例

    语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...

  4. Java序列化魔术方法及其示例使用

    在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...

  5. catalog java,Java Connection getCatalog()方法与示例

    通常,目录是一个目录,其中包含有关数据集,文件或数据库的信息.而数据库目录中包含所有数据库,基本表,视图(虚拟表),同义词,值范围,索引,用户和用户组的列表. Connection接口的getCata ...

  6. filepermission java,Java FilePermission getActions()方法与示例

    FilePermission类getActions()方法getActions()方法在java.io包中可用. getActions()方法用于检查此FilePermission和给定对象在路径名和 ...

  7. java方法参数Bundle,Java ResourceBundle keySet()方法及示例

    ResourceBundle类keySet()方法keySet()方法在java.util包中可用. keySet()方法用于从此ResourceBundle及其超级捆绑包中获取所有现有键,以在Set ...

  8. java exec waitfor,Java Process waitFor()方法与示例

    流程类waitFor()方法在java.lang包中提供了waitFor()方法. waitFor()方法用于使当前正在运行的线程在需要时等待,直到由该Process对象表示的进程完成其终止为止. 当 ...

  9. java arraylist.add(),Java ArrayList add()方法与示例

    ArrayList类add()方法 语法:public boolean add(T ele); public void add(int indices, T ele);add()方法在java.uti ...

  10. java rollback用法,Java Connection rollBack()方法与示例

    回滚操作将撤消当前事务所做的所有更改,即,如果调用Connection接口的rollBack()方法,则所有修改都将还原到最后一次提交. 您还可以通过将所需的Savepoint对象作为参数传递给此方法 ...

最新文章

  1. 【深度学习】(5) 简单网络,案例:服装图片分类,附python完整代码
  2. css -- 运用@media实现网页自适应中的几个关键分辨率
  3. 记录一次与大神们的关于GAN应用于NLP的讨论
  4. Mint-ui中loadmore(上拉加载下拉刷新)组件在ios中滑动会触发点击事件的解决方法...
  5. JavaScript0-闭包
  6. C语言---输出三角形字符阵列
  7. Codeforces Round #459 (Div. 2)题解
  8. linux环境知识点备忘录
  9. exe反编译为py文件
  10. CPCI总线和VPX总线的区别
  11. 软件工程 网络工程,职业方向是怎样的?选择之前一定要了解!
  12. 盘点2009:Office办公软件谁主江湖
  13. Java8 处理日期和时间
  14. ★思维导图的30个问答
  15. Java 爬取微信公众号文章(文字 + 图片)
  16. 如何用计算机制作动态图,怎么制作Gif动画?用电脑制作Gif动图
  17. java习题7参考练习及答案_Java基础练习题及详细答案
  18. AD18学习之画PCB时,如何移动器件同时导线跟随
  19. 洛谷P1462 通往奥格瑞玛的道路 题解
  20. Google人脸识别系统Facenet paper解析

热门文章

  1. 使用未初始化的内存是什么意思_他们都说JVM能实际使用的内存比-Xmx指定的少?这是为什么呢...
  2. freemark循环map_java与freemarker遍历map
  3. 计算机休眠怎么唤醒,电脑休眠后,就无法唤醒了?怎么办?快速教你解决这个问题...
  4. mysql居左查询abcd_MySql速查手册
  5. mysql无法添加或更新子行_违反完整性约束:1452无法添加或更新子行:
  6. php引号变量_下列PHP数据库insert语句中变量前后的点和双引号有什么作用?
  7. python合并多个pdf_python合并多个pdf文件
  8. 生成一个GitHub的token用于git推送本地库至远程库
  9. Angular之jwt令牌身份验证
  10. timeshift备份你的Linux系统