Java PipedInputStream available()方法与示例

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/542042.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

解析xml_Mybatis中mapper的xml解析详解

上一篇文章分析了mapper注解关键类MapperAnnotationBuilder&#xff0c;今天来看mapper的项目了解析关键类XMLMapperBuilder。基础介绍回顾下之前是在分析configuration的初始化过程&#xff0c;已经进行到了最后一步mapperElement(root.evalNode("mappers"))&#x…

lnmp—MemCache的作用

含义及理解&#xff1a; 1 . memcache是一个高性能的分布式的内存对象缓存系统&#xff0c;用于动态web应用以减轻数据库负担。通过在内存里维护一个统一的巨大的hash表&#xff0c;来存储经常被读写的一些数组与文件&#xff0c;从而极大的提高网站的运行效率。 memcache是一…

Java ListResourceBundle getKeys()方法与示例

ListResourceBundle类的getContents()方法 (ListResourceBundle Class getContents() method) getContents() method is available in java.util package. getContents()方法在java.util包中可用。 getContents() method is used to return an enumeration of all the keys tha…

orale用户密码过期处理

使用具有管理权限的用户登录1、查看用户的proifle是哪个&#xff0c;一般是default&#xff1a;SELECT username,PROFILE FROM dba_users;2、查看指定概要文件&#xff08;如default&#xff09;的密码有效期设置&#xff1a;sql>SELECT * FROM dba_profiles s WHERE s.prof…

python字典怎么设置_在python中设置字典中的属性

在python中设置字典中的属性是否可以在python中从字典创建一个对象&#xff0c;使每个键都是该对象的属性&#xff1f;像这样的东西&#xff1a;d { name: Oscar, lastName: Reyes, age:32 }e Employee(d)print e.name # Oscarprint e.age 10 # 42我认为这几乎与这个问题相反…

Java ObjectInputStream readByte()方法与示例

ObjectInputStream类readByte()方法 (ObjectInputStream Class readByte() method) readByte() method is available in java.io package. readByte()方法在java.io包中可用。 readByte() method is used to read a byte (i.e. 8 bit) of data from this ObjectInputStream. re…

openresty—实现缓存前移

含义及理解&#xff1a; OpenResty(又称&#xff1a;ngx_openresty) 是一个基于 NGINX 的可伸缩的 Web 平台&#xff0c;由中国人章亦春发起&#xff0c;提供了很多高质量的第三方模块。 其目标是让Web服务直接跑在Nginx服务内部&#xff0c;充分利用Nginx的非阻塞I/O模型&am…

Nginx+Keepalived+Tomcat之动静分离的web集群

NginxKeepalivedTomcat之动静分离的web集群 博客分类&#xff1a; webserverNginxKeepalivedTomcat之动静分离的web集群为小公司提供大概一天持续在100万/日之间访问的高性能、高可用、高并发访问及动静分离的web集群方案NginxKeepalived 高可用、反向代理NginxPHP …

安装完成后的配置_cent os7 默认安装后的一般配置

在安装cent os7后&#xff0c;进入系统会出现一些命令无法执行。这是因为最小化没有安装包含的软件包。这时候先要配置一下基本的IP参数&#xff0c;(包括动态&#xff0c;静态&#xff0c;或者是双网卡绑定)。我们在虚拟机中模拟操作一下&#xff0c;配置文件在/etc/sysconfig…

Java Integer类lowerOneBit()方法与示例

整数类lowerOneBit()方法 (Integer class lowestOneBit() method) lowestOneBit() method is available in java.lang package. minimumOneBit()方法在java.lang包中可用。 lowestOneBit() method is used to find at most only single 1’s bit from the rightmost side one b…

lnmp构架——对tomcat详解

tomcat的安装部署 安装jdk和tomcat tar zxf jdk-7u79-linux-x64.tar.gz -C /usr/local/ tar zxf apache-tomcat-7.0.37.tar.gz -C /usr/local/做好软连接便于访问 cd /usr/local ln -s jdk1.7.0_79/ java ln -s apache-tomcat-7.0.37/ tomcat配置环境变量 vim /etc/profile…

Linux 查找文件

find 查找目录 -name "文件名"find / -name "php.ini"locate 文件名locate php.ini 一&#xff1a;locate命令 locate命令用于查找文件&#xff0c;它比find命令的搜索速度快&#xff0c;它需要一个数据库&#xff0c;这个数据库由每天的例行工作&#xff…

Java GregorianCalendar hashCode()方法与示例

GregorianCalendar类的hashCode()方法 (GregorianCalendar Class hashCode() method) hashCode() method is available in java.util package. hashCode()方法在java.util包中可用。 hashCode() method is used to returns the hash code for this GregorianCalendar. hashCode…

python元组为什么不可变_为什么python字符串和元组是不可变的?

我不知道为什么字符串和元组是不可变的&#xff1b;使它们不可变的优点和缺点是什么&#xff1f;除了Python解释器的内部实现&#xff0c;这种设计在编写程序上是否有很好的意义&#xff1f;(例如&#xff0c;如果元组和字符串是可变的&#xff0c;会更容易吗&#xff1f;)如果…

InnoDB事务结构体代码变量列表

事务结构 struct trx_t 写在前面 InnoDB是MySQL的一个存储引擎&#xff0c;支持事务&#xff0c;支持非堵塞的一致性读&#xff0c;物理存储结构是Page&#xff0c;每个事务都有回滚日志&#xff0c;重做日志&#xff0c;事务还会有死锁检测&#xff0c;各种各样不同的锁等等等…

对cookie与session的理解

cookie&#xff1a; 在网站中&#xff0c;http请求是无状态的。也就是说即使第一次和服务器连接后并且登录成功后&#xff0c;第二次请求服务器依然不能知道当前请求是哪个用户。 cookie的出现就是为了解决这个问题&#xff0c; 第一次登录后服务器返回一些数据&#xff08;…

ubutun 更换网络源_Ubuntu 更换源

1.切换到root用户# su root备份源文件 目录&#xff1a;/etc/apt# cd /etc/apt/# cp sources.list sources.list.bk3.更换源 阿里源 清华源# >sources.list # 清空源# vim sources.list # 选择一个源&#xff0c;复制进去# apt update # 更新源&#xff0c;需要等几分钟# ex…

php : 常用函数

常用函数&#xff1a; <?php /*** 获取客户端IP* return [string] [description]*/ function getClientIp() {$ip NULL;if (isset($_SERVER[HTTP_X_FORWARDED_FOR])) {$arr explode(,, $_SERVER[HTTP_X_FORWARDED_FOR]);$pos array_search(unknown,$arr);if(false ! $po…

java日历类add方法_Java日历setFirstDayOfWeek()方法与示例

java日历类add方法日历类setFirstDayOfWeek()方法 (Calendar Class setFirstDayOfWeek() method) setFirstDayOfWeek() method is available in java.util package. setFirstDayOfWeek()方法在java.util包中可用。 setFirstDayOfWeek() method is used to sets the first day o…

zabbix监控部署 与添加主机

zabbix介绍&#xff1a; zabbix&#xff08;[zbiks]&#xff09;是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。zabbix能监视各种网络参数&#xff0c;保证服务器系统的安全运营&#xff1b;并提供灵活的通知机制以让系统管理员快速定位/解决…