Class
class BufferedInputStream<T> where T <: InputStream
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)
}
Description: Provides input streams with buffers.
This class supports binding the input stream of other InputStream types (such as ByteArrayStream) to the BufferedInputStream instance. When data is read from the instance, the data is read from the bound stream to the buffer for temporary storage, and then the required data is read from the buffer.
Parent Type:
init(T)
public init(input: T)
Description: Creates a BufferedInputStream instance. The default buffer size is 4096.
Parameters:
- input: T: bound input stream
init(T, Array<Byte>)
public init(input: T, buffer: Array<Byte>)
Description: Creates a BufferedInputStream instance.
The internal buffer is determined by the input parameter. In performance-oriented scenarios, the input buffer
can be reused to reduce the number of memory allocation times for better performance.
Parameters:
- input: T: bound input stream
- buffer: Array<Byte>: internal buffer used by BufferedInputStream
Throws:
- IllegalArgumentException: If the buffer size is equal to 0, this exception is thrown.
init(T, Int64)
public init(input: T, capacity: Int64)
Description: Creates a BufferedInputStream instance.
Parameters:
- input: T: bound input stream
- capacity: Int64: size of the internal buffer
Throws:
- IllegalArgumentException: If the value of capacity is less than or equal to 0, this exception is thrown.
func read(Array<Byte>)
public func read(buffer: Array<Byte>): Int64
Description: Reads data from the bound input stream to buffer
.
Parameters:
Returns:
- Int64: number of bytes of the read data
Throws:
- IllegalArgumentException: If buffer is empty, this exception is thrown.
func reset(T)
public func reset(input: T): Unit
Description: Binds a new input stream and resets the status without resetting capacity
.
Parameters:
- input: T: input stream to be bound
extend<T> BufferedInputStream<T> <: Resource where T <: Resource
extend<T> BufferedInputStream<T> <: Resource where T <: Resource
Description: Implements the Resource interface for BufferedInputStream. This type of object can implement automatic resource release in the try-with-resource
syntax context.
Parent Type:
func close()
public func close(): Unit
Description: Closes the current stream.
Note:
- After this method is called, other interfaces of BufferedInputStream cannot be called. Otherwise, unexpected problems may occur.
func isClosed()
public func isClosed(): Bool
Description: Checks whether the current stream is closed.
Returns:
- Bool: true: yes, false: no
extend<T> BufferedInputStream<T> <: Seekable where T <: Seekable
extend<T> BufferedInputStream<T> <: Seekable where T <: Seekable
Description: Implements the Seekable interface for BufferedInputStream to implement operations such as querying data length and moving the cursor.
Parent Type:
prop length
public prop length: Int64
Description: Returns the total data volume of the current stream.
Type: Int64
prop position
public prop position: Int64
Description: Returns the current cursor position.
Type: Int64
prop remainLength
public prop remainLength: Int64
Description: Returns the unread data volume in the current stream.
Type: Int64
func seek(SeekPosition)
public func seek(sp: SeekPosition): Int64
Description: Moves the cursor to a specified position.
Note:
- The specified position cannot be before the data header in the stream.
- The specified position can be after the end of the data in the stream.
- If this function is called, the buffer is cleared before the cursor is moved.
Parameters:
- sp: SeekPosition: the position to which the cursor is to be moved
Returns:
- Int64: the offset (in bytes) from the start point of the data in the stream to the position after the cursor is moved
class BufferedOutputStream<T> where T <: OutputStream
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)
}
Description: Provides output streams with buffers.
This class supports binding the input stream of the OutputStream type (such as ByteArrayStream) to a BufferedOutputStream instance. When data is written by using the instance, the data is written to the buffer for temporary storage, and then written from the buffer to the stream.
Parent Type:
init(T)
public init(output: T)
Description: Creates a BufferedOutputStream instance. The default buffer size is 4096.
Parameters:
- output: T: bound output stream
init(T, Array<Byte>)
public init(output: T, buffer: Array<Byte>)
Description: Creates a BufferedOutputStream instance.
The internal buffer is determined by the input parameter. In performance-oriented scenarios, the input buffer
can be reused to reduce the number of memory allocation times for better performance.
Parameters:
- output: T: bound output stream
- buffer: Array<Byte>: internal buffer used by BufferedOutputStream
Throws:
- IllegalArgumentException: If the buffer size is equal to 0, this exception is thrown.
init(T, Int64)
public init(output: T, capacity: Int64)
Description: Creates a BufferedOutputStream instance.
Parameters:
- output: T: bound output stream
- capacity: Int64: size of the internal buffer
Throws:
- IllegalArgumentException: If the value of capacity is less than or equal to 0, this exception is thrown.
func flush()
public func flush(): Unit
Description: Refreshes BufferedOutputStream. Writes the remaining data in the internal buffer to the bound output stream and refreshes BufferedOutputStream.
func reset(T)
public func reset(output: T): Unit
Description: Binds a new output stream and resets the status without resetting capacity
.
Parameters:
- output: T: output stream to be bound
func write(Array<Byte>)
public func write(buffer: Array<Byte>): Unit
Description: Writes data in buffer
to the bound output stream.
Parameters:
extend<T> BufferedOutputStream<T> <: Resource where T <: Resource
extend<T> BufferedOutputStream<T> <: Resource where T <: Resource
Description: Implements the Resource interface for BufferedOutputStream. This type of object can implement automatic resource release in the try-with-resource
syntax context.
Parent Type:
func close()
public func close(): Unit
Description: Closes the current stream.
Note:
- After this method is called, other interfaces of BufferedOutputStream cannot be called. Otherwise, unexpected problems may occur.
func isClosed()
public func isClosed(): Bool
Description: Checks whether the current stream is closed.
Returns:
- Bool: true: yes, false: no
extend<T> BufferedOutputStream<T> <: Seekable where T <: Seekable
extend<T> BufferedOutputStream<T> <: Seekable where T <: Seekable
Description: Implements the Seekable interface for BufferedOutputStream to implement operations such as querying data length and moving the cursor.
Parent Type:
prop length
public prop length: Int64
Description: Returns the total data volume of the current stream.
Type: Int64
prop position
public prop position: Int64
Description: Returns the current cursor position.
Type: Int64
prop remainLength
public prop remainLength: Int64
Description: Returns the unread data volume in the current stream.
Type: Int64
func seek(SeekPosition)
public func seek(sp: SeekPosition): Int64
Description: Moves the cursor to a specified position.
Note:
- The specified position cannot be before the data header in the stream.
- The specified position can be after the end of the data in the stream.
- When this function is called, the data in the buffer is written to the bound output stream before the cursor is moved.
Parameters:
- sp: SeekPosition: the position to which the cursor is to be moved
Returns:
- Int64: the offset (in bytes) from the start point of the data in the stream to the position after the cursor is moved
class ByteArrayStream
public class ByteArrayStream <: IOStream & Seekable {
public init()
public init(capacity: Int64)
}
Description: Writes and reads byte streams based on the Array<Byte> data type.
Parent Type:
prop length
public prop length: Int64
Description: Returns the total data volume of the current stream.
Type: Int64
prop position
public prop position: Int64
Description: Obtains the current cursor position.
Type: Int64
prop remainLength
public prop remainLength: Int64
Description: Obtains the unread data volume in the current stream.
Type: Int64
init()
public init()
Description: Creates a ByteArrayStream instance with a default initial capacity of 32.
init(Int64)
public init(capacity: Int64)
Description: Creates a ByteArrayStream instance.
Parameters:
- capacity: Int64: specified initial capacity
Throws:
- IllegalArgumentException: If the value of capacity is less than 0, this exception is thrown.
static func fromString(String)
public static func fromString(data: String): ByteArrayStream
Description: Constructs a ByteArrayStream using the String type.
Parameters:
- data: String: initial data of a new ByteArrayStream
Returns:
- ByteArrayStream: ByteArrayStream constructed by using data
func bytes()
public func bytes(): Array<Byte>
Description: Obtains the slice of the unread data in the current ByteArrayStream.
Note:
- Modifications such as reading, writing, or resetting the buffer will invalidate the slice.
- Modifications to a slice affect the content of the buffer.
Returns:
func capacity()
public func capacity(): Int64
Description: Obtains the size of the current buffer.
Returns:
- Int64: size of the current buffer
func clear()
public func clear(): Unit
Description: Clears all data in the current ByteArrayStream.
func clone()
public func clone(): ByteArrayStream
Description: Constructs a new ByteArrayStream using the data in the current ByteArrayStream.
Returns:
- ByteArrayStream: new ByteArrayStream object
func copyTo(OutputStream)
public func copyTo(output: OutputStream): Unit
Description: Copies the unread data in the current ByteArrayStream to the output stream.
Parameters:
- output: OutputStream: stream to which the data is to be copied
func read(Array<Byte>)
public func read(buffer: Array<Byte>): Int64
Description: Reads data from the input stream and stores the data in buffer.
Parameters:
Returns:
- Int64: number of bytes of the read data
Throws:
- IllegalArgumentException: If buffer is empty, this exception is thrown.
func readString()
public func readString(): String
Description: Reads the remaining data in the stream, converts the data to the String type, and checks whether the data complies with the UTF-8 encoding rule.
Returns:
Throws:
- ContentFormatException: If the remaining bytes do not comply with the UTF-8 encoding rule, this exception is thrown.
func readStringUnchecked()
public unsafe func readStringUnchecked(): String
Description: Reads the remaining data in the stream and converts the data to the String type without checking whether the data complies with the UTF-8 encoding rule.
Returns:
func readToEnd()
public func readToEnd(): Array<Byte>
Description: Obtains the unread data in the current ByteArrayStream.
Returns:
func reserve(Int64)
public func reserve(additional: Int64): Unit
Description: Expands the buffer by a specified size.
Note:
- If the number of remaining bytes in the buffer is greater than or equal to
additional
, capacity expansion is not performed.- If the number of remaining bytes in the buffer is less than
additional
, the buffer is expanded to the larger value between (additional
+capacity
) and (1.5 times the rounded-down value ofcapacity
).
Parameters:
- additional: Int64: size by which the buffer is to be expanded
Throws:
- IllegalArgumentException: If the value of additional is less than 0, this exception is thrown.
- OverflowException: If the buffer size after capacity expansion is greater than the maximum value of Int64, this exception is thrown.
func seek(SeekPosition)
public func seek(sp: SeekPosition): Int64
Description: Moves the cursor to a specified position.
Note:
- The specified position cannot be before the data header in the stream.
- The specified position can be after the end of the data in the stream.
Parameters:
- sp: SeekPosition: the position to which the cursor is to be moved
Returns:
- Int64: the offset (in bytes) from the data header in the stream to the position to which the cursor is moved
Throws:
- IOException: If the specified position is before the data header in the stream, this exception is thrown.
func write(Array<Byte>)
public func write(buffer: Array<Byte>): Unit
Description: Writes data in buffer
to the output stream.
Parameters:
Throws:
- IllegalArgumentException: If data fails to be written or only part of data is written, this exception is thrown.
class ChainedInputStream<T> where T <: InputStream
public class ChainedInputStream<T> <: InputStream where T <: InputStream {
public init(input: Array<T>)
}
Description: Reads data from the InputStream array in sequence.
Parent Type:
init(Array<T>)
public init(input: Array<T>)
Description: Creates a ChainedInputStream instance.
Parameters:
- input: Array<T>: bound input stream array
Throws:
- IllegalArgumentException: If input is empty, this exception is thrown.
func read(Array<Byte>)
public func read(buffer: Array<Byte>): Int64
Description: Reads data from the bound InputStream array and writes the data to buffer in sequence.
Parameters:
Returns:
- Int64: number of bytes read
Throws:
- IllegalArgumentException: If buffer is empty, this exception is thrown.
class MultiOutputStream<T> where T <: OutputStream
public class MultiOutputStream<T> <: OutputStream where T <: OutputStream {
public init(output: Array<T>)
}
Description: Writes data to each output stream in the OutputStream array at the same time.
Parent Type:
init(Array<T>)
public init(output: Array<T>)
Description: Creates a MultiOutputStream instance.
Parameters:
- output: Array<T>: bound output stream array
Throws:
- IllegalArgumentException: If output is empty, this exception is thrown.
func flush()
public func flush(): Unit
Description: Refreshes each output stream in the bound output stream array.
func write(Array<Byte>)
public func write(buffer: Array<Byte>): Unit
Description: Writes the value of buffer to each output stream in the bound OutputStream array.
Parameters:
class StringReader<T> where T <: InputStream
public class StringReader<T> where T <: InputStream {
public init(input: T)
}
Description: Reads data from the InputStream input stream and converts the data to characters or a string.
Note:
- By default, StringReader has a buffer with a size of 4096 bytes.
- Currently, StringReader supports only UTF-8 encoding.
init(T)
public init(input: T)
Description: Creates a StringReader instance.
Parameters:
- input: T: input stream from which the data to be read
func lines()
public func lines(): Iterator<String>
Description: Obtains the line iterator of StringReader.
It is equivalent to cyclically calling func readln()
. If there is an invalid character, an exception is thrown.
Note:
- Each line ends with a newline character.
- The newline character can be
\n
,\r
, or\r\n
.- The read line string does not contain the newline character at the end.
Returns:
Throws:
- ContentFormatException: If the
for-in
syntax is used to traverse the iterator or an invalid character is read when thenext()
method is called, this exception is thrown.
func read()
public func read(): ?Rune
Description: Reads data in a stream by character.
Returns:
- ?Rune: If data is read successfully, Option<Rune>.Some(c) is returned, where c is the character read. Otherwise, Option<Rune>.None is returned.
Throws:
- ContentFormatException: If an invalid character is read, this exception is thrown.
func readToEnd()
public func readToEnd(): String
Description: Reads the remaining data in a stream.
Returns:
- String: remaining data in the stream
Throws:
- ContentFormatException: If an invalid character is read, this exception is thrown.
func readUntil((Rune)->Bool)
public func readUntil(predicate: (Rune)->Bool): Option<String>
Description: Reads data in a stream to the character position (including the character) that makes predicate
return true or to the end of the stream.
Parameters:
- predicate: (Rune)->Bool: expression for returning true under certain conditions
Returns:
- Option<String>: If data is read successfully, Option<String>.Some(str) is returned, where str is the string read. Otherwise, Option<String>.None is returned.
Throws:
- ContentFormatException: If an invalid character is read, this exception is thrown.
func readUntil(Rune)
public func readUntil(v: Rune): Option<String>
Description: Reads data in a stream to a specified character (including the character) or to the end of the stream.
Parameters:
- v: Rune: the specified character
Returns:
- Option<String>: If data is read successfully, Option<String>.Some(str) is returned, where str is the string read. Otherwise, Option<String>.None is returned.
Throws:
- ContentFormatException: If an invalid character is read, this exception is thrown.
func readln()
public func readln(): Option<String>
Description: Reads data in a stream by row.
Note:
- The original newline characters are removed from the read data.
Returns:
- Option<String>: If data is read successfully, Option<String>.Some(str) is returned, where str is the string read. Otherwise, Option<String>.None is returned.
Throws:
- ContentFormatException: If an invalid character is read, this exception is thrown.
func runes()
public func runes(): Iterator<Rune>
Description: Obtains the Rune iterator of StringReader.
Returns:
Throws:
- ContentFormatException: If an invalid character is read when
for-in
ornext()
is called, this exception is thrown.
extend<T> StringReader<T> <: Resource where T <: Resource
extend<T> StringReader<T> <: Resource where T <: Resource
Description: Implements the Resource interface for StringReader. This type of object can implement automatic resource release in the try-with-resource
syntax context.
Parent Type:
func close()
public func close(): Unit
Description: Closes the current stream.
Note:
- After this method is called, other interfaces of StringReader cannot be called. Otherwise, unexpected problems may occur.
func isClosed()
public func isClosed(): Bool
Description: Checks whether the current stream is closed.
Returns:
- Bool: true: yes, false: no
extend<T> StringReader<T> <: Seekable where T <: Seekable
extend<T> StringReader<T> <: Seekable where T <: Seekable
Description: Implements the Seekable interface for StringReader to implement operations such as querying data length and moving the cursor.
Parent Type:
prop length
public prop length: Int64
Description: Returns the total data volume of the current stream.
Type: Int64
prop position
public prop position: Int64
Description: Returns the current cursor position.
Type: Int64
prop remainLength
public prop remainLength: Int64
Description: Returns the unread data volume in the current stream.
Type: Int64
func seek(SeekPosition)
public func seek(sp: SeekPosition): Int64
Description: Moves the cursor to a specified position.
Note:
- The specified position cannot be before the data header in the stream.
- The specified position can be after the end of the data in the stream.
Parameters:
- sp: SeekPosition: the position to which the cursor is to be moved
Returns:
- Int64: the offset (in bytes) from the start point of the data in the stream to the position after the cursor is moved
class StringWriter<T> where T <: OutputStream
public class StringWriter<T> where T <: OutputStream {
public init(output: T)
}
Description: Converts String and some ToString types to strings in the specified encoding format and byte order and writes the strings to the output stream.
Note:
- By default, StringWriter has a buffer with a size of 4096 bytes.
- Currently, StringWriter supports only UTF-8 encoding.
init(T)
public init(output: T)
Description: Creates a StringWriter instance.
Parameters:
- output: T: output stream to which data is to be written
func flush()
public func flush(): Unit
Description: Refreshes the internal buffer, writes the data in the buffer to output, and refreshes output.
func write(Bool)
public func write(v: Bool): Unit
Description: Writes the Bool type.
Parameters:
func write(Float16)
public func write(v: Float16): Unit
Description: Writes the Float16 type.
Parameters:
func write(Float32)
public func write(v: Float32): Unit
Description: Writes the Float32 type.
Parameters:
func write(Float64)
public func write(v: Float64): Unit
Description: Writes the Float64 type.
Parameters:
func write(Int16)
public func write(v: Int16): Unit
Description: Writes the Int16 type.
Parameters:
func write(Int32)
public func write(v: Int32): Unit
Description: Writes the Int32 type.
Parameters:
func write(Int64)
public func write(v: Int64): Unit
Description: Writes the Int64 type.
Parameters:
func write(Int8)
public func write(v: Int8): Unit
Description: Writes the Int8 type.
Parameters:
func write(Rune)
public func write(v: Rune): Unit
Description: Writes the Rune type.
Parameters:
func write(String)
public func write(v: String): Unit
Description: Writes a string.
Parameters:
- v: String: string to be written
func write(UInt16)
public func write(v: UInt16): Unit
Description: Writes the UInt16 type.
Parameters:
func write(UInt32)
public func write(v: UInt32): Unit
Description: Writes the UInt32 type.
Parameters:
func write(UInt64)
public func write(v: UInt64): Unit
Description: Writes the UInt64 type.
Parameters:
func write(UInt8)
public func write(v: UInt8): Unit
Description: Writes the UInt8 type.
Parameters:
func write<T>(T) where T <: ToString
public func write<T>(v: T): Unit where T <: ToString
Description: Writes the ToString type.
Parameters:
- v: T: instance of the ToString type
func writeln()
public func writeln(): Unit
Description: Writes a newline character.
func writeln(Bool)
public func writeln(v: Bool): Unit
Description: Writes the Bool type and newline characters.
Parameters:
func writeln(Float16)
public func writeln(v: Float16): Unit
Description: Writes the Float16 type and newline characters.
Parameters:
func writeln(Float32)
public func writeln(v: Float32): Unit
Description: Writes the Float32 type and newline characters.
Parameters:
func writeln(Float64)
public func writeln(v: Float64): Unit
Description: Writes the Float64 type and newline characters.
Parameters:
func writeln(Int16)
public func writeln(v: Int16): Unit
Description: Writes the Int16 type and newline characters.
Parameters:
func writeln(Int32)
public func writeln(v: Int32): Unit
Description: Writes the Int32 type and newline characters.
Parameters:
func writeln(Int64)
public func writeln(v: Int64): Unit
Description: Writes the Int64 type and newline characters.
Parameters:
func writeln(Int8)
public func writeln(v: Int8): Unit
Description: Writes the Int8 type and newline characters.
Parameters:
func writeln(Rune)
public func writeln(v: Rune): Unit
Description: Writes the Rune type and newline characters.
Parameters:
func writeln(String)
public func writeln(v: String): Unit
Description: Writes a string and a newline character.
Parameters:
- v: String: string to be written
func writeln(UInt16)
public func writeln(v: UInt16): Unit
Description: Writes the UInt16 type and newline characters.
Parameters:
func writeln(UInt32)
public func writeln(v: UInt32): Unit
Description: Writes the UInt32 type and newline characters.
Parameters:
func writeln(UInt64)
public func writeln(v: UInt64): Unit
Description: Writes the UInt64 type and newline characters.
Parameters:
func writeln(UInt8)
public func writeln(v: UInt8): Unit
Description: Writes the UInt8 type and newline characters.
Parameters:
func writeln<T>(T) where T <: ToString
public func writeln<T>(v: T): Unit where T <: ToString
Description: Writes the ToString type and newline characters.
Parameters:
- v: T: instance of the ToString type
extend<T> StringWriter<T> <: Resource where T <: Resource
extend<T> StringWriter<T> <: Resource where T <: Resource
Description: Implements the Resource interface for StringWriter. This type of object can implement automatic resource release in the try-with-resource
syntax context.
Parent Type:
func close()
public func close(): Unit
Description: Closes the current stream.
Note:
- After this method is called, other interfaces of StringWriter cannot be called. Otherwise, unexpected problems may occur.
func isClosed()
public func isClosed(): Bool
Description: Checks whether the current stream is closed.
Returns:
- Bool: true: yes, false: no
extend<T> StringWriter<T> <: Seekable where T <: Seekable
extend<T> StringWriter<T> <: Seekable where T <: Seekable
Description: Implements the Seekable interface for StringWriter to implement operations such as querying data length and moving the cursor.
Parent Type:
prop length
public prop length: Int64
Description: Returns the total data volume of the current stream.
Type: Int64
prop position
public prop position: Int64
Description: Returns the current cursor position.
Type: Int64
prop remainLength
public prop remainLength: Int64
Description: Returns the unread data volume in the current stream.
Type: Int64
func seek(SeekPosition)
public func seek(sp: SeekPosition): Int64
Description: Moves the cursor to a specified position.
Note:
- The specified position cannot be before the data header in the stream.
- The specified position can be after the end of the data in the stream.
Parameters:
- sp: SeekPosition: the position to which the cursor is to be moved
Returns:
- Int64: the offset (in bytes) from the start point of the data in the stream to the position after the cursor is moved