From f537abe9f3646c739beaf15076246a2f71a347e9 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期四, 20 二月 2025 16:57:55 +0800 Subject: [PATCH] IOS广告增加区域屏蔽 --- src/main/java/com/yeshi/buwan/util/StringUtil.java | 78 ++++++++++++++++++-------------------- 1 files changed, 37 insertions(+), 41 deletions(-) diff --git a/src/main/java/com/yeshi/buwan/util/StringUtil.java b/src/main/java/com/yeshi/buwan/util/StringUtil.java index ed3c115..a35c0cd 100644 --- a/src/main/java/com/yeshi/buwan/util/StringUtil.java +++ b/src/main/java/com/yeshi/buwan/util/StringUtil.java @@ -1,30 +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 java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.text.DateFormat; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import com.google.gson.*; import javax.persistence.Entity; import javax.servlet.http.HttpServletRequest; - -import com.google.gson.FieldNamingPolicy; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; - -import sun.misc.BASE64Decoder; -import sun.misc.BASE64Encoder; +import java.io.*; +import java.lang.reflect.Type; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.text.DateFormat; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * @author Administrator @@ -58,6 +45,18 @@ String st = ""; for (int i = 0; i < srcList.size(); i++) { st += srcList.get(i) + seperate; + } + if (st.endsWith(seperate)) { + st = st.substring(0, st.length() - seperate.length()); + } + return st; + } + + + public static String join(Collection srcList, String seperate) { + String st = ""; + for (Iterator<String> its = srcList.iterator(); its.hasNext(); ) { + st += its.next() + seperate; } if (st.endsWith(seperate)) { st = st.substring(0, st.length() - seperate.length()); @@ -176,7 +175,16 @@ return o.toString(); } else { Gson gson = new GsonBuilder().enableComplexMapKeySerialization().excludeFieldsWithoutExposeAnnotation() - .setDateFormat(DateFormat.LONG).setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)// 浼氭妸瀛楁棣栧瓧姣嶅ぇ鍐� + .setDateFormat(DateFormat.LONG).registerTypeAdapter(Date.class, new JsonSerializer<Date>() { + @Override + public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) { + if (value == null) { + return new JsonPrimitive("0"); + } else { + return new JsonPrimitive(value.getTime()); + } + } + }).setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)// 浼氭妸瀛楁棣栧瓧姣嶅ぇ鍐� .setPrettyPrinting().setVersion(1.0).create(); String st = gson.toJson(o); return Utils.JsonFilter(st); @@ -261,7 +269,7 @@ e.printStackTrace(); } if (b != null) { - s = new BASE64Encoder().encode(b); + s = Base64.getEncoder().encodeToString(b); } return s; } @@ -270,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(); @@ -292,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) { @@ -345,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; @@ -360,6 +355,7 @@ out.close(); return true; } catch (Exception e) { + e.printStackTrace(); return false; } } -- Gitblit v1.8.0