Build warnings regarding using Sun proprietary API

允我心安 提交于 2019-12-12 11:15:44

问题


I am trying to clean up my build environment and have discovered a couple of warnings reported around usage of Sun proprietary API's.

[javac] /workspace/<path-to-files>/Handler.java:18: warning: sun.net.www.protocol.http.Handler is Sun proprietary API and may be removed in a future release
[javac] public class Handler extends sun.net.www.protocol.http.Handler {
[javac]                                                       ^
[javac] /workspace/<path-to-files>/HttpClient.java:16: warning: sun.net.www.http.HttpClient is Sun proprietary API and may be removed in a future release 
[javac] public class HttpClient extends sun.net.www.http.HttpClient {
[javac]
[javac] /workspace/<path-to-files>/HttpURLConnection.java:19: warning: sun.net.www.protocol.http.HttpURLConnection is Sun proprietary API and may be removed in a future release
[javac] public class HttpURLConnection extends sun.net.www.protocol.http.HttpURLConnection {
[javac]                                                                 ^

and...

[javac] /workspace/<path-to-files>/JavaFile.java:17: warning: sun.misc.BASE64Decoder is Sun proprietary API and may be removed in a future release
[javac] import sun.misc.BASE64Decoder;
[javac]                ^
[javac] /workspace/<path-to-files>/JavaFile.java:338: warning: sun.misc.BASE64Encoder is Sun proprietary API and may be removed in a future release
[javac]          BASE64Encoder encoder = new BASE64Encoder();
[javac]          ^

Can anyone suggest a good alternative to these API's? Or can these be replaced with the official Java API's? I realise that these are just warnings, but this is something I plan on resolving.


回答1:


It's not clear why you're declaring your own HttpURLConnection and Handler classes in the first place - are you sure you want to compile those?

As for Base64 - I like this public domain implementation myself.




回答2:


If you have written a http client then you've reinvented the wheel. There's a really good one already in apache http client.

If you want Base64 encoding/decoding there's an class for that in apache commons codec.




回答3:


Apache Commons Codec include Base64 class.




回答4:


I'm not sure why you would need to use those sun.net.www.protocol.http objects directly in your code, as those are used internally by HttpUrlConnection. You can use that object instead of the internal ones. If that API doesn't meet your needs, there is Apache HttpClient.

As for base 64 encoding, you can use the one supplied with Java Mail like this:

final InputStream decoded = MimeUtility.decode(encodedInput, "base64");

or Apache commons-codec.




回答5:


For Base64, as of Java 8 you can use java.util.Base64.getEncoder().encode(Byte[]) and java.util.Base64.getDecoder().decode(Byte[])



来源:https://stackoverflow.com/questions/13475722/build-warnings-regarding-using-sun-proprietary-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!