When I needed to do that, I just copied and pasted the code out of
GWT's ClientBundle image stuff:
private String toBase64(byte[] data) {
// This is bad, but I am lazy and don't want to write _another_
encoder
sun.misc.BASE64Encoder enc = new sun.misc.BASE64Encoder();
String base64Contents = enc.encode(data).replaceAll("\\s+", "");
return "data:image/jpeg;base64," + base64Contents;
}
(And I don't have to worry about IE since we were able to convince
management that IE users could install ChromeFrame!)