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.pswp.cn/news/542042.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/542042.shtml
英文地址,請注明出處:http://en.pswp.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;并提供靈活的通知機制以讓系統管理員快速定位/解決…