ballerina/io package
Primitives Summary
Type | Description |
---|
Type Definitions
Type | Values | Description |
---|---|---|
Format | tdf | default | csv | |
Mode | w | rw | r | a | |
Seperator | : | , | |
Annotations
Name | Attachement Points | Data Type | Description |
---|
Objects Summary
Object | Description |
---|---|
SocketProperties |
|
Endpoints Summary
Endpoint | Description |
---|
Functions Summary
Return Type | Function and Description |
---|---|
CSVChannel | error | openCsvFile(string path) Function to create CSV channel to read CSV input |
ByteChannel | openFile(string path, Mode accessMode) Opens a byte channel from a specified file location |
Socket | error | openSecureSocket(string host, int port, SocketProperties options) Open a secure socket connection with a remote server |
Socket | error | openSocket(string host, int port, SocketProperties options) Opens a socket from a specified network location |
print() Prints a 'any' value to the STDOUT |
|
println() Prints an any value to the STDOUT in a new line |
|
string | readln(any a) Returns the input read from STDIN |
string | sprintf(string format) Returns a formatted string using the specified format string and arguments |
Global Variables
Name | Data Type | Description |
---|---|---|
APPEND | Mode | Describes access mode for append |
COLON | Seperator | Describes TDF format to open CSV |
COMMA | Seperator | Supported record formats of CSV |
READ | Mode | Permissions which will be used to open file |
RW | Mode | Describes acces mode for reading and writing |
TAB | Seperator | Describes RFC4180 format to open CSV |
WRITE | Mode | Describes access mode for writing |
public object SocketProperties
SocketProperties structs represents the properties which are used to configure TCP connection.
Field Name | Data Type | Default Value | Description |
---|---|---|---|
localPort | int | ||
keyStoreFile | string | ||
keyStorePassword | string | ||
trustStoreFile | string | ||
trustStorePassword | string | ||
certPassword | string | ||
sslEnabledProtocols | string | ||
ciphers | string | ||
sslProtocol | string |
public function openCsvFile(string path) returns (CSVChannel | error)
Function to create CSV channel to read CSV input
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
path | string | Specfies the path to the CSV file |
Return Type | Description | ||
---|---|---|---|
CSVChannel | error | DelimitedRecordChannel converted from CSV Channel |
public function openFile(string path, Mode accessMode) returns (ByteChannel)
Opens a byte channel from a specified file location
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
path | string | path to the file location | |
accessMode | Mode | whether the file should be opened for read,write or append |
Return Type | Description | ||
---|---|---|---|
ByteChannel | Channel which will allow to source/sink |
public function openSecureSocket(string host, int port, SocketProperties options) returns (Socket | error)
Open a secure socket connection with a remote server
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
host | string | Remote server domain/IP | |
port | int | Remote server port | |
options | SocketProperties | Connection stream that bridge the client and the server |
Return Type | Description | ||
---|---|---|---|
Socket | error | Socket which will allow to communicate with a remote server |
public function openSocket(string host, int port, SocketProperties options) returns (Socket | error)
Opens a socket from a specified network location
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
host | string | Remote server domain/IP | |
port | int | Remote server port | |
options | SocketProperties | Connection stream that bridge the client and the server |
Return Type | Description | ||
---|---|---|---|
Socket | error | Socket which will allow to communicate with a remote server |
public function print()
Prints a 'any' value to the STDOUT
public function println()
Prints an any value to the STDOUT in a new line
public function readln(any a) returns (string)
Returns the input read from STDIN
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
a | any | any value to be printed |
Return Type | Description | ||
---|---|---|---|
string |
public function sprintf(string format) returns (string)
Returns a formatted string using the specified format string and arguments
Parameter Name | Data Type | Default Value | Description |
---|---|---|---|
format | string | Format specifier |
Return Type | Description | ||
---|---|---|---|
string | Formatted string |
public type ByteChannel object
Ballerina ByteChannel represents a channel which will allow I/O operations to be done
-
<ByteChannel> read(int nBytes) returns ((blob,int) | error)
Function to read bytes
Parameter Name Data Type Default Value Description nBytes int Number of bytes which should be read Return Type Description (blob,int) | error The bytes which were read -
<ByteChannel> write(blob content, int offset) returns (int | error)
Function to write bytes
Parameter Name Data Type Default Value Description content blob Bytes which should be written offset int If the bytes need to be written with an offset, the value of that offset Return Type Description int | error Number of bytes written -
<ByteChannel> close() returns (error)
Function to close a byte channel
Return Type Description error Returns if there's any error while performaing I/O operation -
<ByteChannel> base64Encode() returns (ByteChannel | error)
Encode a given ByteChannel with Base64 encoding scheme.
Return Type Description ByteChannel | error Return an encoded ByteChannel -
<ByteChannel> base64Decode() returns (ByteChannel | error)
Decode a given ByteChannel with Base64 encoding scheme.
Return Type Description ByteChannel | error Return a decoded ByteChannel
public type CSVChannel object
Ballerina DelimitedRecordChannel represents a channel which will allow to read/write text records
Field Name | Data Type | Default Value | Description |
---|---|---|---|
dc | DelimitedTextRecordChannel |
-
<CSVChannel> hasNext() returns (boolean)
Function to check whether next record is available or not
Return Type Description boolean True if the channel has more records; false otherwise -
<CSVChannel> getNext() returns (string[] | error)
Function to read text records
Return Type Description string[] | error Fields listed in the record -
<CSVChannel> write(string[] record) returns (error)
Function to write text records
Parameter Name Data Type Default Value Description record string[] Return Type Description error Returns if there's any error while performaing I/O operation -
<CSVChannel> close() returns (error)
Function to close the text record channel
Return Type Description error Returns if there's any error while performaing I/O operation -
<CSVChannel> getTable(typedesc structType) returns (table | error)
Function to load delimited records to in-memory table
Parameter Name Data Type Default Value Description structType typedesc Name of the struct that each record need to populate Return Type Description table | error Returns if there's any error while performaing I/O operation
public type CharacterChannel object
Ballerina CharacterChannel represents a channel which will allow to read/write characters
-
<CharacterChannel> read(int numberOfChars) returns (string | error)
Function to read characters
Parameter Name Data Type Default Value Description numberOfChars int Number of characters which should be read Return Type Description string | error The character sequence which was read -
<CharacterChannel> write(string content, int startOffset) returns (int | error)
Function to write characters
Parameter Name Data Type Default Value 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 Type Description int | error Number of characters written -
<CharacterChannel> readJson() returns (json | error)
Function to convert a character channel to a JSON
Return Type Description json | error Returns A JSON -
<CharacterChannel> readXml() returns (xml | error)
Function to convert a character channel to a XML
Return Type Description xml | error Returns A XML -
<CharacterChannel> writeJson(json content) returns (error)
Writes json through a given character channel
Parameter Name Data Type Default Value Description content json Return Type Description error -
<CharacterChannel> writeXml(xml content) returns (error)
Writes xml through a given character channel
Parameter Name Data Type Default Value Description content xml Return Type Description error -
<CharacterChannel> close() returns (error)
Function to close a character channel
Return Type Description error Returns if there's any error while performaing I/O operation
public type DelimitedTextRecordChannel object
Ballerina DelimitedRecordChannel represents a channel which will allow to read/write text records
-
<DelimitedTextRecordChannel> hasNext() returns (boolean)
Function to check whether next record is available or not
Return Type Description boolean True if the channel has more records; false otherwise -
<DelimitedTextRecordChannel> getNext() returns (string[] | error)
Function to read text records
Return Type Description string[] | error Fields listed in the record -
<DelimitedTextRecordChannel> write(string[] record) returns (error)
Function to write text records
Parameter Name Data Type Default Value Description record string[] Return Type Description error Returns if there's any error while performaing I/O operation -
<DelimitedTextRecordChannel> close() returns (error)
Function to close the text record channel
Return Type Description error Returns if there's any error while performaing I/O operation
public type Socket object
Represetns a TCP socket.
Field Name | Data Type | Default Value | Description |
---|---|---|---|
channel | ByteChannel | ||
port | int | ||
localPort | int | ||
address | string | ||
localAddress | string |
-
<Socket> close() returns (error)
Close the socket connection with the remote server
Return Type Description error Returns an error if socket could not be closed -
<Socket> shutdownInput() returns (error)
Shutdown the connection for reading
Return Type Description error Returns an error if socket could not be shutdown for reading -
<Socket> shutdownOutput() returns (error)
Shutdown the connection for writing
Return Type Description error Returns an error if socket could not be shutdown for writing