static BString createBString(String s) { if (s == null) { return null; } return new BString(s); }
public Descriptor build() throws IOException { try (InputStream targetStream = new ByteArrayInputStream(descriptorData)) { DescriptorProtos.FileDescriptorProto fileDescriptorSet = DescriptorProtos.FileDescriptorProto .parseFrom(targetStream); return new Descriptor(fileDescriptorSet.getName(), new BString(bytesToHex(descriptorData)) .stringValue()); } } }
@Override public BPacket toBValue(BString bString, BValueSerializer serializer) { if (bString.stringValue() == null) { return BPacket.from(B_STRING, null); } return BPacket.from(B_STRING, bString); }
if (args[i] instanceof BString) { callee.intRegs[++booleanRegIndex] = ((BString) args[i]).value().toLowerCase().equals("true") ? 1 : 0; } else { callee.intRegs[++booleanRegIndex] = ((BValueType) args[i]).booleanValue() ? 1 : 0;
/** * If the given Content-Type header value doesn't have a boundary parameter value, get a new boundary string and * append it to Content-Type and set it to transport message. * * @param transportMessage Represent transport message * @param contentType Represent the Content-Type header value * @return The boundary string that was extracted from header or the newly generated one */ public static String addBoundaryIfNotExist(HttpCarbonMessage transportMessage, String contentType) { String boundaryString; BString boundaryValue = HeaderUtil.extractBoundaryParameter(contentType); boundaryString = boundaryValue != null ? boundaryValue.toString() : HttpUtil.addBoundaryParameter(transportMessage, contentType); return boundaryString; }
private Object createArrayInstance(BMap<String, BValue> jsonNode) { BString ct = (BString) jsonNode.get(COMPONENT_TYPE); String componentType = ct.stringValue(); BInteger bSize = (BInteger) jsonNode.get(LENGTH_TAG); int size = (int) bSize.intValue(); Class<?> clazz = findClass(componentType); if (clazz != null) { return Array.newInstance(clazz, size); } throw new BallerinaException("Can not create array instance of: " + componentType + "[]"); }
if (args[i] instanceof BString) { local.intRegs[intParamCount++] = ((BString) args[i]).value().toLowerCase().equals("true") ? 1 : 0; } else { local.intRegs[intParamCount++] = ((BValueType) args[i]).booleanValue() ? 1 : 0;
@SuppressWarnings("unchecked") public <V extends BValue> V getZeroValue() { return (V) new BString(BLangConstants.STRING_EMPTY_VALUE); }
/** * {@inheritDoc} */ @Override public BString getTextValue() { StringBuilder seqTextBuilder = new StringBuilder(); for (int i = 0; i < sequence.size(); i++) { BXMLItem item = (BXMLItem) sequence.getRefValue(i); seqTextBuilder.append(item.getTextValue().stringValue()); } return new BString(seqTextBuilder.toString()); }
/** * {@inheritDoc} */ @Override public BXML<?> elements(String qname) { BValueArray elementsSeq = new BValueArray(); switch (nodeType) { case ELEMENT: if (getElementName().stringValue().equals(getQname(qname).toString())) { elementsSeq.add(0, this); } break; default: break; } return new BXMLSequence(elementsSeq); }
@Override public <V extends BValue> V getEmptyValue() { return (V) new BString(BLangConstants.STRING_EMPTY_VALUE); }
switch (algorithm.stringValue()) { case "SHA1": hashAlgorithm = "SHA-1"; throw new BallerinaException("Error while encoding" + e.getMessage(), context); context.setReturnValues(new BString(result));
/** * {@inheritDoc} */ @Override public BXML<?> elements(String qname) { BValueArray elementsSeq = new BValueArray(BTypes.typeXML); String qnameStr = getQname(qname).toString(); int j = 0; for (int i = 0; i < sequence.size(); i++) { BXMLItem item = (BXMLItem) sequence.getRefValue(i); if (item.getNodeType() == XMLNodeType.ELEMENT && item.getElementName().stringValue().equals(qnameStr)) { elementsSeq.add(j++, item); } } return new BXMLSequence(elementsSeq); }
private static BString getBString(String str) { return str != null ? new BString(str) : null; }
String keyString = context.getStringArgument(1); BString algorithm = context.getNullableRefArgument(0) != null ? (BString) context.getNullableRefArgument(0) : new BString(""); BValue encodingBVal = context.getNullableRefArgument(1); String encoding = encodingBVal != null ? encodingBVal.stringValue() : "UTF-8"; switch (algorithm.stringValue()) { case "SHA1": hmacAlgorithm = "HmacSHA1"; context); context.setReturnValues(new BString(result));
public static BValue[] notifyTransactionBegin(Strand ctx, String globalTransactionId, String url, String transactionBlockId, String protocol) { BValue[] args = { (globalTransactionId == null ? null : new BString(globalTransactionId)), new BString(transactionBlockId), new BString(url), new BString(protocol) }; BValue[] returns = invokeCoordinatorFunction(ctx, TransactionConstants.COORDINATOR_BEGIN_TRANSACTION, args); checkTransactionCoordinatorError(returns[0], "error in global transaction start: "); return returns; }
@Override public void execute(Context context) { String configKey = context.getStringArgument(0); BString type = (BString) context.getNullableRefArgument(0); // TODO: Add a try-catch switch (type.stringValue()) { case "STRING": String val = configRegistry.getAsString(configKey); context.setReturnValues(val != null ? new BString(val) : null); break; case "INT": context.setReturnValues(new BInteger(configRegistry.getAsInt(configKey))); break; case "FLOAT": context.setReturnValues(new BFloat(configRegistry.getAsFloat(configKey))); break; case "BOOLEAN": context.setReturnValues(new BBoolean(configRegistry.getAsBoolean(configKey))); break; case "MAP": context.setReturnValues(buildBMap(configRegistry.getAsMap(configKey))); break; default: throw new IllegalStateException("invalid value type: " + type.stringValue()); } }
/** * {@inheritDoc} */ @Override public BString getItemType() { return new BString(nodeType.value()); }
/** * {@inheritDoc} */ @Override public BString getElementName() { if (nodeType == XMLNodeType.ELEMENT) { return new BString(((OMElement) omNode).getQName().toString()); } return BTypes.typeString.getEmptyValue(); }