java 构建关于使用 Sun 专有 API 的警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13475722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Build warnings regarding using Sun proprietary API
提问by MeanwhileInHell
I am trying to clean up my build environment and have discovered a couple of warnings reported around usage of Sun proprietary API's.
我正在尝试清理我的构建环境,并且发现了一些关于 Sun 专有 API 使用情况的警告。
[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.
任何人都可以建议这些 API 的替代品吗?或者这些可以用官方的 Java API 代替吗?我意识到这些只是警告,但这是我计划解决的问题。
回答by Jon Skeet
It's not clear why you're declaring your own HttpURLConnection
and Handler
classes in the first place - are you sureyou want to compile those?
目前还不清楚为什么你宣称自己HttpURLConnection
和Handler
班级第一名-你一定要编译那些?
As for Base64 - I like this public domain implementationmyself.
至于 Base64 - 我自己喜欢这个公共领域的实现。
回答by Qwerky
If you have written a http client then you've reinvented the wheel. There's a really good one already in apache http client.
如果您编写了一个 http 客户端,那么您就重新发明了轮子。apache http client 中已经有一个非常好的。
If you want Base64 encoding/decoding there's an class for that in apache commons codec.
如果你想要 Base64 编码/解码,在apache commons codec 中有一个类。
回答by CAMOBAP
Apache Commons Codecinclude Base64class.
回答by zeusalmighty
For Base64, as of Java 8 you can use java.util.Base64.getEncoder().encode(Byte[])
and java.util.Base64.getDecoder().decode(Byte[])
对于 Base64,从 Java 8 开始,您可以使用java.util.Base64.getEncoder().encode(Byte[])
和java.util.Base64.getDecoder().decode(Byte[])
回答by laz
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.
我不确定为什么您需要sun.net.www.protocol.http
在代码中直接使用这些对象,因为HttpUrlConnection
. 您可以使用该对象而不是内部对象。如果该 API 不能满足您的需求,则可以使用Apache HttpClient。
As for base 64 encoding, you can use the one supplied with Java Maillike this:
至于 base 64 编码,您可以使用Java Mail提供的编码,如下所示:
final InputStream decoded = MimeUtility.decode(encodedInput, "base64");