Re: Warning message with proprietary class
On 03-03-2010 20:55, francan wrote:
In my Tomcat 6.0.20 container I am using sun.misc.BASE64Encoder to get
NTLM Intranet username and everything works. Unfortunately I get the
below warning message after I compile the class:
-----------------------
Auth.java:3: warning: sun.misc.BASE64Encoder is Sun proprietary API
and
may be removed in a future release import sun.misc.BASE64Encoder;
^
1 warning
----------------------------
It seems the sun.misc.BASE64Encoder is Sun proprietary API and is
available from the rt.jar? I was wondering if I should put the rt.jar
in my web app lib folder (\WEB-INF\lib) just in case it is removed
from the jvm in the future?
No.
You should be using the supported Base64 API.
The one in javax.mail.
See some code below for example of usage.
Arne
==============
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.mail.MessagingException;
import javax.mail.internet.MimeUtility;
public class B64 {
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;
}
}