ballerina.io package

public struct ByteChannel

Ballerina ByteChannel represents a channel which will allow I/O operations to be done

  • < ByteChannel > close ( )

    Function to close a byte channel

  • < ByteChannel > readAllBytes ( ) ( blob , int )

    Function to read all bytes in the given I/O source

    Return Variable Data Type Description
    blob all bytes read from the channel
    int Number of bytes read
  • < ByteChannel > readBytes ( int numberOfBytes ) ( blob , int )

    Function to read bytes

    Parameter Name Data Type Description
    numberOfBytes int Number of bytes which should be read

    Return Variable Data Type Description
    blob The bytes which were read
    int Number of bytes read
  • < ByteChannel > writeBytes ( blob content , int startOffset ) ( int )

    Function to write bytes

    Parameter Name Data Type Description
    content blob Bytes which should be written
    startOffset int If the bytes need to be written with an offset, the value of that offset

    Return Variable Data Type Description
    int Number of bytes written

public struct CharacterChannel

Ballerina CharacterChannel represents a channel which will allow to read/write characters

  • < CharacterChannel > closeCharacterChannel ( )

    Function to close a character channel

  • < CharacterChannel > readAllCharacters ( ) ( string )

    Function to read all characters in the give I/O source

    Return Variable Data Type Description
    string all characters read
  • < CharacterChannel > readCharacters ( int numberOfChars ) ( string )

    Function to read characters

    Parameter Name Data Type Description
    numberOfChars int Number of characters which should be read

    Return Variable Data Type Description
    string The character sequence which was read
  • < CharacterChannel > writeCharacters ( string content , int startOffset ) ( int )

    Function to write characters

    Parameter Name Data Type Description
    content string Text content which should be written
    startOffset int If the content needs to be written with an offset, the value of that offset

    Return Variable Data Type Description
    int Number of characters written

public struct DelimitedRecordChannel

Ballerina DelimitedRecordChannel represents a channel which will allow to read/write text records

  • < DelimitedRecordChannel > closeDelimitedRecordChannel ( )

    Function to close the text record channel

  • < DelimitedRecordChannel > hasNextTextRecord ( ) ( boolean )

    Function to check whether next record is available or not

    Return Variable Data Type Description
    boolean True if the channel has more records; false otherwise
  • < DelimitedRecordChannel > nextTextRecord ( ) ( string[] )

    Function to read text records

    Return Variable Data Type Description
    string[] Fields listed in the record
  • < DelimitedRecordChannel > writeTextRecord ( string[] records )

    Function to write text records

    Parameter Name Data Type Description
    records string[] Fields which are included in the record

public function createCharacterChannel ( ByteChannel byteChannel , string encoding ) ( CharacterChannel )

Function to create a CharacterChannel from ByteChannel

Parameter Name Data Type Description
byteChannel ByteChannel
encoding string The charset/encoding of the content (i.e UTF-8, ASCII)

Return Variable Data Type Description
CharacterChannel CharacterChannel converted from ByteChannel

public function createDelimitedRecordChannel ( CharacterChannel channel , string recordSeparator , string fieldSeparator ) ( DelimitedRecordChannel )

Function to create a CharacterChannel to DelimitedRecordChannel

Parameter Name Data Type Description
channel CharacterChannel The CharacterChannel to be converted
recordSeparator string Terminating expression to distinguish between records
fieldSeparator string Terminating expression to distinguish between fields

Return Variable Data Type Description
DelimitedRecordChannel DelimitedRecordChannel converted from CharacterChannel

public function openFile ( string path , string accessMode ) ( ByteChannel )

Function to return a ByteChannel related to the file. This ByteChannel can then be used to read/write from/to the file.

Parameter Name Data Type Description
path string The path of the file
accessMode string Specifies whether the file should be opened for reading or writing (r/w)

Return Variable Data Type Description
ByteChannel ByteChannel which will allow to perform I/O operations

public function print ( any a )

Prints a 'any' value to the STDOUT

Parameter Name Data Type Description
a any any value to be printed

public function println ( any a )

Prints an any value to the STDOUT in a new line

Parameter Name Data Type Description
a any any value to be printed