I received an XML file with a PDF Attachment in it encoded as Base64
string. I am trying to generate a PDF
file out of it. Following code works well:
String base64encodedPdf =" .... ";
byte[] imgBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary(base64encodedPdf);
IOUtils.write(imgBytes, new FileOutputStream("C:\\\\test.pdf"));
Problem arises when attachment data is too big to copy to editor directly, thought I can copy it to a text file and read file and convert to String
. This is how I do it:
org.apache.commons.io.FileUtils.readFileToString(file, encoding)
I am curious what encoding shall I specify... UTF-8
, UTF-16
and why?
EDIT:
This is the meta-information available to me
<AttachmentType tc="1">Document</AttachmentType>
<MimeType>application/pdf</MimeType>
<TransferEncodingTypeString>Base64</TransferEncodingTypeString>
<TransferEncodingTypeTC tc="4">Base64</TransferEncodingTypeTC>