This works fine for text strings but does not work for binary data. I have a PDF file that I am receiving via HL7 as b64 that I need to send via API as an unencoded string (needs to be sent just like it looks opening the file in notepad). After i b64 decode to byte and run this on the byte array:
var aBytes = qie.base64DecodeToBytes(b64Pdf);
var s = new java.lang.String(aBytes);
var bBytes = s.getBytes();
qie.debug(java.util.Arrays.equals(aBytes, bBytes)); //Returns FALSE
If I write aBytes to file I can open the PDF. If I write bBytes to file there are extra ? in the binary data and the file isn't able to be opened. Same thing if I b64 decode to string and then convert to byte[] and write the file. I believe it has something to do with java bytes being signed.
EDIT:
Looks like binary data requires setting a different encoding that is 1 to 1 mapping.
This works:
var s = new java.lang.String(aBytes, "ISO-8859-1");
bytes = s.getBytes("ISO-8859-1");