diff --git a/ballerina/block_stream.bal b/ballerina/block_stream.bal index fc6b6311..2ff9e70d 100644 --- a/ballerina/block_stream.bal +++ b/ballerina/block_stream.bal @@ -18,14 +18,13 @@ import ballerina/jballerina.java; # The read-only byte array that is used to read the byte content from the streams. public type Block readonly & byte[]; -# The `BlockStream` is used to initialize a stream of type `Block`. This `BlockStream` refers to the stream that is embedded to -# the I/O byte channels. +# A stream of `Block` objects that is used to read the byte content from the streams. public class BlockStream { private ReadableByteChannel readableByteChannel; private int blockSize; private boolean isClosed = false; - # Initialize a `BlockStream` using an `io:ReadableByteChannel`. + # Initializes a stream of `Block` objects. # # + readableByteChannel - The `io:ReadableByteChannel` that this block stream is referred to # + blockSize - The size of a block as an integer @@ -34,9 +33,9 @@ public class BlockStream { self.blockSize = blockSize; } - # The next function reads and returns the next block of the related stream. + # Reads the next block of the stream. # - # + return - An `io:Block` when a block is avaliable in the stream or returns `()` when the stream reaches the end + # + return - An `io:Block` when a block is available in the stream or returns `()` when the stream reaches the end public isolated function next() returns record {|Block value;|}|Error? { byte[]|Error block = readBlock(self.readableByteChannel, self.blockSize); if block is byte[] { @@ -49,8 +48,8 @@ public class BlockStream { } } - # Closes the stream. The primary usage of this function is to close the stream without reaching the end - # If the stream reaches the end, the `BlockStream.next()` will automatically close the stream. + # Closes the stream manually. + # If not invoked, the stream closes automatically upon reaching end-of-stream. # # + return - `()` when the closing was successful or an `io:Error` public isolated function close() returns Error? { diff --git a/ballerina/constants.bal b/ballerina/constants.bal index 85b591d5..41082754 100644 --- a/ballerina/constants.bal +++ b/ballerina/constants.bal @@ -14,7 +14,7 @@ // specific language governing permissions and limitations // under the License. -# The format, which will be used to represent the CSV. +# Specifies the format used to represent CSV data. # # DEFAULT - The default value is the format specified by the CSVChannel. Precedence will be given to the field # separator and record separator. diff --git a/ballerina/csv_stream.bal b/ballerina/csv_stream.bal index 3148f61d..584aaba6 100644 --- a/ballerina/csv_stream.bal +++ b/ballerina/csv_stream.bal @@ -15,22 +15,21 @@ // under the License. import ballerina/jballerina.java; -# The `io:CSVStream` is used to initialize a stream of type CSV records. This `io:CSVStream` refers to the stream -# that is embedded to the I/O record channels. +# A stream of CSV records that is used to read the CSV content from the streams. public class CSVStream { private ReadableTextRecordChannel readableTextRecordChannel; private boolean isClosed = false; - # Initialize a `CSVStream` using an `io:ReadableTextRecordChannel`. + # Initializes a stream of CSV records. # # + readableTextRecordChannel - The `io:ReadableTextRecordChannel` that this CSV stream is referred to public isolated function init(ReadableTextRecordChannel readableTextRecordChannel) { self.readableTextRecordChannel = readableTextRecordChannel; } - # The next function reads and returns the next CSV record of the related stream. + # Reads the next CSV record of the stream. # - # + return - A CSV record as a string array when a record is avaliable in the stream or + # + return - A CSV record as a string array when a record is available in the stream or # `()` when the stream reaches the end public isolated function next() returns record {|string[] value;|}|Error? { var recordValue = readRecord(self.readableTextRecordChannel); @@ -45,8 +44,8 @@ public class CSVStream { } } - # Close the stream. The primary usage of this function is to close the stream without reaching the end. - # If the stream reaches the end, the `CSVStream.next()` will automatically close the stream. + # Closes the stream manually. + # If not invoked, the stream closes automatically upon reaching end-of-stream. # # + return - `()` when the closing was successful or an `io:Error` public isolated function close() returns Error? { diff --git a/ballerina/file_byte_io.bal b/ballerina/file_byte_io.bal index 20749173..1959d349 100644 --- a/ballerina/file_byte_io.bal +++ b/ballerina/file_byte_io.bal @@ -14,21 +14,21 @@ // specific language governing permissions and limitations // under the License. -# Read the entire file content as a byte array. +# Reads the entire file content as a byte array. # ```ballerina # byte[]|io:Error content = io:fileReadBytes("./resources/myfile.txt"); # ``` -# + path - The path of the file +# + path - The file path # + return - A read-only byte array or an `io:Error` public isolated function fileReadBytes(string path) returns readonly & byte[]|Error { return channelReadBytes(check openReadableFile(path)); } -# Read the entire file content as a stream of blocks. +# Reads the entire file content as a stream of blocks. # ```ballerina # stream|io:Error content = io:fileReadBlocksAsStream("./resources/myfile.txt", 1000); # ``` -# + path - The path of the file +# + path - The file path # + blockSize - An optional size of the byte block. The default size is 4KB # + return - A byte block stream or an `io:Error` public isolated function fileReadBlocksAsStream(string path, int blockSize = 4096) returns stream| @@ -36,30 +36,30 @@ Error { return channelReadBlocksAsStream(check openReadableFile(path), blockSize); } -# Write a set of bytes to a file. +# Writes a set of bytes to a file. # ```ballerina # byte[] content = [60, 78, 39, 28]; # io:Error? result = io:fileWriteBytes("./resources/myfile.txt", content); # ``` -# + path - The path of the file +# + path - The file path # + content - Byte content to write -# + option - To indicate whether to overwrite or append the given content -# + return - An `io:Error` or else `()` +# + option - Indicate whether to overwrite or append the given content +# + return - An `io:Error` if the write operation fails, or () public isolated function fileWriteBytes(string path, byte[] content, FileWriteOption option = OVERWRITE) returns Error? { return channelWriteBytes(check openWritableFile(path, option), content); } -# Write a byte stream to a file. +# Writes a byte stream to a file. # ```ballerina # byte[] content = [[60, 78, 39, 28]]; # stream byteStream = content.toStream(); # io:Error? result = io:fileWriteBlocksFromStream("./resources/myfile.txt", byteStream); # ``` -# + path - The path of the file +# + path - The file path # + byteStream - Byte stream to write -# + option - To indicate whether to overwrite or append the given content -# + return - An `io:Error` or else `()` +# + option - Indicate whether to overwrite or append the given content +# + return - An `io:Error` if the write operation fails, or () public isolated function fileWriteBlocksFromStream(string path, stream byteStream, FileWriteOption option = OVERWRITE) returns Error? { return channelWriteBlocksFromStream(check openWritableFile(path, option), byteStream); diff --git a/ballerina/file_csv_io.bal b/ballerina/file_csv_io.bal index c23ffdd1..ba447cfc 100644 --- a/ballerina/file_csv_io.bal +++ b/ballerina/file_csv_io.bal @@ -15,7 +15,7 @@ // under the License. import ballerina/jballerina.java; -# Read file content as a CSV. +# Reads file content as a CSV. # When the expected data type is record[], the first entry of the csv file should contain matching headers. # ```ballerina # string[][]|io:Error content = io:fileReadCsv("./resources/myfile.csv"); @@ -30,9 +30,8 @@ public isolated function fileReadCsv(string path, int skipHeaders = 0, typedesc< 'class: "io.ballerina.stdlib.io.nativeimpl.CsvChannelUtils" } external; -# Read file content as a CSV. -# When the expected data type is stream, -# the first entry of the csv file should contain matching headers. +# Reads file content as a CSV. +# When the expected data type is stream, the first entry of the csv file should contain matching headers. # ```ballerina # stream|io:Error content = io:fileReadCsvAsStream("./resources/myfile.csv"); @@ -45,9 +44,9 @@ public isolated function fileReadCsvAsStream(string path, typedesc[] content, FileWriteOption option = OVERWRITE) returns Error? { return channelWriteCsv(path, option, content); } -# Write CSV record stream to a file. -# When the input is a `stream` in `OVERWRITE`, headers will be written to the CSV file by default. -# For `APPEND`, order of the existing csv file is inferred using the headers and used as the order. +# Writes CSV record stream to a file. +# When the input is a `stream` in `OVERWRITE`, headers will be written to the CSV file. +# For `APPEND`, order of the existing csv file is inferred using the headers. # ```ballerina # type Coord record {int x;int y;}; # Coord[] contentRecord = [{x: 1,y: 2},{x: 1,y: 2}] @@ -78,7 +77,7 @@ Error? { # ``` # + path - The CSV file path # + content - A CSV record stream to be written -# + option - To indicate whether to overwrite or append the given content +# + option - Indicate whether to overwrite or append the given content # + return - `()` when the writing was successful or an `io:Error` public isolated function fileWriteCsvFromStream(string path, stream, Error?> content, FileWriteOption option = OVERWRITE) returns Error? { diff --git a/ballerina/file_string_io.bal b/ballerina/file_string_io.bal index f372d5ee..b0adc429 100644 --- a/ballerina/file_string_io.bal +++ b/ballerina/file_string_io.bal @@ -19,7 +19,7 @@ # ```ballerina # string|io:Error content = io:fileReadString("./resources/myfile.txt"); # ``` -# + path - The path of the file +# + path - The file path # + return - The entire file content as a string or an `io:Error` public isolated function fileReadString(string path) returns string|Error { return channelReadString(check openReadableFile(path)); @@ -30,8 +30,8 @@ public isolated function fileReadString(string path) returns string|Error { # ```ballerina # string[]|io:Error content = io:fileReadLines("./resources/myfile.txt"); # ``` -# + path - The path of the file -# + return - The file as list of lines or an `io:Error` +# + path - The file path +# + return - The file content as a string array or an `io:Error` public isolated function fileReadLines(string path) returns string[]|Error { return channelReadLines(check openReadableFile(path)); } @@ -41,7 +41,7 @@ public isolated function fileReadLines(string path) returns string[]|Error { # ```ballerina # stream|io:Error content = io:fileReadLinesAsStream("./resources/myfile.txt"); # ``` -# + path - The path of the file +# + path - The file path # + return - The file content as a stream of strings or an `io:Error` public isolated function fileReadLinesAsStream(string path) returns stream|Error { return channelReadLinesAsStream(check openReadableFile(path)); @@ -51,7 +51,7 @@ public isolated function fileReadLinesAsStream(string path) returns stream lineStream = content.toStream(); # io:Error? result = io:fileWriteLinesFromStream("./resources/myfile.txt", lineStream); # ``` -# + path - The path of the file +# + path - The file path # + lineStream - A stream of lines to write -# + option - To indicate whether to overwrite or append the given content +# + option - Indicate whether to overwrite or append the given content # + return - `()` when the writing was successful or an `io:Error` public isolated function fileWriteLinesFromStream(string path, stream lineStream, FileWriteOption option = OVERWRITE) returns Error? { return channelWriteLinesFromStream(check openWritableFile(path, option), lineStream); } -# Write a JSON to a file. +# Writes a JSON to a file. # ```ballerina # json content = {"name": "Anne", "age": 30}; # io:Error? result = io:fileWriteJson("./resources/myfile.json", content); # ``` -# + path - The path of the JSON file +# + path - The JSON file path # + content - JSON content to write # + return - `()` when the writing was successful or an `io:Error` public isolated function fileWriteJson(string path, json content) returns Error? { return channelWriteJson(check openWritableFile(path), content); } -# Write XML content to a file. +# Writes XML content to a file. # ```ballerina # xml content = xml `The Lost World`; # io:Error? result = io:fileWriteXml("./resources/myfile.xml", content); # ``` -# + path - The path of the XML file +# + path - The XML file path # + content - XML content to write # + xmlOptions - XML writing options (XML entity type and DOCTYPE) # + fileWriteOption - File write option (`OVERWRITE` and `APPEND` are the possible values and the default value is `OVERWRITE`) diff --git a/ballerina/line_stream.bal b/ballerina/line_stream.bal index 3a1d72ff..bff7e414 100644 --- a/ballerina/line_stream.bal +++ b/ballerina/line_stream.bal @@ -15,22 +15,21 @@ // under the License. import ballerina/jballerina.java; -# The `io:LineStream` is used to initialize a stream of the type strings(lines). This `io:LineStream` refers to the -# stream that is embedded to the I/O character channels. +# A stream of strings(lines) that is used to read the character content from the streams. public class LineStream { private ReadableCharacterChannel readableCharacterChannel; private boolean isClosed = false; - # Initialize an `io:LineStream` using an `io:ReadableCharacterChannel`. + # Initializes A stream of strings(lines). # # + readableCharacterChannel - The `io:ReadableCharacterChannel` that the line stream is referred to public isolated function init(ReadableCharacterChannel readableCharacterChannel) { self.readableCharacterChannel = readableCharacterChannel; } - # The next function reads and returns the next line of the related stream. + # Reads the next line of the stream. # - # + return - A line as a string when a line is avaliable in the stream or returns `()` when the stream reaches the end + # + return - A line as a string when a line is available in the stream or returns `()` when the stream reaches the end public isolated function next() returns record {|string value;|}|Error? { var line = readLine(self.readableCharacterChannel); if line is string { @@ -44,8 +43,8 @@ public class LineStream { } } - # Closes the stream. The primary usage of this function is to close the stream without reaching the end - # If the stream reaches the end, the `LineStream.next()` will automatically close the stream. + # Closes the stream manually. + # If not invoked, the stream closes automatically upon reaching end-of-stream. # # + return - `()` when the closing was successful or an `io:Error` public isolated function close() returns Error? { diff --git a/ballerina/open.bal b/ballerina/open.bal index cea7be90..7d3a8562 100644 --- a/ballerina/open.bal +++ b/ballerina/open.bal @@ -15,25 +15,25 @@ // under the License. import ballerina/jballerina.java; -# Retrieves a `ReadableByteChannel` from a given file path. +# Retrieves a readable byte channel from a given file path. # ```ballerina # io:ReadableByteChannel readableFieldResult = check io:openReadableFile("./files/sample.txt"); # ``` # -# + path - Relative/absolute path string to locate the file +# + path - The relative or absolute file path # + return - The `io:ReadableByteChannel` related to the given file or else an `io:Error` if there is an error while opening public isolated function openReadableFile(string path) returns ReadableByteChannel|Error = @java:Method { name: "openReadableFile", 'class: "io.ballerina.stdlib.io.nativeimpl.ByteChannelUtils" } external; -# Retrieves a `WritableByteChannel` from a given file path. +# Retrieves a writable byte channel from a given file path. # ```ballerina # io:WritableByteChannel writableFileResult = check io:openWritableFile("./files/sampleResponse.txt"); # ``` # -# + path - Relative/absolute path string to locate the file -# + option - To indicate whether to overwrite or append the given content +# + path - The relative or absolute file path +# + option - Indicate whether to overwrite or append the given content # + return - The `io:WritableByteChannel` related to the given file or else an `io:Error` if any error occurred public isolated function openWritableFile(string path, FileWriteOption option = OVERWRITE) returns WritableByteChannel|Error = @java:Method { @@ -46,7 +46,7 @@ WritableByteChannel|Error = @java:Method { # var byteChannel = io:createReadableChannel(content); # ``` # -# + content - Content, which should be exposed as a channel +# + content - The content as a byte array, which should be exposed as a channel # + return - The `io:ReadableByteChannel` related to the given bytes or else an `io:Error` if any error occurred public isolated function createReadableChannel(byte[] content) returns ReadableByteChannel|Error = @java:Method { name: "createReadableChannel", @@ -58,9 +58,9 @@ public isolated function createReadableChannel(byte[] content) returns ReadableB # io:ReadableCSVChannel rCsvChannel = check io:openReadableCsvFile(srcFileName); # ``` # -# + path - File path, which describes the location of the CSV +# + path - The CSV file path # + fieldSeparator - CSV record separator (i.e., comma or tab) -# + charset - Representation of the encoding characters in the file +# + charset - The character encoding used to read the file # + skipHeaders - Number of headers, which should be skipped # + return - The `io:ReadableCSVChannel`, which could be used to iterate through the CSV records or else an `io:Error` if any error occurred public isolated function openReadableCsvFile(string path, Separator fieldSeparator = ",", @@ -76,11 +76,11 @@ ReadableCSVChannel|Error { # io:WritableCSVChannel wCsvChannel = check io:openWritableCsvFile(srcFileName); # ``` # -# + path - File path, which describes the location of the CSV +# + path - The CSV file path # + fieldSeparator - CSV record separator (i.e., comma or tab) -# + charset - Representation of the encoding characters in the file +# + charset - The character encoding used to read the file # + skipHeaders - Number of headers, which should be skipped -# + option - To indicate whether to overwrite or append the given content +# + option - Indicate whether to overwrite or append the given content # + return - The `io:WritableCSVChannel`, which could be used to write the CSV records or else an `io:Error` if any error occurred public isolated function openWritableCsvFile(string path, Separator fieldSeparator = ",", string charset = "UTF-8", int skipHeaders = 0, diff --git a/ballerina/options.bal b/ballerina/options.bal index 841ecac9..8511e2df 100644 --- a/ballerina/options.bal +++ b/ballerina/options.bal @@ -43,7 +43,7 @@ public type XmlDoctype record {| string? internalSubset = (); |}; -# The writing options of an XML. +# Represents the writing options of an XML. # # + xmlEntityType - The entity type of the XML input (the default value is `DOCUMENT_ENTITY`) # + doctype - XML DOCTYPE value (the default value is `()`) diff --git a/ballerina/print.bal b/ballerina/print.bal index 27d2245b..a9968b52 100644 --- a/ballerina/print.bal +++ b/ballerina/print.bal @@ -36,7 +36,7 @@ public type PrintableRawTemplate object { public Printable[] insertions; }; -# Prints `any`, `error`, or string templates (such as `The respective int value is ${val}`) value(s) to the `STDOUT`. +# Prints `any`, `error`, or string template value(s) to the standard output stream. # ```ballerina # io:print("Start processing the CSV file from ", srcFileName); # ``` @@ -50,8 +50,7 @@ public isolated function print(Printable... values) { externPrint(stdout, ...printables); } -# Prints `any`, `error` or string templates(such as `The respective int value is ${val}`) value(s) to the STDOUT -# followed by a new line. +# Prints `any`, `error` or string templates value(s) to the standard output stream and terminates the line. # ```ballerina # io:println("Start processing the CSV file from ", srcFileName); # ``` @@ -65,8 +64,7 @@ public isolated function println(Printable... values) { externPrintln(stdout, ...printables); } -# Prints `any`, `error`, or string templates(such as `The respective int value is ${val}`) value(s) to -# a given stream(STDOUT or STDERR). +# Prints `any`, `error`, or string templates value(s) to a given stream(STDOUT or STDERR). # ```ballerina # io:fprint(io:stderr, "Unexpected error occurred"); # ``` @@ -80,8 +78,7 @@ public isolated function fprint(FileOutputStream fileOutputStream, Printable... externPrint(fileOutputStream, ...printables); } -# 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. +# Prints `any`, `error`, or string templates value(s) to a given stream(STDOUT or STDERR) and terminates the line. # ```ballerina # io:fprintln(io:stderr, "Unexpected error occurred"); # ``` diff --git a/ballerina/read.bal b/ballerina/read.bal index b5464112..54297a0d 100644 --- a/ballerina/read.bal +++ b/ballerina/read.bal @@ -16,13 +16,14 @@ import ballerina/jballerina.java; -# Retrieves the input read from the STDIN. +# Reads a line of input from the standard input (STDIN). +# If an argument is provided, it will be printed as a prompt before reading the input. # ```ballerina # string choice = io:readln("Enter choice 1 - 5: "); # string choice = io:readln(); # ``` # -# + a - Any value to be printed +# + a - An optional value to be printed before reading the input # + return - Input read from the STDIN public function readln(any? a = ()) returns string = @java:Method { name: "readln", diff --git a/ballerina/readable_byte_channel.bal b/ballerina/readable_byte_channel.bal index 673e5265..92eac2fa 100644 --- a/ballerina/readable_byte_channel.bal +++ b/ballerina/readable_byte_channel.bal @@ -15,9 +15,8 @@ // under the License. import ballerina/jballerina.java; -# ReadableByteChannel represents an input resource (i.e file), which could be used to source bytes. +# Represents a readable byte channel that represents an input resource (i.e file), which could be used to source bytes. # A file path or an in-memory `byte` array can be used to obtain an `io:ReadableByteChannel`. -# An `io:ReadableByteChannel` does not support initialization, and it should be obtained using the following methods or implemented natively. # # `io:openReadableFile("./files/sample.txt")` - used to obtain an `io:ReadableByteChannel` from a given file path # `io:createReadableChannel(byteArray)` - used to obtain an `io:ReadableByteChannel` from a given `byte` array @@ -27,20 +26,20 @@ public class ReadableByteChannel { isolated function init() { } - # Source bytes from a given input resource. + # Reads bytes from a given input resource. # This operation will be asynchronous in which the total number of required bytes might not be returned at a given # time. An `io:EofError` will return once the channel reaches the end. # ```ballerina # byte[]|io:Error result = readableByteChannel.read(1000); # ``` # - # + nBytes - A positive integer. Represents the number of bytes, which should be read + # + nBytes - Represents the number of bytes, which should be read. This should be a positive integer. # + return - Content (the number of bytes) read, an `EofError` once the channel reaches the end or else an `io:Error` public isolated function read(int nBytes) returns byte[]|Error { return byteReadExtern(self, nBytes); } - # Read all content of the channel as a `byte` array and return a read only `byte` array. + # Reads all content of the channel as a `byte` array and return a read only `byte` array. # ```ballerina # byte[]|io:Error result = readableByteChannel.readAll(); # ``` @@ -51,11 +50,11 @@ public class ReadableByteChannel { return readResult.cloneReadOnly(); } - # Return a block stream that can be used to read all `byte` blocks as a stream. + # Returns a block stream that can be used to read all `byte` blocks as a stream. # ```ballerina # stream|io:Error result = readableByteChannel.blockStream(); # ``` - # + blockSize - A positive integer. Size of the block. + # + blockSize - The size of the block. This should be a positive integer. # + return - A block stream or else an `io:Error` public isolated function blockStream(int blockSize) returns stream|Error { BlockStream blockStream = new (self, blockSize); @@ -82,7 +81,7 @@ public class ReadableByteChannel { return base64DecodeExtern(self); } - # Closes the `io:ReadableByteChannel`. + # Closes the readable byte channel to release any underlying resources. # After a channel is closed, any further reading operations will cause an error. # ```ballerina # io:Error? err = readableByteChannel.close(); diff --git a/ballerina/readable_character_channel.bal b/ballerina/readable_character_channel.bal index 6715a0a5..7d9361b2 100644 --- a/ballerina/readable_character_channel.bal +++ b/ballerina/readable_character_channel.bal @@ -21,7 +21,7 @@ public class ReadableCharacterChannel { private ReadableByteChannel byteChannel; private string charset; - # Constructs an `io:ReadableCharacterChannel` from a given `io:ReadableByteChannel` and `Charset`. + # Initializes a readable character channel. # # + byteChannel - The `io:ReadableByteChannel`, which would be used to read the characters # + charset - The character set, which is used to encode/decode the given bytes to characters @@ -44,7 +44,7 @@ public class ReadableCharacterChannel { return readExtern(self, numberOfChars); } - # Read the entire channel content as a string. + # Reads the entire channel content as a string. # ```ballerina # string|io:Error content = readableCharChannel.readString(); # ``` @@ -53,7 +53,7 @@ public class ReadableCharacterChannel { return readAllAsStringExtern(self); } - # Read the entire channel content as a list of lines. + # Reads the entire channel content as a list of lines. # ```ballerina # string[]|io:Error content = readableCharChannel.readAllLines(); # ``` @@ -82,18 +82,19 @@ public class ReadableCharacterChannel { return readXmlExtern(self); } - # Reads a property from a .properties file with a default value. + # Reads the value of a specified property key from a properties file. + # If the key is not found, the provided default value is returned. # ```ballerina # string|io:Error result = readableCharChannel.readProperty(key, defaultValue); # ``` - # + key - The property key, which needs to be read - # + defaultValue - The default value to be returned + # + key - The property key to look up in the properties file + # + defaultValue - The default value to return if the key is not found # + return - The property value related to the given key or else an `io:Error` public isolated function readProperty(string key, string defaultValue = "") returns string|Error { return readPropertyExtern(self, key, defaultValue); } - # Return a stream of lines that can be used to read all the lines in a file as a stream. + # Returns a stream of lines that can be used to read all the lines in a file as a stream. # ```ballerina # stream|io:Error? result = readableCharChannel.lineStream(); # ``` @@ -104,7 +105,7 @@ public class ReadableCharacterChannel { return new stream(lineStream); } - # Reads all properties from a .properties file. + # Reads all properties from a properties file. # ```ballerina # map|io:Error result = readableCharChannel.readAllProperties(); # ``` diff --git a/ballerina/readable_csv_channel.bal b/ballerina/readable_csv_channel.bal index d397982c..44c3ba92 100644 --- a/ballerina/readable_csv_channel.bal +++ b/ballerina/readable_csv_channel.bal @@ -15,14 +15,14 @@ // under the License. import ballerina/jballerina.java; -# Represents a ReadableCSVChannel which could be used to read records from CSV file. +# Represents a readable CSV channel which could be used to read records from CSV file. public class ReadableCSVChannel { private ReadableTextRecordChannel? dc; - # Constructs a CSV channel from a CharacterChannel to read CSV records. + # Initializes a readable CSV channel. # - # + byteChannel - The CharacterChannel, which will represent the content in the CSV file - # + fs - Field separator, which will separate between the records in the CSV file + # + byteChannel - The `io:ReadableCharacterChannel`, which will represent the content in the CSV file + # + fs - The field separator, which will separate between the records in the CSV file # + nHeaders - Number of headers, which should be skipped prior to reading records public isolated function init(ReadableCharacterChannel byteChannel, Separator fs = ",", int nHeaders = 0) { if fs == TAB { @@ -56,12 +56,12 @@ public class ReadableCSVChannel { } } - # Indicates whether there's another record, which could be read. + # Checks if there is another record available to be read from the CSV channel. # ```ballerina # boolean hasNext = readableCSVChannel.hasNext(); # ``` # - # + return - True if there is a record + # + return - True if there is another record available public isolated function hasNext() returns boolean { var recordChannel = self.dc; if recordChannel is ReadableTextRecordChannel { @@ -103,7 +103,7 @@ public class ReadableCSVChannel { } } - # Closes the `io:ReadableCSVChannel`. + # Closes the readable CSV channel to release any underlying resources. # After a channel is closed, any further reading operations will cause an error. # ```ballerina # io:Error? err = readableCSVChannel.close(); diff --git a/ballerina/readable_data_channel.bal b/ballerina/readable_data_channel.bal index 40e23e50..e8d3e56c 100644 --- a/ballerina/readable_data_channel.bal +++ b/ballerina/readable_data_channel.bal @@ -18,10 +18,10 @@ import ballerina/jballerina.java; # Represents a data channel for reading data. public class ReadableDataChannel { - # Initializes the data channel. + # Initializes a readable data channel. # - # + byteChannel - The channel, which would represent the source to read/write data - # + bOrder - Network byte order + # + byteChannel - The `io:ReadableByteChannel` channel, which would represent the source to read/write data + # + bOrder - The byte order used for reading data. Defaults to `"BE"` (Big Endian) public isolated function init(ReadableByteChannel byteChannel, ByteOrder bOrder = "BE") { // Remove temp once this got fixed #19842 string temp = bOrder; @@ -83,7 +83,7 @@ public class ReadableDataChannel { # boolean|io:Error result = dataChannel.readBool(); # ``` # - # + return - Boolean value, which is read or else `io:Error` if any error occurred + # + return - The boolean value read from the data channel, or an `io:Error` if an error occurs public isolated function readBool() returns boolean|Error { return readBoolExtern(self); } @@ -93,9 +93,9 @@ public class ReadableDataChannel { # string|io:Error string = dataChannel.readString(10, "UTF-8"); # ``` # - # + nBytes - Specifies the number of bytes, which represents the string - # + encoding - Specifies the char-set encoding of the string - # + return - The value of the string or else `io:Error` if any error occurred + # + nBytes - The number of bytes to read from the data channel to construct the string + # + encoding - The character encoding to use for decoding the bytes into a string (e.g., "UTF-8") + # + return - The string value read from the data channel, or an `io:Error` if an error occurs public isolated function readString(int nBytes, string encoding) returns string|Error { return readStringExtern(self, nBytes, encoding); } @@ -105,7 +105,7 @@ public class ReadableDataChannel { # int|io:Error result = dataChannel.readVarInt(); # ``` # - # + return - The value of the integer which is read or else `io:Error` if any error occurred + # + return - The variable-length integer value read from the data channel, or an `io:Error` if an error occurs public isolated function readVarInt() returns int|Error { return readVarIntExtern(self); } diff --git a/ballerina/readable_record_channel.bal b/ballerina/readable_record_channel.bal index 41485d66..d6095950 100644 --- a/ballerina/readable_record_channel.bal +++ b/ballerina/readable_record_channel.bal @@ -15,18 +15,18 @@ // under the License. import ballerina/jballerina.java; -# Represents a channel which will allow to read. +# Represents a readable record channel. public class ReadableTextRecordChannel { private ReadableCharacterChannel charChannel; private string rs; private string fs; - # Constructs a ReadableTextRecordChannel from a given ReadableCharacterChannel. + # Initializes a readable text record channel. # - # + charChannel - CharacterChannel which will point to the input/output resource - # + fs - Field separator (this could be a regex) - # + rs - Record separator (this could be a regex) + # + charChannel - The `io:ReadableCharacterChannel` which will point to the input/output resource + # + fs - The field separator (this could be a regex) + # + rs - The record separator (this could be a regex) public isolated function init(ReadableCharacterChannel charChannel, string fs = "", string rs = "", string fmt = "default") { self.charChannel = charChannel; @@ -45,7 +45,7 @@ public class ReadableTextRecordChannel { return hasNextExtern(self); } - # Get the next record from the input/output resource. + # Reads the next record from the input/output resource. # ```ballerina # string[]|io:Error record = readableRecChannel.getNext(); # ``` diff --git a/ballerina/writable_byte_channel.bal b/ballerina/writable_byte_channel.bal index ff06da52..3726bd55 100644 --- a/ballerina/writable_byte_channel.bal +++ b/ballerina/writable_byte_channel.bal @@ -15,10 +15,9 @@ // under the License. import ballerina/jballerina.java; -# WritableByteChannel represents an output resource (i.e file) which could be used to sink bytes +# Represents a writable byte channel that acts as an output resource (e.g., a file) for writing bytes. # A file path can be used to obtain an `io:WritableByteChannel`. -# An `io:WritableByteChannel` can only be obtained using the following method or by providing a native implementation. -# It cannot be instantiated. +# # `io:openWritableFile("./files/sample.txt")` - used to obtain an `io:WritableByteChannel` from a given file path public class WritableByteChannel { diff --git a/ballerina/writable_character_channel.bal b/ballerina/writable_character_channel.bal index e316996c..e8b0d8b4 100644 --- a/ballerina/writable_character_channel.bal +++ b/ballerina/writable_character_channel.bal @@ -15,13 +15,13 @@ // under the License. import ballerina/jballerina.java; -# Represents a channel which could be used to write characters through a given WritableCharacterChannel. +# Represents a writable character channel used for writing characters. public class WritableCharacterChannel { private WritableByteChannel bChannel; private string charset; - # Constructs an `io:WritableByteChannel` from a given `io:WritableByteChannel` and `Charset`. + # Initializes a writable character channel. # # + bChannel - The `io:WritableByteChannel`, which would be used to write the characters # + charset - The character set, which would be used to encode the given bytes to characters @@ -31,24 +31,24 @@ public class WritableCharacterChannel { initWritableCharacterChannel(self, bChannel, charset); } - # Writes a given sequence of characters (string). + # Writes a sequence of characters (string) to the writable character channel. # ```ballerina # int|io:Error result = writableCharChannel.write("Content", 0); # ``` # - # + content - Content to be written - # + startOffset - Number of characters to be offset when writing the content - # + return - Content length that written or else an `io:Error` + # + content - The string content to be written + # + startOffset - The number of characters to skip from the beginning of the content before writing + # + return - The number of characters written to the channel, or an `io:Error` if an error occurs public isolated function write(string content, int startOffset) returns int|Error { return writeExtern(self, content, startOffset); } - # Writes a string as a line with a following newline character `\n`. + # Writes a string as a line followed by a newline character (`\n`) to the writable character channel. # ```ballerina # io:Error? result = writableCharChannel.writeLine("Content"); # ``` # - # + content - Content to be written + # + content - The string content to be written # + return - `()` if the writing was successful or an `io:Error` public isolated function writeLine(string content) returns Error? { string lineContent = content + NEW_LINE; @@ -59,24 +59,24 @@ public class WritableCharacterChannel { return; } - # Writes a given JSON to the given channel. + # Writes the provided JSON content to the writable character channel. # ```ballerina # io:Error? err = writableCharChannel.writeJson(inputJson, 0); # ``` # - # + content - The JSON to be written + # + content - The JSON content to be written # + return - `()` if the writing was successful or an `io:Error` public isolated function writeJson(json content) returns Error? { return writeJsonExtern(self, content); } - # Writes a given XML to the channel. + # Writes the provided XML content to the writable character channel. # ```ballerina # io:Error? err = writableCharChannel.writeXml(inputXml, 0); # ``` # - # + content - The XML to be written - # + xmlDoctype - Optional argument to specify the XML DOCTYPE configurations + # + content - The XML content to be written + # + xmlDoctype - An optional argument to specify the XML DOCTYPE configurations for the XML content # + return - `()` or else an `io:Error` if any error occurred public isolated function writeXml(xml content, XmlDoctype? xmlDoctype = ()) returns Error? { string doctype = ""; @@ -86,18 +86,18 @@ public class WritableCharacterChannel { return writeXmlExtern(self, content, doctype); } - # Writes a given key-valued pair `map` to a property file. + # Writes a key-value pair map (`map`) to a property file. # ```ballerina # io:Error? err = writableCharChannel.writeProperties(properties); # ``` # + properties - The map that contains keys and values - # + comment - Comment describing the property list + # + comment - A comment describing the property list to be included # + return - `()` or else an `io:Error` if any error occurred public isolated function writeProperties(map properties, string comment) returns Error? { return writePropertiesExtern(self, properties, comment); } - # Closes the `io:WritableCharacterChannel`. + # Closes the character channel. # After a channel is closed, any further writing operations will cause an error. # ```ballerina # io:Error err = writableCharChannel.close(); diff --git a/ballerina/writable_csv_channel.bal b/ballerina/writable_csv_channel.bal index 48f02421..487b8b87 100644 --- a/ballerina/writable_csv_channel.bal +++ b/ballerina/writable_csv_channel.bal @@ -23,14 +23,14 @@ public const string FS_COLON = ":"; # Represents the minimum number of headers, which will be included in the CSV. public const int MINIMUM_HEADER_COUNT = 0; -# Represents a WritableCSVChannel, which could be used to write records from the CSV file. +# Represents a writable CSV channel, which could be used to write records from the CSV file. public class WritableCSVChannel { private WritableTextRecordChannel? dc; - # Constructs a CSV channel from a `CharacterChannel` to read/write CSV records. + # Initializes a writable CSV channel. # - # + CharacterChannel - The `CharacterChannel`, which will represent the content in the CSV file - # + fs - Field separator, which will separate the records in the CSV + # + CharacterChannel - The `io:WritableCharacterChannel`, which will represent the content in the CSV file + # + fs - The field separator, which will separate the records in the CSV public isolated function init(WritableCharacterChannel characterChannel, Separator fs = ",") { if fs == TAB { self.dc = new WritableTextRecordChannel(characterChannel, fmt = "TDF"); @@ -58,7 +58,7 @@ public class WritableCSVChannel { return; } - # Closes the `io:WritableCSVChannel`. + # Closes the writable CSV channel. # After a channel is closed, any further writing operations will cause an error. # ```ballerina # io:Error? err = csvChannel.close(); diff --git a/ballerina/writable_data_channel.bal b/ballerina/writable_data_channel.bal index 90054fcf..50a37eeb 100644 --- a/ballerina/writable_data_channel.bal +++ b/ballerina/writable_data_channel.bal @@ -28,104 +28,104 @@ public const BIG_ENDIAN = "BE"; # Specifies the byte order to be the least significant byte first. public const LITTLE_ENDIAN = "LE"; -# Represents a WritableDataChannel for writing data. +# Represents a writable data channel used for writing various types of data. public class WritableDataChannel { - # Initializes data channel. + # Initializes a writable data channel. # - # + byteChannel - Channel, which would represent the source to read/write data - # + bOrder - Network byte order + # + byteChannel - The `io:WritableByteChannel`, which would represent the source to read/write data + # + bOrder - The network byte order, which specifies the order of bytes (e.g., `io:BIG_ENDIAN` or `io:LITTLE_ENDIAN`) public isolated function init(WritableByteChannel byteChannel, ByteOrder bOrder = "BE") { // Remove temp once this got fixed #19842 string temp = bOrder; initWritableDataChannel(self, byteChannel, temp); } - # Writes a 16 bit integer. + # Writes a 16 bit integer value to the writable data channel. # ```ballerina # io:Error? err = dataChannel.writeInt16(length); # ``` # - # + value - The integer, which will be written + # + value - The 16-bit integer value to be written to the data channel # + return - `()` if the content is written successfully or else an `io:Error` if any error occurred public isolated function writeInt16(int value) returns Error? { return writeInt16Extern(self, value); } - # Writes a 32 bit integer. + # Writes a 32 bit integer value to the writable data channel. # ```ballerina # io:Error? err = dataChannel.writeInt32(length); # ``` # - # + value - The integer, which will be written + # + value - The 32-bit integer value to be written to the data channel # + return - `()` if the content is written successfully or else an `io:Error` if any error occurred public isolated function writeInt32(int value) returns Error? { return writeInt32Extern(self, value); } - # Writes a 64 bit integer. + # Writes a 64 bit integer value to the writable data channel. # ```ballerina # io:Error? err = dataChannel.writeInt64(length); # ``` # - # + value - The integer, which will be written + # + value - The 64-bit integer value to be written to the data channel # + return - `()` if the content is written successfully or else an `io:Error` if any error occurred public isolated function writeInt64(int value) returns Error? { return writeInt64Extern(self, value); } - # Writes a 32 bit float. + # Writes a 32 bit float value to the writable data channel. # ```ballerina # io:Error? err = dataChannel.writeFloat32(3.12); # ``` # - # + value - The float, which will be written + # + value - The 32-bit float value to be written to the data channel # + return - `()` if the float is written successfully or else an `io:Error` if any error occurred public isolated function writeFloat32(float value) returns Error? { return writeFloat32Extern(self, value); } - # Writes a 64 bit float. + # Writes a 64 bit float value to the writable data channel. # ```ballerina - # io:Error? err = dataChannel.writeFloat32(3.12); + # io:Error? err = dataChannel.writeFloat64(3.12); # ``` # - # + value - The float, which will be written + # + value - The 64-bit float value to be written to the data channel # + return - `()` if the float is written successfully or else an `io:Error` if any error occurred public isolated function writeFloat64(float value) returns Error? { return writeFloat64Extern(self, value); } - # Writes a boolean. + # Writes a boolean value to the writable data channel. # ```ballerina # io:Error? err = dataChannel.writeInt64(length); # ``` # - # + value - The boolean, which will be written + # + value - The boolean value to be written to the data channel # + return - `()` if the content is written successfully or else an `io:Error` if any error occurred public isolated function writeBool(boolean value) returns Error? { return writeBoolExtern(self, value); } - # Writes a given string value to the respective channel. + # Writes a string value to the writable data channel. # ```ballerina # io:Error? err = dataChannel.writeString(record); # ``` # - # + value - The value, which should be written + # + value - The string value to be written to the data channel # + encoding - The encoding, which will represent the value string # + return - `()` if the content is written successfully or else an `io:Error` if any error occurred public isolated function writeString(string value, string encoding) returns Error? { return writeStringExtern(self, value, encoding); } - # Writes a variable-length integer. + # Writes a variable-length integer to the writable data channel. # ```ballerina # io:Error? err = dataChannel.writeVarInt(length); # ``` # - # + value - The int, which will be written - # + return - The value of the integer, which is written or else an `io:Error` if any error occurred + # + value - The variable-length integer value to be written to the data channel + # + return - `()` if the integer is written successfully, or an `io:Error` if an error occurs public isolated function writeVarInt(int value) returns Error? { return writeVarIntExtern(self, value); } diff --git a/ballerina/writable_record_channel.bal b/ballerina/writable_record_channel.bal index 3ed5a9ed..a3457f1c 100644 --- a/ballerina/writable_record_channel.bal +++ b/ballerina/writable_record_channel.bal @@ -15,16 +15,16 @@ // under the License. import ballerina/jballerina.java; -# Represents a channel, which will allow to write records through a given WritableCharacterChannel. +# Represents a writable text record channel that allows writing records. public class WritableTextRecordChannel { private WritableCharacterChannel characterChannel; private string fs; private string rs; - # Constructs a DelimitedTextRecordChannel from a given WritableCharacterChannel. + # Initializes a writable text record channel. # + characterChannel - The `io:WritableCharacterChannel`, which will point to the input/output resource - # + fs - Field separator (this could be a regex) - # + rs - Record separator (this could be a regex) + # + fs - The field separator (this could be a regex) + # + rs - The record separator (this could be a regex) # + fmt - The format, which will be used to represent the CSV (this could be # "DEFAULT" (the format specified by the CSVChannel), # "CSV" (Field separator would be "," and record separator would be a new line) or else