public class IOUtils extends Object
Constructor and Description |
---|
IOUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
close(Channel byteChannel,
EventContext eventContext,
Function<EventResult,EventResult> function)
Closes the channel asynchronously.
|
static void |
close(CharacterChannel charChannel,
EventContext eventContext,
Function<EventResult,EventResult> function)
Closes the character channel asynchronously.
|
static void |
close(DelimitedRecordChannel charChannel,
EventContext eventContext,
Function<EventResult,EventResult> function)
Closes the delimited record channel asynchronously.
|
static DelimitedRecordChannel |
createDelimitedRecordChannel(String filePath,
String encoding,
String mode,
Format format)
Creates a delimited record channel to read from CSV file.
|
static BStruct |
createError(Context context,
String message)
Returns the error struct for the corresponding message.
|
static FileChannel |
openFileChannel(Path path,
String accessMode)
Open a file channel from the given path.
|
static void |
read(Channel channel,
byte[] content,
EventContext context,
Function<EventResult,EventResult> function)
Reads bytes asynchronously and trigger the callback.
|
static void |
read(CharacterChannel characterChannel,
int numberOfCharacters,
EventContext context,
Function<EventResult,EventResult> function)
Reads characters from the channel.
|
static void |
read(DelimitedRecordChannel recordChannel,
EventContext context,
Function<EventResult,EventResult> function)
Reads delimited records asynchronously.
|
static int |
readFull(Channel channel,
byte[] content,
EventContext context)
Asynchronously reads bytes from the channel.
|
static void |
write(Channel channel,
byte[] content,
int offset,
EventContext context,
Function<EventResult,EventResult> function)
Writes bytes to a channel asynchronously.
|
static void |
write(CharacterChannel characterChannel,
String content,
int offset,
EventContext context,
Function<EventResult,EventResult> function)
Writes characters to a channel.
|
static void |
write(DelimitedRecordChannel recordChannel,
BStringArray records,
EventContext context,
Function<EventResult,EventResult> function)
Asynchronously writes delimited records to the channel.
|
static int |
writeFull(Channel channel,
byte[] content,
int offset,
EventContext context)
Asynchronously writes bytes to a channel.
|
static void |
writeFull(CharacterChannel characterChannel,
String payload,
EventContext eventContext)
Writes the whole payload to the channel.
|
public static BStruct createError(Context context, String message)
context
- context of the native function.message
- error message.public static int writeFull(Channel channel, byte[] content, int offset, EventContext context) throws ExecutionException, InterruptedException
channel
- the channel the bytes should be written.content
- content which should be written.context
- context of the native function call.offset
- the start index of the bytes which should be written.ExecutionException
- errors which occur during execution.InterruptedException
- during interrupt error.public static void write(Channel channel, byte[] content, int offset, EventContext context, Function<EventResult,EventResult> function)
Writes bytes to a channel asynchronously.
channel
- channel which will be used to write bytes.content
- content which will be written.offset
- the offset which will be set to write bytes.context
- context of the native function call.function
- callback function which should be called upon completion.public static void writeFull(CharacterChannel characterChannel, String payload, EventContext eventContext) throws BallerinaException
Writes the whole payload to the channel.
characterChannel
- the character channel the payload should be written.payload
- the content.eventContext
- the context of the event.BallerinaException
- during i/o error.public static int readFull(Channel channel, byte[] content, EventContext context) throws InterruptedException, ExecutionException
content
- the initialized array which should be filled with the content.context
- context of the native function call.channel
- the channel the content should be read into.InterruptedException
- during interrupt error.ExecutionException
- errors which occurs while execution.public static void read(CharacterChannel characterChannel, int numberOfCharacters, EventContext context, Function<EventResult,EventResult> function)
characterChannel
- channel the characters should be read.numberOfCharacters
- the number of characters to read.context
- context of the event.function
- the callback function which will be triggered after reading characters.public static void write(CharacterChannel characterChannel, String content, int offset, EventContext context, Function<EventResult,EventResult> function)
characterChannel
- the channel the characters will be writtencontent
- the content which will be written.offset
- if an offset should be specified while writing.context
- context of the event.function
- callback function which should be triggeredpublic static void read(Channel channel, byte[] content, EventContext context, Function<EventResult,EventResult> function)
Reads bytes asynchronously and trigger the callback.
channel
- the channel which the bytes should be read from.content
- the byte[] which will holds the content which will be read.context
- context which will be obtained from the native function call.function
- the callback function which will be triggered.public static void read(DelimitedRecordChannel recordChannel, EventContext context, Function<EventResult,EventResult> function)
recordChannel
- channel the bytes should be read from.context
- event context.function
- callback function which will be triggered.public static void write(DelimitedRecordChannel recordChannel, BStringArray records, EventContext context, Function<EventResult,EventResult> function)
recordChannel
- channel the records should be written.records
- the record content.context
- event context.function
- callback function which will be triggered.public static void close(Channel byteChannel, EventContext eventContext, Function<EventResult,EventResult> function)
byteChannel
- channel which should be closed.eventContext
- context of the event.function
- callback function which will be triggered.public static void close(CharacterChannel charChannel, EventContext eventContext, Function<EventResult,EventResult> function)
charChannel
- channel which should be closed.eventContext
- context of the event.function
- callback function which will be triggered.public static void close(DelimitedRecordChannel charChannel, EventContext eventContext, Function<EventResult,EventResult> function)
charChannel
- channel which should be closed.eventContext
- context of the event.function
- callback function which will be triggered.public static FileChannel openFileChannel(Path path, String accessMode) throws IOException
path
- path to the file.accessMode
- file access mode.IOException
- during i/o error.public static DelimitedRecordChannel createDelimitedRecordChannel(String filePath, String encoding, String mode, Format format) throws IOException
filePath
- path to the CSV file.encoding
- the encoding of CSV file.mode
- permission to access the file.format
- format of the CSV file.IOException
- during I/O error.Copyright © 2018 WSO2. All rights reserved.