對象BufferedStream
緩存讀取對象
BufferedReader 對像用於對二進制流對像數據進行緩存,並提供文本讀取能力,僅支持utf-8 格式轉換。創建方法:
1var reader = new io.BufferedStream(stream);
繼承關係
構造函數
BufferedStream
BufferedStream 構造函數
1new BufferedStream(Stream stm);
調用參數:
- stm: Stream, BufferedStream 的二進制基礎流對象
成員屬性
stream
Stream, 查詢創建緩存對象時的流對象
1readonly Stream BufferedStream.stream;
charset
String, 查詢和設置當前對象處理文本時的字符集,缺省為utf-8
1String BufferedStream.charset;
EOL
String, 查詢和設置行結尾標識,缺省時,posix:\"\n\";windows:\"\r\n\"
1String BufferedStream.EOL;
fd
Integer, 查詢 Stream 對應的文件描述符值, 由子類實現
1readonly Integer BufferedStream.fd;
成員函數
readText
讀取指定字符的文本
1String BufferedStream.readText(Integer size) async;
調用參數:
- size: Integer, 指定讀取的文本字符個數,以utf8 或者指定的編碼字節數為準
返回結果:
- String, 返回讀取的文本字符串,若無數據可讀,或者連接中斷,則返回null
readLine
讀取一行文本,行結尾標識基於EOL 屬性的設置,缺省時,posix:\"\n\";windows:\"\r\n\"
1String BufferedStream.readLine(Integer maxlen = -1) async;
調用參數:
- maxlen: Integer, 指定此次讀取的最大字符串,以utf8 編碼字節數為準,缺省不限製字符數
返回結果:
- String, 返回讀取的文本字符串,若無數據可讀,或者連接中斷,則返回null
readLines
以數組方式讀取一組文本行,行結尾標識基於EOL 屬性的設置,缺省時,posix:\"\n\";windows:\"\r\n\"
1Array BufferedStream.readLines(Integer maxlines = -1);
調用參數:
- maxlines: Integer, 指定此次讀取的最大行數,缺省讀取全部文本行
返回結果:
- Array, 返回讀取的文本行數組,若無數據可讀,或者連接中斷,空數組
readUntil
讀取一個文本字符串,以指定的字節為結尾
1
2String BufferedStream.readUntil(String mk,
Integer maxlen = -1) async;
調用參數:
- mk: String, 指定結尾的字符串
- maxlen: Integer, 指定此次讀取的最大字符串,以utf8 編碼字節數為準,缺省不限製字符數
返回結果:
- String, 返回讀取的文本字符串,若無數據可讀,或者連接中斷,則返回null
writeText
寫入一個字符串
1BufferedStream.writeText(String txt) async;
調用參數:
- txt: String, 指定寫入的字符串
writeLine
寫入一個字符串,並寫入換行符
1BufferedStream.writeLine(String txt) async;
調用參數:
- txt: String, 指定寫入的字符串
read
從流內讀取指定大小的數據
1Buffer BufferedStream.read(Integer bytes = -1) async;
調用參數:
- bytes: Integer, 指定要讀取的數據量,缺省為讀取隨機大小的數據塊,讀出的數據尺寸取決於設備
返回結果:
- Buffer, 返回從流內讀取的數據,若無數據可讀,或者連接中斷,則返回null
write
將給定的數據寫入流
1BufferedStream.write(Buffer data) async;
調用參數:
- data: Buffer, 給定要寫入的數據
flush
將文件緩衝區內容寫入物理設備
1BufferedStream.flush() async;
close
關閉當前流對象
1BufferedStream.close() async;
copyTo
複製流數據到目標流中
1
2Long BufferedStream.copyTo(Stream stm,
Long bytes = -1) async;
調用參數:
- stm: Stream, 目標流對象
- bytes: Long, 複製的字節數
返回結果:
- Long, 返回複製的字節數
toString
返回對象的字符串表示,一般返回"[Native Object]",對象可以根據自己的特性重新實現
1String BufferedStream.toString();
返回結果:
- String, 返回對象的字符串表示
toJSON
返回對象的JSON 格式表示,一般返回對象定義的可讀屬性集合
1Value BufferedStream.toJSON(String key = "");
調用參數:
- key: String, 未使用
返回結果:
- Value, 返回包含可JSON 序列化的值