public class BufferedInputStream<T> <: InputStream where T <: InputStream {
public init(input: T)
public init(input: T, buffer: Array<Byte>)
public init(input: T, capacity: Int64)
} 功能:提供带缓冲区的输入流。
可将其他 InputStream 类型的输入流(如 ByteArrayStream)绑定到 BufferedInputStream 实例,从该实例读取数据时,先把数据从被绑定的流读入缓冲区暂存,再从缓冲区读取用户需要的数据。
public init(input: T)
功能:创建 BufferedInputStream 实例,缓冲区容量取默认值 4096。
参数:
public init(input: T, buffer: Array<Byte>)
功能:创建 BufferedInputStream 实例。
其内部使用的缓存区由入参决定,在注重性能的场景下,通过复用传入的 buffer,可以减少内存分配次数,提高性能。
参数:
异常:
public init(input: T, capacity: Int64)
功能:创建 BufferedInputStream 实例。
参数:
异常:
public func read(buffer: Array<Byte>): Int64
功能:从绑定的输入流读出数据到 buffer 中。
参数:
返回值:
异常:
public func reset(input: T): Unit
功能:绑定新的输入流,重置状态,但不重置 capacity。
参数:
func close()
public func close(): Unit
功能:关闭当前流。
func isClosed()
public func isClosed(): Bool
功能:判断当前流是否关闭。
返回值:
prop length
public prop length: Int64
功能:返回当前流中的总数据量。
类型:Int64
prop position
public prop position: Int64
功能:返回当前光标位置。
类型:Int64
prop remainLength
public prop remainLength: Int64
功能:返回当前流中未读的数据量。
类型:Int64
func seek(SeekPosition)
public func seek(sp: SeekPosition): Int64
功能:移动光标到指定的位置。
参数:
返回值:
public class BufferedOutputStream<T> <: OutputStream where T <: OutputStream {
public init(output: T)
public init(output: T, buffer: Array<Byte>)
public init(output: T, capacity: Int64)
} 功能:提供带缓冲区的输出流。
可将其他 OutputStream 类型的输入流(如 ByteArrayStream)绑定到 BufferedOutputStream 实例,从该实例写入数据时,先把数据写入缓冲区暂存,再从缓冲区写入数据到流中。
public init(output: T)
功能:创建 BufferedOutputStream 实例,缓冲区容量取默认值 4096。
参数:
public init(output: T, buffer: Array<Byte>)
功能:创建 BufferedOutputStream 实例。
其内部使用的缓存区由入参决定,在注重性能的场景下,通过复用传入的 buffer,可以减少内存分配次数,提高性能。
参数:
异常:
public init(output: T, capacity: Int64)
功能:创建 BufferedOutputStream 实例。
参数:
异常:
public func flush(): Unit
功能:刷新 BufferedOutputStream:将内部缓冲区的剩余数据写入绑定的输出流,并刷新 BufferedOutputStream。
public func reset(output: T): Unit
功能:绑定新的输出流,重置状态,但不重置 capacity。
参数:
public func write(buffer: Array<Byte>): Unit
功能:将 buffer 中的数据写入到绑定的输出流中。
参数:
func close()
public func close(): Unit
功能:关闭当前流。
func isClosed()
public func isClosed(): Bool
功能:判断当前流是否关闭。
返回值:
prop length
public prop length: Int64
功能:返回当前流中的总数据量。
类型:Int64
prop position
public prop position: Int64
功能:返回当前光标位置。
类型:Int64
prop remainLength
public prop remainLength: Int64
功能:返回当前流中未读的数据量。
类型:Int64
func seek(SeekPosition)
public func seek(sp: SeekPosition): Int64
功能:移动光标到指定的位置。
参数:
返回值:
public class ByteArrayStream <: IOStream & Seekable {
public init()
public init(capacity: Int64)
} public init(capacity: Int64)
功能:创建 ByteArrayStream 实例。
参数:
异常:
public static func fromString(data: String): ByteArrayStream
功能:通过 String 类型构造一个 ByteArrayStream。
参数:
返回值:
public func bytes(): Array<Byte>
功能:获取当前 ByteArrayStream 中未被读取的数据的切片。
返回值:
public func clone(): ByteArrayStream
功能:用当前 ByteArrayStream 中的数据来构造一个新的 ByteArrayStream。
返回值:
public func copyTo(output: OutputStream): Unit
功能:将当前 ByteArrayStream 中未被读取的所有数据拷贝到 output 流中。
参数:
public func read(buffer: Array<Byte>): Int64
功能:从输入流中读取数据放到 buffer 中。
参数:
返回值:
异常:
public func readString(): String
功能:读取流中的剩余数据,并转换为 String 类型,做 UTF-8 编码检查。
返回值:
异常:
public unsafe func readStringUnchecked(): String
功能:读取流中的剩余数据,并转换为 String 类型,不做 UTF-8 编码检查。
返回值:
public func reserve(additional: Int64): Unit
功能:将缓冲区扩容指定大小。
参数:
异常:
public func seek(sp: SeekPosition): Int64
功能:将光标跳转到指定位置。
参数:
返回值:
异常:
public func write(buffer: Array<Byte>): Unit
功能:将 buffer 中的数据写入到输出流中。
参数:
异常:
public class ChainedInputStream<T> <: InputStream where T <: InputStream {
public init(input: Array<T>)
} 功能:提供顺序从 InputStream 数组中读取数据的能力。
public init(input: Array<T>)
功能:创建 ChainedInputStream 实例。
参数:
异常:
public func read(buffer: Array<Byte>): Int64
功能:依次从绑定 InputStream 数组中读出数据到 buffer 中。
参数:
返回值:
异常:
public class MultiOutputStream<T> <: OutputStream where T <: OutputStream {
public init(output: Array<T>)
} 功能:提供将数据同时写入到 OutputStream 数组中每个输出流中的能力。
public init(output: Array<T>)
功能:创建 MultiOutputStream 实例。
参数:
异常:
public func write(buffer: Array<Byte>): Unit
功能:将 buffer 同时写入到绑定的 OutputStream 数组里的每个输出流中。
参数:
public class StringReader<T> where T <: InputStream {
public init(input: T)
} 功能:提供从 InputStream 输入流中读出数据并转换成字符或字符串的能力。
public func lines(): Iterator<String>
功能:获得 StringReader 的行迭代器。
相当于循环调用 func readln(),内部遇到非法字符时也会抛出异常。
返回值:
异常:
public func read(): ?Rune
功能:按字符读取流中的数据。
返回值:
异常:
public func readToEnd(): String
功能:读取流中所有剩余数据。
返回值:
异常:
public func readUntil(predicate: (Rune)->Bool): Option<String>
功能:从流内读取到使 predicate 返回 true 的字符位置(包含这个字符)或者流结束位置的数据。
参数:
返回值:
异常:
public func readUntil(v: Rune): Option<String>
功能:从流内读取到指定字符(包含指定字符)或者流结束位置的数据。
参数:
返回值:
异常:
public func readln(): Option<String>
功能:按行读取流中的数据。
返回值:
异常:
public func runes(): Iterator<Rune>
功能:获得 StringReader 的 Rune 迭代器。
返回值:
异常:
func close()
public func close(): Unit
功能:关闭当前流。
func isClosed()
public func isClosed(): Bool
功能:判断当前流是否关闭。
返回值:
prop length
public prop length: Int64
功能:返回当前流中的总数据量。
类型:Int64
prop position
public prop position: Int64
功能:返回当前光标位置。
类型:Int64
prop remainLength
public prop remainLength: Int64
功能:返回当前流中未读的数据量。
类型:Int64
func seek(SeekPosition)
public func seek(sp: SeekPosition): Int64
功能:移动光标到指定的位置。
参数:
返回值:
public class StringWriter<T> where T <: OutputStream {
public init(output: T)
} 功能:提供将 String 以及一些 ToString 类型转换成指定编码格式和字节序配置的字符串并写入到输出流的能力。
public func write<T>(v: T): Unit where T <: ToString
功能:写入 ToString 类型。
参数:
public func writeln(v: String): Unit
功能:写入字符串 + 换行符。
参数:
public func writeln<T>(v: T): Unit where T <: ToString
功能:写入 ToString 类型 + 换行符。
参数:
func close()
public func close(): Unit
功能:关闭当前流。
func isClosed()
public func isClosed(): Bool
功能:判断当前流是否关闭。
返回值:
prop length
public prop length: Int64
功能:返回当前流中的总数据量。
类型:Int64
prop position
public prop position: Int64
功能:返回当前光标位置。
类型:Int64
prop remainLength
public prop remainLength: Int64
功能:返回当前流中未读的数据量。
类型:Int64
func seek(SeekPosition)
public func seek(sp: SeekPosition): Int64
功能:移动光标到指定的位置。
参数:
返回值: