|
|
|
@ -61,9 +61,9 @@ public class TbUtils { |
|
|
|
parserConfig.addImport("decodeToJson", new MethodStub(TbUtils.class.getMethod("decodeToJson", |
|
|
|
ExecutionContext.class, String.class))); |
|
|
|
parserConfig.addImport("stringToBytes", new MethodStub(TbUtils.class.getMethod("stringToBytes", |
|
|
|
ExecutionContext.class, String.class))); |
|
|
|
ExecutionContext.class, Object.class))); |
|
|
|
parserConfig.addImport("stringToBytes", new MethodStub(TbUtils.class.getMethod("stringToBytes", |
|
|
|
ExecutionContext.class, String.class, String.class))); |
|
|
|
ExecutionContext.class, Object.class, String.class))); |
|
|
|
parserConfig.registerNonConvertableMethods(TbUtils.class, Collections.singleton("stringToBytes")); |
|
|
|
parserConfig.addImport("parseInt", new MethodStub(TbUtils.class.getMethod("parseInt", |
|
|
|
String.class))); |
|
|
|
@ -192,14 +192,22 @@ public class TbUtils { |
|
|
|
return new String(bytes, charsetName); |
|
|
|
} |
|
|
|
|
|
|
|
public static List<Byte> stringToBytes(ExecutionContext ctx, String str) { |
|
|
|
byte[] bytes = str.getBytes(); |
|
|
|
return bytesToList(ctx, bytes); |
|
|
|
public static List<Byte> stringToBytes(ExecutionContext ctx, Object str) throws IllegalAccessException { |
|
|
|
if (str instanceof String) { |
|
|
|
byte[] bytes = str.toString().getBytes(); |
|
|
|
return bytesToList(ctx, bytes); |
|
|
|
} else { |
|
|
|
throw new IllegalAccessException("Invalid type parameter [" + str.getClass().getSimpleName() + "]. Expected 'String'"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static List<Byte> stringToBytes(ExecutionContext ctx, String str, String charsetName) throws UnsupportedEncodingException { |
|
|
|
byte[] bytes = str.getBytes(charsetName); |
|
|
|
return bytesToList(ctx, bytes); |
|
|
|
public static List<Byte> stringToBytes(ExecutionContext ctx, Object str, String charsetName) throws UnsupportedEncodingException, IllegalAccessException { |
|
|
|
if (str instanceof String) { |
|
|
|
byte[] bytes = str.toString().getBytes(charsetName); |
|
|
|
return bytesToList(ctx, bytes); |
|
|
|
} else { |
|
|
|
throw new IllegalAccessException("Invalid type parameter [" + str.getClass().getSimpleName() + "]. Expected 'String'"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static byte[] bytesFromList(List<Byte> bytesList) { |
|
|
|
|