use of org.ballerinalang.model.values.BString in project ballerina by ballerina-lang.
the class Base64ToBase16Encode method execute.
@Override
public void execute(Context context) {
String value = context.getStringArgument(0);
byte[] base64DecodedValue = Base64.getDecoder().decode(value);
String base16EncodedValue = DatatypeConverter.printHexBinary(base64DecodedValue);
context.setReturnValues(new BString(base16EncodedValue));
}
use of org.ballerinalang.model.values.BString in project ballerina by ballerina-lang.
the class MimeUtilityFunctionTest method testMimeBase64DecodeString.
@Test(description = "Test 'testMimeBase64DecodeString' function in ballerina.mime package")
public void testMimeBase64DecodeString() {
BValue[] args = { new BString("QmFsbGVyaW5h"), new BString("utf-8") };
BValue[] returns = BRunUtil.invoke(compileResult, "testMimeBase64DecodeString", args);
Assert.assertEquals(returns.length, 1);
Assert.assertEquals(returns[0].stringValue(), "Ballerina");
}
use of org.ballerinalang.model.values.BString in project ballerina by ballerina-lang.
the class MimeUtilityFunctionTest method testGetAndSetText.
@Test(description = "Set text data to entity and get the content back from entity as text")
public void testGetAndSetText() {
BString textContent = new BString("Hello Ballerina !");
BValue[] args = { textContent };
BValue[] returns = BRunUtil.invoke(compileResult, "testSetAndGetText", args);
Assert.assertEquals(returns.length, 1);
Assert.assertEquals(returns[0].stringValue(), "Hello Ballerina !");
}
use of org.ballerinalang.model.values.BString in project ballerina by ballerina-lang.
the class MimeUtilityFunctionTest method testGetTextMoreThanOnce.
@Test(description = "Test whether the text content can be retrieved properly when it is called multiple times")
public void testGetTextMoreThanOnce() {
BString textContent = new BString("Hello Ballerina !");
BValue[] args = { textContent };
BValue[] returns = BRunUtil.invoke(compileResult, "testGetTextMultipleTimes", args);
Assert.assertEquals(returns.length, 1);
Assert.assertEquals(returns[0].stringValue(), "Hello Ballerina !Hello Ballerina !Hello Ballerina !");
}
use of org.ballerinalang.model.values.BString in project ballerina by ballerina-lang.
the class SystemTest method testFormatStringWithPadding.
@Test
public void testFormatStringWithPadding() {
BRefValueArray fArgs = new BRefValueArray();
fArgs.add(0, new BString("Hello Ballerina"));
BValue[] args = { new BString("%9.2s"), fArgs };
BValue[] returns = BRunUtil.invoke(compileResult, "testSprintf", args);
Assert.assertEquals(returns[0].stringValue(), " He");
}
Aggregations