From 04f09e52ffd4681bdfd85e51acd3da0d1280c3d3 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期六, 16 四月 2022 16:07:10 +0800
Subject: [PATCH] bug修复

---
 src/main/java/com/yeshi/buwan/util/StringUtil.java |   48 ++++++++++++------------------------------------
 1 files changed, 12 insertions(+), 36 deletions(-)

diff --git a/src/main/java/com/yeshi/buwan/util/StringUtil.java b/src/main/java/com/yeshi/buwan/util/StringUtil.java
index cb8e1e7..a35c0cd 100644
--- a/src/main/java/com/yeshi/buwan/util/StringUtil.java
+++ b/src/main/java/com/yeshi/buwan/util/StringUtil.java
@@ -1,29 +1,17 @@
 package com.yeshi.buwan.util;
 
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
+import com.google.gson.*;
+
+import javax.persistence.Entity;
+import javax.servlet.http.HttpServletRequest;
+import java.io.*;
 import java.lang.reflect.Type;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.text.DateFormat;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
+import java.util.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-
-import javax.persistence.Entity;
-import javax.servlet.http.HttpServletRequest;
-
-import com.google.gson.*;
-
-import com.yeshi.buwan.domain.vip.VIPPriceType;
-import sun.misc.BASE64Decoder;
-import sun.misc.BASE64Encoder;
 
 /**
  * @author Administrator
@@ -281,7 +269,7 @@
             e.printStackTrace();
         }
         if (b != null) {
-            s = new BASE64Encoder().encode(b);
+            s = Base64.getEncoder().encodeToString(b);
         }
         return s;
     }
@@ -290,19 +278,17 @@
 
         String s = null;
         if (b != null) {
-            s = new BASE64Encoder().encode(b);
+            s = Base64.getEncoder().encodeToString(b);
         }
         return s;
     }
 
     // 瑙e瘑
     public static String getFromBase64(String s) {
-        byte[] b = null;
         String result = null;
         if (s != null) {
-            BASE64Decoder decoder = new BASE64Decoder();
+            byte[] b = Base64.getDecoder().decode(s);
             try {
-                b = decoder.decodeBuffer(s);
                 result = new String(b, "utf-8");
             } catch (Exception e) {
                 e.printStackTrace();
@@ -312,17 +298,7 @@
     }
 
     public static byte[] getFromBase64Byte(String s) {
-        byte[] b = null;
-        if (s != null) {
-            BASE64Decoder decoder = new BASE64Decoder();
-            try {
-                b = decoder.decodeBuffer(s);
-                return b;
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
-        }
-        return null;
+        return Base64.getDecoder().decode(s);
     }
 
     public static String getNumberFromString(String st) {
@@ -365,10 +341,9 @@
             }
         if (imgStr == null) // 鍥惧儚鏁版嵁涓虹┖
             return false;
-        BASE64Decoder decoder = new BASE64Decoder();
         try {
             // Base64瑙g爜
-            byte[] b = decoder.decodeBuffer(imgStr);
+            byte[] b = Base64.getDecoder().decode(imgStr);
             for (int i = 0; i < b.length; ++i) {
                 if (b[i] < 0) {// 璋冩暣寮傚父鏁版嵁
                     b[i] += 256;
@@ -380,6 +355,7 @@
             out.close();
             return true;
         } catch (Exception e) {
+            e.printStackTrace();
             return false;
         }
     }

--
Gitblit v1.8.0