I have a server side web service that returns a PDF document as a BASE64 encoded string. When I decode that string in Vaadin and save the PDF document, the document is damaged. I have looked at both the original file that was created and the new file that resulted from the decode string and they are different. I suspect the problem is that the code that generates the encoded string is using “ISO8859-1” character set while the Vaadin is using a different character set.
How would I go about converting the string from the server side character set so that Vaadin can decode the string correctly?
from doing a quick test run (tcl has a base64 package), I noticed several things:
there are some characters before the Base64 starts (I removed them)
I then base 64 decoded it and it returns an invalid PDF - but: one that seems to have correct start and end(i.e. PDF… and EOF) - maybe checking this anyways makes sense
as Base 64 only uses chars that are the same in every charset
some base64 implementations require a linebreak after 70-odd characters, and your file lacks that. This is where I’d look at first (maybe you can find out what the webservice uses and try the same)
Sebastian,
I just want to make sure I understand what you are saying correctly.
Since Base64 only uses chars that are the same in charset, I do not need to convert from one charset to another. Is that correct?
You mentioned that there were some charcters before the Base64. Are you talking about "java string = " and "abl string = "? If so, they were added by me to denote where each string came from. If not which characters did you remove?
You mention that some base64 implementation require a linebreak every 70-odd characters. Do you know if that is the case with the com.google.gwt.user.server.Base64Utils? That is the utility that I am using to convert the string back into a binary value.
Just thought I would give something a try. I copied the string I was getting from the web service into a on-line tool to do base64 encoding/decoding. That on-line tool decoded the string correctly. The problem has to be with the Base64Utility not handling my data correctly.
great! Although irrelevant: 1.) yes, base64 should be charset independent; 2.) yes, this was what I removed, so all is OK. and 3.) I don’t know about this specific one.
I tried the apache.commons.codec first, and when I ran my code it complained about not being able to find the class. Being new to java and Vaadin, I started looking for another class that would work for me. That is when I found the gwt Base64Utils, which seemed to be working, but my file was corrupt. Once I found out that it had a bug, I noticed the Tomcat version, so I tried that and it worked for me. Do not want to go to 8 yet, as I am under a fairly tight deadline and changing version could cause other problems.