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 struct Socket

Represents a client socket connection. This can be used to communicate with a remote machine

Field Name Data Type Description Default Value
channel ByteChannel Connection stream that bridge the client and the server
port int Remote server port
localPort int Client side port that open for the communication
address string Remote server domain/IP
localAddress string Client domain/IP
  • < Socket > closeSocket ( )

    Close the socket connection with the remote server

public struct SocketProperties

SocketProperties structs represents the properties which are used to configure TCP connection

Field Name Data Type Description Default Value
localPort int Client side port that open for the communication

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 openSocket ( string host , int port , SocketProperties options ) ( Socket )

Represents a client socket connection. This can be used to communicate with a remote server

Parameter Name Data Type Description
host string Remote server domain/IP
port int Remote server port
options SocketProperties Connection stream that bridge the client and the server

Return Variable Data Type Description
Socket Socket which will allow to communicate with a remote server

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

public function sprintf ( string format , any[] args ) ( string )

Returns a formatted string using the specified format string and arguments

Parameter Name Data Type Description
format string Format specifier
args any[] Arguments to be formatted, should match number of args in format specifier

Return Variable Data Type Description
string Formatted string