use of org.ballerinalang.model.values.BBlob in project ballerina by ballerina-lang.
the class ToBlob method execute.
public void execute(Context ctx) {
try {
String string = ctx.getStringArgument(0);
String encoding = ctx.getStringArgument(1);
byte[] arr = string.getBytes(encoding);
ctx.setReturnValues(new BBlob(arr));
} catch (UnsupportedEncodingException e) {
throw new BallerinaException("Unsupported Encoding", e);
}
}
use of org.ballerinalang.model.values.BBlob in project ballerina by ballerina-lang.
the class GetBlob method execute.
@Override
public void execute(Context context) {
BlobDataSource result = null;
try {
BStruct entityStruct = (BStruct) context.getRefArgument(FIRST_PARAMETER_INDEX);
MessageDataSource messageDataSource = EntityBodyHandler.getMessageDataSource(entityStruct);
if (messageDataSource != null) {
result = (BlobDataSource) messageDataSource;
} else {
result = EntityBodyHandler.constructBlobDataSource(entityStruct);
EntityBodyHandler.addMessageDataSource(entityStruct, result);
// Set byte channel to null, once the message data source has been constructed
entityStruct.addNativeData(ENTITY_BYTE_CHANNEL, null);
}
} catch (Throwable e) {
context.setReturnValues(MimeUtil.createEntityError(context, "Error occurred while extracting blob data from entity : " + e.getMessage()));
}
context.setReturnValues(new BBlob(result != null ? result.getValue() : new byte[0]));
}
Aggregations