Class: WritableCharacterChannel

Represents a channel which could be used to write characters through a given WritableCharacterChannel.

Constructor

Constructs a WritableByteChannel from a given WritableByteChannel and Charset.

init (WritableByteChannel bChannel, string charset)
  • bChannel WritableByteChannel
  • The WritableByteChannel, which would be used to write the characters

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

Methods

write

Writes a given sequence of characters (string).

writeLine

Writes a string as a line with a following newline character \n.

writeJson

Writes a given JSON to the given channel.

writeXml

Writes a given XML to the channel.

writeProperties

Writes a given key-valued pair map<string> to a property file.

close

Closes a given WritableCharacterChannel channel.

write

function write(string content, int startOffset) returns int | Error
Isolated Function

Writes a given sequence of characters (string).

1int|io:Error result = writableCharChannel.write("Content", 0);

Parameters

  • content string
  • Content to be written

  • startOffset int
  • Number of characters to be offset when writing the content

Return Type

(int | Error)

Content length that written or else io:Error

writeLine

function writeLine(string content) returns Error?
Isolated Function

Writes a string as a line with a following newline character \n.

1io:Error? result = writableCharChannel.writeLine("Content");

Parameters

  • content string
  • Content to be written

Return Type

(Error?)

Returns null if the writing was successful or an io:Error

writeJson

function writeJson(json content) returns Error?
Isolated Function

Writes a given JSON to the given channel.

1io:Error? err = writableCharChannel.writeJson(inputJson, 0);

Parameters

  • content json
  • The JSON to be written

Return Type

(Error?)

Returns null if the writing was successful or an io:Error

writeXml

function writeXml(xml content, XmlDoctype? xmlDoctype) returns Error?
Isolated Function

Writes a given XML to the channel.

1io:Error? err = writableCharChannel.writeXml(inputXml, 0);

Parameters

  • content xml
  • The XML to be written

  • xmlDoctype XmlDoctype? (default ())
  • Optional argument to specify the XML DOCTYPE configurations

Return Type

(Error?)

() or else io:Error if any error occurred

writeProperties

function writeProperties(map<string> properties, string comment) returns Error?
Isolated Function

Writes a given key-valued pair map<string> to a property file.

1io:Error? err = writableCharChannel.writeProperties(properties);

Parameters

  • properties map<string>
  • The map that contains keys and values

  • comment string
  • Comment describing the property list

Return Type

(Error?)

() or else io:Error if any error occurred

close

function close() returns Error?
Isolated Function

Closes a given WritableCharacterChannel channel. After a channel is closed, any further writing operations will cause an error.

1io:Error err = writableCharChannel.close();

Return Type

(Error?)

() or else an io:Error if any error occurred