use of org.ballerinalang.nativeimpl.io.channels.base.CharacterChannel in project ballerina by ballerina-lang.
the class CreateCharacterChannel method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute(Context context) {
BStruct byteChannelInfo;
BStruct characterChannel;
String encoding;
try {
// File which holds access to the channel information
byteChannelInfo = (BStruct) context.getRefArgument(CHAR_CHANNEL_INDEX);
encoding = context.getStringArgument(ENCODING_INDEX);
characterChannel = BLangConnectorSPIUtil.createBStruct(context, CHAR_CHANNEL_PACKAGE, STRUCT_TYPE);
Channel byteChannel = (Channel) byteChannelInfo.getNativeData(IOConstants.BYTE_CHANNEL_NAME);
CharacterChannel bCharacterChannel = new CharacterChannel(byteChannel, encoding);
characterChannel.addNativeData(IOConstants.CHARACTER_CHANNEL_NAME, bCharacterChannel);
context.setReturnValues(characterChannel);
} catch (Throwable e) {
String message = "Error occurred while converting byte channel to character channel:" + e.getMessage();
log.error(message, e);
context.setReturnValues(IOUtils.createError(context, message));
}
}
use of org.ballerinalang.nativeimpl.io.channels.base.CharacterChannel in project ballerina by ballerina-lang.
the class LoadToTable method getDelimitedRecordChannel.
private DelimitedRecordChannel getDelimitedRecordChannel(Context context, FileChannel sourceChannel) {
final String recordSeparator = context.getStringArgument(1);
final String fieldSeparator = context.getStringArgument(2);
final String encoding = context.getStringArgument(3);
FileIOChannel fileIOChannel = new FileIOChannel(sourceChannel);
CharacterChannel characterChannel = new CharacterChannel(fileIOChannel, Charset.forName(encoding).name());
return new DelimitedRecordChannel(characterChannel, recordSeparator, fieldSeparator);
}
Aggregations