@Override public void execute(Context context) { BValueArray input = (BValueArray) context.getRefArgument(0); byte[] encodedValue = Base64.getEncoder().encode(input.getBytes()); context.setReturnValues(new BString(new String(encodedValue, StandardCharsets.ISO_8859_1))); } }
private static byte[] getByteArray(BValue value) { byte[] val = null; if (value instanceof BValueArray) { val = ((BValueArray) value).getBytes(); } else if (value instanceof BString) { val = getBytesFromBase64String(value.stringValue()); } return val; }
@Override public void execute(Context context) { byte[] bytes = ((BValueArray) context.getRefArgument(0)).getBytes(); String encoding = context.getStringArgument(0); try { String value = new String(bytes, encoding); context.setReturnValues(new BString(value)); } catch (UnsupportedEncodingException e) { throw new BallerinaException("unsupported encoding: " + encoding , e); } } }
@Override public void execute(Context context) { BValueArray input = (BValueArray) context.getRefArgument(0); String output = EncodingUtil.encodeHex(input.getBytes()); context.setReturnValues(new BString(output)); } }
@Override public void execute(Context context) { LLVM.LLVMTargetMachineRef t = FFIUtil.getRecodeArgumentNative(context, 0); LLVM.LLVMModuleRef m = FFIUtil.getRecodeArgumentNative(context, 1); BValueArray fileNameByteArray = (BValueArray) context.getRefArgument(2); int codegen = (int) context.getIntArgument(0); BValueArray errorMsgByteArray = (BValueArray) context.getRefArgument(3); int returnValue = LLVM.LLVMTargetMachineEmitToFile(t, m, fileNameByteArray.getBytes(), codegen, errorMsgByteArray.getBytes()); context.setReturnValues(new BInteger(returnValue)); } }
@Override public void execute(Context context) { BValue entityBody = context.getRefArgument(0); Checksum checksum = new CRC32(); byte[] bytes; long checksumVal; BType argType = entityBody.getType(); if (argType == BTypes.typeJSON || argType == BTypes.typeXML || argType == BTypes.typeString) { // TODO: Look at the possibility of making the encoding configurable bytes = entityBody.stringValue().getBytes(StandardCharsets.UTF_8); } else if (argType.getTag() == TypeTags.ARRAY_TAG && ((BArrayType) argType).getElementType().getTag() == TypeTags.BYTE_TAG) { bytes = ((BValueArray) entityBody).getBytes(); } else { throw new BallerinaException( "failed to generate hash: unsupported data type: " + entityBody.getType().getName()); } checksum.update(bytes, 0, bytes.length); checksumVal = checksum.getValue(); context.setReturnValues(new BString(Long.toHexString(checksumVal))); } }
@Override public void execute(Context context, CallableUnitCallback callback) { try { BMap<String, BValue> wsConnection = (BMap<String, BValue>) context.getRefArgument(0); WebSocketOpenConnectionInfo connectionInfo = (WebSocketOpenConnectionInfo) wsConnection .getNativeData(WebSocketConstants.NATIVE_DATA_WEBSOCKET_CONNECTION_INFO); byte[] binaryData = ((BValueArray) context.getRefArgument(1)).getBytes(); ChannelFuture future = connectionInfo.getWebSocketConnection().ping(ByteBuffer.wrap(binaryData)); WebSocketUtil.handleWebSocketCallback(context, callback, future); } catch (Exception e) { context.setReturnValues(HttpUtil.getError(context, e.getMessage())); callback.notifySuccess(); } }
BValue value = constrainedType.get(fieldName); if (value != null) { byte[] blobData = ((BValueArray) constrainedType.get(fieldName)).getBytes(); stmt.setBlob(index, new ByteArrayInputStream(blobData), blobData.length); } else {
@Override public void execute(Context context, CallableUnitCallback callback) { try { BMap<String, BValue> wsConnection = (BMap<String, BValue>) context.getRefArgument(0); WebSocketOpenConnectionInfo connectionInfo = (WebSocketOpenConnectionInfo) wsConnection .getNativeData(WebSocketConstants.NATIVE_DATA_WEBSOCKET_CONNECTION_INFO); byte[] binaryData = ((BValueArray) context.getRefArgument(1)).getBytes(); ChannelFuture future = connectionInfo.getWebSocketConnection().pong(ByteBuffer.wrap(binaryData)); WebSocketUtil.handleWebSocketCallback(context, callback, future); } catch (Exception e) { context.setReturnValues(HttpUtil.getError(context, e)); callback.notifySuccess(); } }
@Override public void execute(Context context, CallableUnitCallback callback) { try { BMap<String, BValue> wsConnection = (BMap<String, BValue>) context.getRefArgument(0); WebSocketOpenConnectionInfo connectionInfo = (WebSocketOpenConnectionInfo) wsConnection .getNativeData(WebSocketConstants.NATIVE_DATA_WEBSOCKET_CONNECTION_INFO); byte[] binaryData = ((BValueArray) context.getRefArgument(1)).getBytes(); boolean finalFrame = context.getBooleanArgument(0); ChannelFuture webSocketChannelFuture = connectionInfo.getWebSocketConnection().pushBinary(ByteBuffer.wrap(binaryData), finalFrame); WebSocketUtil.handleWebSocketCallback(context, callback, webSocketChannelFuture); } catch (Exception e) { context.setReturnValues(HttpUtil.getError(context, e)); callback.notifySuccess(); } }
BType elementType = ((BArrayType) field.getFieldType()).getElementType(); if (elementType.getTag() == TypeTags.BYTE_TAG) { structData[i] = ((BValueArray) bValue).getBytes(); break; } else {
jmsMessage.setBoolean(key, ((BBoolean) value).booleanValue()); } else if (value instanceof BValueArray) { jmsMessage.setBytes(key, ((BValueArray) value).getBytes()); } else if (value instanceof BInteger) { jmsMessage.setLong(key, ((BInteger) value).intValue());