Functions - io

createReadableChannel

Creates an in-memory channel which will reference stream of bytes.

openReadableCsvFile

Retrieves a readable CSV channel from a give file path.

openReadableFile

Retrieves a ReadableByteChannel from a given file path.

openWritableCsvFile

Retrieves a writable CSV channel from a give file path.

openWritableFile

Retrieves a WritableByteChannel from a given file path.

print

Prints any or error value(s) to the STDOUT.

println

Prints any or error value(s) to the STDOUT followed by a new line.

readln

Returns the input read from STDIN.

sprintf

Returns a formatted string using the specified format string and arguments. Following format specifiers are allowed. b boolean B boolean (ALL_CAPS) d int f float x hex X HEX (ALL_CAPS) s string (This specifier is applicable for any of the supported types in Ballerina. These values will be converted to their string representation.)

createReadableChannel

(byte[] content)

returns ReadableByteChannel | IOError

Creates an in-memory channel which will reference stream of bytes.

Parameters

  • content byte[]
  • Content which should be exposed as channel

  • Return Type

    (ReadableByteChannel | IOError)
  • ByteChannel representation to read the memory content or IOError if any error occurred

openReadableCsvFile

(string path, Separator fieldSeparator, string charset, int skipHeaders)

returns ReadableCSVChannel | IOError

Retrieves a readable CSV channel from a give file path.

Parameters

  • path string
  • File path which describes the location of the CSV

  • fieldSeparator Separator - ,
  • CSV record separator (i.e comma or tab)

  • charset string - UTF-8
  • Encoding characters in the file represents

  • skipHeaders int - 0
  • Number of headers which should be skipped

openReadableFile

(string path)

returns ReadableByteChannel | IOError

Retrieves a ReadableByteChannel from a given file path.

Parameters

  • path string
  • Relative/absolute path string to locate the file

openWritableCsvFile

(string path, Separator fieldSeparator, string charset, int skipHeaders)

returns WritableCSVChannel | IOError

Retrieves a writable CSV channel from a give file path.

Parameters

  • path string
  • File path which describes the location of the CSV

  • fieldSeparator Separator - ,
  • CSV record separator (i.e comma or tab)

  • charset string - UTF-8
  • Encoding characters in the file represents

  • skipHeaders int - 0
  • Number of headers which should be skipped

  • Return Type

    (WritableCSVChannel | IOError)
  • WritableCSVChannel which could be used to write CSV records or IOError if any error occurred

openWritableFile

(string path, boolean append)

returns WritableByteChannel | IOError

Retrieves a WritableByteChannel from a given file path.

Parameters

  • path string
  • Relative/absolute path string to locate the file

  • append boolean - false
  • Append to end of file.

print

Prints any or error value(s) to the STDOUT.

Parameters

  • values any | error
  • The value(s) to be printed.

println

Prints any or error value(s) to the STDOUT followed by a new line.

Parameters

  • values any | error
  • The value(s) to be printed.

readln

(any a)

returns string

Returns the input read from STDIN.

Parameters

  • a any
  • Any value to be printed

  • Return Type

    (string)
  • Input read from STDIN

sprintf

(string format, any | error args)

returns string

Returns a formatted string using the specified format string and arguments. Following format specifiers are allowed. b boolean B boolean (ALL_CAPS) d int f float x hex X HEX (ALL_CAPS) s string (This specifier is applicable for any of the supported types in Ballerina. These values will be converted to their string representation.)

Parameters

  • format string
  • A format string

  • args any | error
  • Arguments referenced by the format specifiers in the format string.

  • Return Type

    (string)
  • Formatted string