Re: sun.misc.base64
Janna wrote:
Can anyone tell me what jar or package I need to include sun.misc.Base64.*
dependencies? I want to use this package in an application being developed
in Eclipse, but I don;t know where it exists (This has to be developed under
JDK 1.4.2). Thanks guys.
Using internal Java classes from SUN is not recommended.
Use the supported Base64 in JavaMail.
public static String b64encode(byte[] b) throws MessagingException,
IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream b64os = MimeUtility.encode(baos, "base64");
b64os.write(b);
b64os.close();
return new String(baos.toByteArray());
}
public static byte[] b64decode(String s) throws
MessagingException, IOException {
ByteArrayInputStream bais = new ByteArrayInputStream(s.getBytes());
InputStream b64is = MimeUtility.decode(bais, "Base64");
byte[] tmp = new byte[s.length()];
int n = b64is.read(tmp);
byte[] res = new byte[n];
System.arraycopy(tmp, 0, res, 0, n);
return res;
}
Arne