Class: ReadableCharacterChannel
Represents a channel, which could be used to read characters through a given ReadableByteChannel.
Constructor
Constructs an io:ReadableCharacterChannel
from a given io:ReadableByteChannel
and Charset
.
init (ReadableByteChannel byteChannel, string charset)
- byteChannel ReadableByteChannel
The
io:ReadableByteChannel
, which would be used to read the characters
- charset string
The character set, which is used to encode/decode the given bytes to characters
Methods
read | Reads a given number of characters. |
readString | Read the entire channel content as a string. |
readAllLines | Read the entire channel content as a list of lines. |
readJson | Reads a JSON from the given channel. |
readXml | Reads an XML from the given channel. |
readProperty | Reads a property from a .properties file with a default value. |
lineStream | Return a stream of lines that can be used to read all the lines in a file as a stream. |
readAllProperties | Reads all properties from a .properties file. |
close | Closes the character channel. |
read
Reads a given number of characters. This will attempt to read up to the numberOfChars
characters of the channel.
An io:EofError
will return once the channel reaches the end.
1string|io:Error result = readableCharChannel.read(1000);
Parameters
- numberOfChars int
Number of characters, which should be read
readAllLines
Read the entire channel content as a list of lines.
1string[]|io:Error content = readableCharChannel.readAllLines();
lineStream
Return a stream of lines that can be used to read all the lines in a file as a stream.
1stream<string, io:Error>|io:Error? result = readableCharChannel.lineStream();