admin管理员组文章数量:1794759
idea编译报错 sun.misc.BASE64Decoder升级处理
idea编译报错 sun.misc.BASE64Decoder升级处理
警告: 17:01:15 /deploy/jenkins/workspace/auto-java-test/utils/ImageBase64Utils.java:67: warning: BASE64Encoder is internal proprietary API and may be removed in a future release 17:01:15 BASE64Encoder encoder = new BASE64Encoder();
import sun.misc.BASE64Decoder;
替代写法: //从JDK 1.8开始,就提供了java.util.Base64.Decoder和java.util.Base64.Encoder的JDK公共API,可代替sun.misc.BASE64Decoder和sun.misc.BASE64Encoder的JDK内部API。 //byte[] bytes = new BASE64Decoder().decodeBuffer(base64); byte[] bytes = Base64.getDecoder().decode(base64); //或者使用方法 import org.apachemons.codec.binary.Base64; return Base64.encodeBase64String(encrypted);
demo测试类
代码语言:javascript代码运行次数:0运行复制@Test
public void test2() throws Exception{
//从JDK 1.8开始,就提供了java.util.Base64.Decoder和java.util.Base64.Encoder的JDK公共API,可代替sun.misc.BASE64Decoder和sun.misc.BASE64Encoder的JDK内部API。
//byte[] bytes = new BASE64Decoder().decodeBuffer(base64);
System.out.println("-----------------------早期写法----------------------");
String text = "字串文字";
BASE64Encoder encoder = new BASE64Encoder();
BASE64Decoder decoder = new BASE64Decoder();
byte[] textByte = text.getBytes("UTF-8");
//编码
String encodedText = encoder.encode(textByte);
System.out.println(encodedText);
//解码
System.out.println(new String(decoder.decodeBuffer(encodedText), "UTF-8"));
/**
* 与sun.mis c套件和Apache Commons Codec所提供的Base64编解码器来比较的话,Java 8提供的Base64拥有更好的效能。实际测试编码与解码速度的话,Java 8提供的Base64,要比sun.mis c套件提供的还要快至少11倍,比Apache Commons Codec提供的还要快至少3倍。因此在Java上若要使用Base64,这个Java 8底下的java .util套件所提供的Base64类别绝对是首选!
*
*/
System.out.println("-----------------------新的写法----------------------");
byte[] test11 = Base64.getEncoder().encode(textByte);
System.out.println("test11字符串="+new String(test11, "UTF-8"));
byte[] bytes11 = Base64.getDecoder().decode(test11);
System.out.println("test11="+new String(bytes11, "UTF-8"));
System.out.println("-----------------------apache写法----------------------");
String test22 = org.apache.tomcat.util.codec.binary.Base64.encodeBase64String(textByte);
System.out.println("test22字符串="+test22);
byte[] bytes22 = org.apache.tomcat.util.codec.binary.Base64.decodeBase64(test22);
System.out.println("test22="+new String(bytes22, "UTF-8"));
/**
* 打印效果: 结果一致
* -----------------------早期写法----------------------
* 5a2X5Liy5paH5a2X
* 字串文字
* -----------------------新的写法----------------------
* test11字符串=5a2X5Liy5paH5a2X
* test11=字串文字
* -----------------------apache写法----------------------
* test22字符串=5a2X5Liy5paH5a2X
* test22=字串文字
*/
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。 原始发表:2021-12-23,如有侵权请联系 cloudcommunity@tencent 删除字符串base64编码编译测试本文标签: idea编译报错 sunmiscBASE64Decoder升级处理
版权声明:本文标题:idea编译报错 sun.misc.BASE64Decoder升级处理 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1754989321a1709123.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论