警告: BASE64Decoder是内部专用 API, 可能会在未来发行版中删除

开发过程中遇到这个问题,虽然不影响项目运行,打包发布,但还是要把警告扼杀在摇篮中。
sun.misc包都是sun公司的内部类,并没有在java api中公开过,不建议使用,所以使用这些方法是不安全的,将来随时可能会从中去除,所以相应的应该使用替代的对象及方法。

针对警告: BASE64Decoder是内部专用 API, 可能会在未来发行版中删除解决办法

采用org.apache.commons.codec.binary.Base64替换

在这里插入图片描述

import org.apache.commons.codec.binary.Base64;

/**
 * @author wind
 * @version V1.0
 * @className Base64Encoder
 * @createDate 2021年12月28日
 */
public class Base64Encoder  {

    /**
     * @param bytes
     * @return
     */
    public static byte[] decode(final byte[] bytes) {
        return Base64.decodeBase64(bytes);
    }

    /**
     * 二进制数据编码为BASE64字符串
     *
     * @param bytes
     * @return
     * @throws Exception
     */
    public static String encode(final byte[] bytes) {
        return new String(Base64.encodeBase64(bytes));
    }

}
原方法
 
BASE64Encoder encoder = new BASE64Encoder();
 
//String imagestr new String(base64en.encode(str.getBytes("GBK"))).replace("\n","").replace("\r","");
 
String imagestr =  encoder.encode(captcha);
 
BASE64Decoder decoder = new BASE64Decoder();
 
byte[] bytes = decoder.decodeBuffer(imagestr);
 
现方法
 
import java.util.Base64.Encoder
import java.util.Base64.Decoder
 
Encoder encoder = Base64.getEncoder();
String result = encoder.encodeToString(byteArray);
 
Decoder decoder = Base64.getDecoder();
byte[] result = decoder.decode(str);
  • 5
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Windyº

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值