Object - io : ReadableCharacterChannel

Represents a channel, which could be used to read characters through a given ReadableByteChannel.

Constructor

__init

(ReadableByteChannel byteChannel, string charset)

  • byteChannel ReadableByteChannel
  • The ReadableByteChannel, which would be used to read the characters

  • charset string
  • The character set, which would be used to encode/decode the given bytes to characters

Methods

Reads a given number of characters.
Reads a JSON from the given channel.
Reads an XML from the given channel.
Closes a given character channel.

read

(int numberOfChars)

returns string | Error

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.

 string|io:Error result = readableCharChannel.read(1000);

Parameters

  • numberOfChars int
  • Number of characters, which should be read

  • Return Type

    (string | Error)
  • Content, which is read, an EofError once the channel reaches the end or else an io:Error

readJson

()

returns json | Error

Reads a JSON from the given channel.

 json|io:Error result = readableCharChannel.readJson();

  • Return Type

    (json | Error)
  • The read JSON string or else an io:Error

readXml

()

returns xml | Error

Reads an XML from the given channel.

 json|io:Error result = readableCharChannel.readXml();

  • Return Type

    (xml | Error)
  • The read XML or else an io:Error

close

()

returns Error?

Closes a given character channel.

 io:Error? err = readableCharChannel.close();

  • Return Type

    (Error?)
  • If an error occurred while writing