use of org.ballerinalang.nativeimpl.io.events.records.DelimitedRecordWriteEvent in project ballerina by ballerina-lang.
the class IOUtils method write.
/**
* Asynchronously writes delimited records to the channel.
*
* @param recordChannel channel the records should be written.
* @param records the record content.
* @param context event context.
* @param function callback function which will be triggered.
*/
public static void write(DelimitedRecordChannel recordChannel, BStringArray records, EventContext context, Function<EventResult, EventResult> function) {
DelimitedRecordWriteEvent recordWriteEvent = new DelimitedRecordWriteEvent(recordChannel, records, context);
CompletableFuture<EventResult> future = EventManager.getInstance().publish(recordWriteEvent);
future.thenApply(function);
}
use of org.ballerinalang.nativeimpl.io.events.records.DelimitedRecordWriteEvent in project ballerina by ballerina-lang.
the class AsyncReadWriteTest method writeRecords.
@Test(description = "Test which will write records to a channel using async io framework")
public void writeRecords() throws IOException, ExecutionException, InterruptedException {
// Number of characters in this file would be 6
ByteChannel byteChannel = TestUtil.openForWriting(currentDirectoryPath + "records.csv");
Channel channel = new MockByteChannel(byteChannel);
CharacterChannel characterChannel = new CharacterChannel(channel, StandardCharsets.UTF_8.name());
DelimitedRecordChannel recordChannel = new DelimitedRecordChannel(characterChannel, "\n", ",");
String[] recordOne = { "Foo", "Bar", "911" };
BStringArray recordOneArr = new BStringArray(recordOne);
DelimitedRecordWriteEvent recordWriteEvent = new DelimitedRecordWriteEvent(recordChannel, recordOneArr);
Future<EventResult> future = eventManager.publish(recordWriteEvent);
future.get();
String[] recordTwo = { "Jim", "Com", "119" };
BStringArray recordTwoArr = new BStringArray(recordTwo);
recordWriteEvent = new DelimitedRecordWriteEvent(recordChannel, recordTwoArr);
future = eventManager.publish(recordWriteEvent);
future.get();
recordChannel.close();
}
Aggregations