Functions
createReadableChannel | I Creates an in-memory channel, which will be a reference stream of bytes. |
fileReadBlocksAsStream | I Read the entire file content as a stream of blocks. |
fileReadBytes | I Read the entire file content as a byte array. |
fileReadCsv | I Read file content as a CSV. |
fileReadCsvAsStream | I Read file content as a CSV. |
fileReadJson | I Reads file content as a JSON. |
fileReadLines | I Reads the entire file content as a list of lines. |
fileReadLinesAsStream | I Reads file content as a stream of lines. |
fileReadString | I Reads the entire file content as a |
fileReadXml | I Reads file content as an XML. |
fileWriteBlocksFromStream | I Write a byte stream to a file. |
fileWriteBytes | I Write a set of bytes to a file. |
fileWriteCsv | I Write CSV content to a file. |
fileWriteCsvFromStream | I Write CSV record stream to a file. |
fileWriteJson | I Write a JSON to a file. |
fileWriteLines | I Write an array of lines to a file. |
fileWriteLinesFromStream | I Write stream of lines to a file. |
fileWriteString | I Write a string content to a file. |
fileWriteXml | I Write XML content to a file. |
fprint | I Prints |
fprintln | I Prints |
openReadableCsvFile | I Retrieves a readable CSV channel from a given file path. |
openReadableFile | I Retrieves a |
openWritableCsvFile | I Retrieves a writable CSV channel from a given file path. |
openWritableFile | I Retrieves a |
I Prints | |
println | I Prints |
readln | Retrieves the input read from the STDIN. |
createReadableChannel
function createReadableChannel(byte[ ] content) returns ReadableByteChannel | Error
Creates an in-memory channel, which will be a reference stream of bytes.
1var byteChannel = io:createReadableChannel(content);
Parameters
- content byte[ ]
Content, which should be exposed as a channel
Return Type
(ReadableByteChannel | Error)The io:ReadableByteChannel
related to the given bytes or else an io:Error
if any error occurred
fileReadBlocksAsStream
Read the entire file content as a stream of blocks.
1stream<io:Block, io:Error?>|io:Error content = io:fileReadBlocksAsStream("./resources/myfile.txt", 1000);
fileReadBytes
Read the entire file content as a byte array.
1byte[]|io:Error content = io:fileReadBytes("./resources/myfile.txt");
Parameters
- path string
The path of the file
fileReadCsv
Read file content as a CSV.
1string[][]|io:Error content = io:fileReadCsv("./resources/myfile.csv");
fileReadCsvAsStream
Read file content as a CSV.
1stream<string[], io:Error?>|io:Error content = io:fileReadCsvAsStream("./resources/myfile.csv");
Parameters
- path string
The CSV file path
fileReadJson
Reads file content as a JSON.
1json|io:Error content = io:fileReadJson("./resources/myfile.json");
Parameters
- path string
The path of the JSON file
fileReadLines
Reads the entire file content as a list of lines.
The resulting string array does not contain the terminal carriage (e.g., \r
or \n
).
1string[]|io:Error content = io:fileReadLines("./resources/myfile.txt");
Parameters
- path string
The path of the file
fileReadLinesAsStream
Reads file content as a stream of lines.
The resulting stream does not contain the terminal carriage (e.g., \r
or \n
).
1stream<string, io:Error?>|io:Error content = io:fileReadLinesAsStream("./resources/myfile.txt");
Parameters
- path string
The path of the file
fileReadString
Reads the entire file content as a string
.
The resulting string output does not contain the terminal carriage (e.g., \r
or \n
).
1string|io:Error content = io:fileReadString("./resources/myfile.txt");
Parameters
- path string
The path of the file
fileReadXml
Reads file content as an XML.
1xml|io:Error content = io:fileReadXml("./resources/myfile.xml");
Parameters
- path string
The path of the XML file
fileWriteBlocksFromStream
function fileWriteBlocksFromStream(string path, stream<byte[ ], Error?> byteStream, FileWriteOption option) returns Error?
Write a byte stream to a file.
1byte[] content = [[60, 78, 39, 28]];2stream<byte[], io:Error?> byteStream = content.toStream();3io:Error? result = io:fileWriteBlocksFromStream("./resources/myfile.txt", byteStream);
Parameters
- path string
The path of the file
- option FileWriteOption (default OVERWRITE)
To indicate whether to overwrite or append the given content
fileWriteBytes
function fileWriteBytes(string path, byte[ ] content, FileWriteOption option) returns Error?
Write a set of bytes to a file.
1byte[] content = [60, 78, 39, 28];2io:Error? result = io:fileWriteBytes("./resources/myfile.txt", content);
Parameters
- path string
The path of the file
- content byte[ ]
Byte content to write
- option FileWriteOption (default OVERWRITE)
To indicate whether to overwrite or append the given content
fileWriteCsv
function fileWriteCsv(string path, string[ ] content, FileWriteOption option) returns Error?
Write CSV content to a file.
1string[][] content = [["Anne", "Johnson", "SE"], ["John", "Cameron", "QA"]];2io:Error? result = io:fileWriteCsv("./resources/myfile.csv", content);
Parameters
- path string
The CSV file path
- content string[ ]
CSV content as an array of string arrays
- option FileWriteOption (default OVERWRITE)
To indicate whether to overwrite or append the given content
fileWriteCsvFromStream
function fileWriteCsvFromStream(string path, stream<string[ ], Error?> content, FileWriteOption option) returns Error?
Write CSV record stream to a file.
1string[][] content = [["Anne", "Johnson", "SE"], ["John", "Cameron", "QA"]];2stream<string[], io:Error?> recordStream = content.toStream();3io:Error? result = io:fileWriteCsvFromStream("./resources/myfile.csv", recordStream);
Parameters
- path string
The CSV file path
- option FileWriteOption (default OVERWRITE)
To indicate whether to overwrite or append the given content
fileWriteJson
Write a JSON to a file.
1json content = {"name": "Anne", "age": 30};2io:Error? result = io:fileWriteJson("./resources/myfile.json", content);
fileWriteLines
function fileWriteLines(string path, string[ ] content, FileWriteOption option) returns Error?
Write an array of lines to a file.
During the writing operation, a newline character \n
will be added after each line.
1string[] content = ["Hello Universe..!!", "How are you?"];2io:Error? result = io:fileWriteLines("./resources/myfile.txt", content);
Parameters
- path string
The path of the file
- content string[ ]
An array of string lines to write
- option FileWriteOption (default OVERWRITE)
To indicate whether to overwrite or append the given content
fileWriteLinesFromStream
function fileWriteLinesFromStream(string path, stream<string, Error?> lineStream, FileWriteOption option) returns Error?
Write stream of lines to a file.
During the writing operation, a newline character \n
will be added after each line.
1string content = ["Hello Universe..!!", "How are you?"];2stream<string, io:Error?> lineStream = content.toStream();3io:Error? result = io:fileWriteLinesFromStream("./resources/myfile.txt", lineStream);
Parameters
- path string
The path of the file
- option FileWriteOption (default OVERWRITE)
To indicate whether to overwrite or append the given content
fileWriteString
function fileWriteString(string path, string content, FileWriteOption option) returns Error?
Write a string content to a file.
1string content = "Hello Universe..!!";2io:Error? result = io:fileWriteString("./resources/myfile.txt", content);
Parameters
- path string
The path of the file
- content string
String content to write
- option FileWriteOption (default OVERWRITE)
To indicate whether to overwrite or append the given content
fileWriteXml
function fileWriteXml(string path, xml content, FileWriteOption fileWriteOption, *XmlWriteOptions xmlOptions) returns Error?
Write XML content to a file.
1xml content = xml `<book>The Lost World</book>`;2io:Error? result = io:fileWriteXml("./resources/myfile.xml", content);
Parameters
- path string
The path of the XML file
- content xml
XML content to write
- fileWriteOption FileWriteOption (default OVERWRITE)
File write option (OVERWRITE
and APPEND
are the possible values and the default value is OVERWRITE
)
- xmlOptions *XmlWriteOptions
XML writing options (XML entity type and DOCTYPE)
fprint
function fprint(FileOutputStream fileOutputStream, Printable... values)
Prints any
, error
, or string templates(such as The respective int value is ${val}
) value(s) to
a given stream(STDOUT or STDERR).
1io:fprint(io:stderr, "Unexpected error occurred");
Parameters
- fileOutputStream FileOutputStream
The output stream (io:stdout
or io:stderr
) content needs to be printed
- values Printable...
The value(s) to be printed
fprintln
function fprintln(FileOutputStream fileOutputStream, Printable... values)
Prints any
, error
, or string templates(such as The respective int value is ${val}
) value(s) to
a given stream(STDOUT or STDERR) followed by a new line.
1io:fprintln(io:stderr, "Unexpected error occurred");
Parameters
- fileOutputStream FileOutputStream
The output stream (io:stdout
or io:stderr
) content needs to be printed
- values Printable...
The value(s) to be printed
openReadableCsvFile
function openReadableCsvFile(string path, Separator fieldSeparator, string charset, int skipHeaders) returns ReadableCSVChannel | Error
Retrieves a readable CSV channel from a given file path.
1io:ReadableCSVChannel rCsvChannel = check io:openReadableCsvFile(srcFileName);
Parameters
- path string
File path, which describes the location of the CSV
- fieldSeparator Separator (default ",")
CSV record separator (i.e., comma or tab)
- charset string (default "UTF-8")
Representation of the encoding characters in the file
- skipHeaders int (default 0)
Number of headers, which should be skipped
Return Type
(ReadableCSVChannel | Error)The io:ReadableCSVChannel
, which could be used to iterate through the CSV records or else an io:Error
if any error occurred
openReadableFile
function openReadableFile(string path) returns ReadableByteChannel | Error
Retrieves a ReadableByteChannel
from a given file path.
1io:ReadableByteChannel readableFieldResult = check io:openReadableFile("./files/sample.txt");
Parameters
- path string
Relative/absolute path string to locate the file
Return Type
(ReadableByteChannel | Error)The io:ReadableByteChannel
related to the given file or else an io:Error
if there is an error while opening
openWritableCsvFile
function openWritableCsvFile(string path, Separator fieldSeparator, string charset, int skipHeaders, FileWriteOption option) returns WritableCSVChannel | Error
Retrieves a writable CSV channel from a given file path.
1io:WritableCSVChannel wCsvChannel = check io:openWritableCsvFile(srcFileName);
Parameters
- path string
File path, which describes the location of the CSV
- fieldSeparator Separator (default ",")
CSV record separator (i.e., comma or tab)
- charset string (default "UTF-8")
Representation of the encoding characters in the file
- skipHeaders int (default 0)
Number of headers, which should be skipped
- option FileWriteOption (default OVERWRITE)
To indicate whether to overwrite or append the given content
Return Type
(WritableCSVChannel | Error)The io:WritableCSVChannel
, which could be used to write the CSV records or else an io:Error
if any error occurred
openWritableFile
function openWritableFile(string path, FileWriteOption option) returns WritableByteChannel | Error
Retrieves a WritableByteChannel
from a given file path.
1io:WritableByteChannel writableFileResult = check io:openWritableFile("./files/sampleResponse.txt");
Parameters
- path string
Relative/absolute path string to locate the file
- option FileWriteOption (default OVERWRITE)
To indicate whether to overwrite or append the given content
Return Type
(WritableByteChannel | Error)The io:WritableByteChannel
related to the given file or else an io:Error
if any error occurred
function print(Printable... values)
Prints any
, error
, or string templates (such as The respective int value is ${val}
) value(s) to the STDOUT
.
1io:print("Start processing the CSV file from ", srcFileName);
Parameters
- values Printable...
The value(s) to be printed
println
function println(Printable... values)
Prints any
, error
or string templates(such as The respective int value is ${val}
) value(s) to the STDOUT
followed by a new line.
1io:println("Start processing the CSV file from ", srcFileName);
Parameters
- values Printable...
The value(s) to be printed