| | |
| | | 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.Date; |
| | | 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 |
| | |
| | | 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()); |
| | |
| | | } else { |
| | | Gson gson = new GsonBuilder().enableComplexMapKeySerialization().excludeFieldsWithoutExposeAnnotation() |
| | | .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)// 会把字段首字母大写 |
| | | @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); |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | if (b != null) { |
| | | s = new BASE64Encoder().encode(b); |
| | | s = Base64.getEncoder().encodeToString(b); |
| | | } |
| | | return s; |
| | | } |
| | |
| | | |
| | | String s = null; |
| | | if (b != null) { |
| | | s = new BASE64Encoder().encode(b); |
| | | s = Base64.getEncoder().encodeToString(b); |
| | | } |
| | | return s; |
| | | } |
| | | |
| | | // 解密 |
| | | 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(); |
| | |
| | | } |
| | | |
| | | 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) { |
| | |
| | | } |
| | | if (imgStr == null) // 图像数据为空 |
| | | return false; |
| | | BASE64Decoder decoder = new BASE64Decoder(); |
| | | try { |
| | | // Base64解码 |
| | | 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; |
| | |
| | | out.close(); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | } |