package com.tencent.klevin.download.b.w; import android.os.Build; import android.os.Environment; import android.os.StatFs; import android.text.TextUtils; import android.webkit.URLUtil; import com.kuaishou.weapon.p0.t; import java.io.File; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.HashMap; import java.util.Map; import java.util.Random; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public class e { public static String a(Map<String, String> map) { if (map == null || map.isEmpty()) { return ""; } JSONArray jSONArray = new JSONArray(); try { for (Map.Entry<String, String> entry : map.entrySet()) { JSONObject jSONObject = new JSONObject(); jSONObject.put("k", entry.getKey()); jSONObject.put(t.c, entry.getValue()); jSONArray.put(jSONObject); } } catch (Exception e2) { e2.printStackTrace(); } return jSONArray.toString(); } public static boolean a(int i2) { return i2 == 301 || i2 == 302 || i2 == 303 || i2 == 300 || i2 == 307 || i2 == 308; } public static boolean b(String str, String str2) { return (f(str) && f(str2)) || (str != null && str.equals(str2)); } public static long c() { return System.currentTimeMillis(); } public static String d(String str) { if (TextUtils.isEmpty(str)) { str = b(); } return "." + str + ".tkddtmp"; } public static String e(String str) { if (TextUtils.isEmpty(str)) { return null; } try { return new URL(str).getHost(); } catch (MalformedURLException e2) { e2.printStackTrace(); return null; } } public static boolean f(String str) { return TextUtils.isEmpty(str); } public static boolean g(String str) { if (str == null || str.length() <= 6 || !str.substring(0, 7).equalsIgnoreCase("http://")) { return false; } return true; } public static boolean h(String str) { if (str == null || str.length() <= 7 || !str.substring(0, 8).equalsIgnoreCase("https://")) { return false; } return true; } public static Map<String, String> i(String str) { if (TextUtils.isEmpty(str)) { return null; } try { JSONArray jSONArray = new JSONArray(str); int length = jSONArray.length(); HashMap hashMap = new HashMap(); for (int i2 = 0; i2 < length; i2++) { JSONObject jSONObject = jSONArray.getJSONObject(i2); if (jSONObject != null) { String optString = jSONObject.optString("k"); String optString2 = jSONObject.optString(t.c); if (!TextUtils.isEmpty(optString)) { hashMap.put(optString, optString2); } } } return hashMap; } catch (JSONException e2) { e2.printStackTrace(); return null; } } public static String j(String str) { return TextUtils.isEmpty(str) ? "" : str; } public static long k(String str) { if (TextUtils.isEmpty(str)) { return -1; } try { return Long.parseLong(str); } catch (NumberFormatException e2) { e2.printStackTrace(); return -1; } } public static String l(String str) { if (TextUtils.isEmpty(str)) { return null; } String trim = str.trim(); if (trim.contains(";")) { String[] split = trim.split(";"); for (String str2 : split) { if (str2.trim().contains("/")) { return str2.trim(); } } } else if (trim.contains("/")) { return trim; } return null; } public static synchronized String b() { String b; synchronized (e.class) { b = b(String.valueOf(System.currentTimeMillis()) + new Random().nextInt(1000000)); } return b; } public static String c(String str, String str2) { try { URI uri = new URI(str); return new URI(uri.getScheme(), uri.getUserInfo(), str2, uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()).toURL().toString(); } catch (Exception e2) { e2.printStackTrace(); return null; } } public static String b(String str) { try { MessageDigest instance = MessageDigest.getInstance("MD5"); instance.update(str.getBytes()); byte[] digest = instance.digest(); StringBuilder sb = new StringBuilder(); for (byte b : digest) { int i2 = b; if (b < 0) { i2 = b + 256; } if (i2 < 16) { sb.append("0"); } sb.append(Integer.toHexString(i2 == 1 ? 1 : 0)); } return sb.toString(); } catch (NoSuchAlgorithmException e2) { e2.printStackTrace(); return ""; } } public static String c(String str) { String a = a(str); if (TextUtils.isEmpty(a)) { return a; } String replaceAll = a.replaceAll("[\\/|\\\\|\\*|\\:|\\||\"|'|\\<|\\>|\\{|\\}|\\?|\\%|,]", " "); return replaceAll.contains("../") ? replaceAll.replaceAll("\\.\\./", "") : replaceAll; } public static StringBuilder a(File file) { StringBuilder sb = new StringBuilder(); if (file == null) { sb.append("IS_NULL"); return sb; } sb.append("p:"); sb.append(file.getAbsoluteFile()); sb.append(","); boolean z = false; try { sb.append("ex:"); z = file.exists(); sb.append(z); } catch (Exception e2) { sb.append(e2.getMessage()); } sb.append(","); try { sb.append("len:"); sb.append(file.length()); } catch (Exception e3) { sb.append(e3.getMessage()); } sb.append(","); try { sb.append("rw:"); sb.append(file.canWrite()); } catch (Exception e4) { sb.append(e4.getMessage()); } sb.append(","); try { sb.append("r:"); sb.append(file.canRead()); } catch (Exception e5) { sb.append(e5.getMessage()); } if (Build.VERSION.SDK_INT >= 18 && z) { try { StatFs statFs = new StatFs(file.getAbsolutePath()); sb.append(",free:"); sb.append(statFs.getAvailableBytes()); } catch (Exception e6) { e6.printStackTrace(); sb.append(",free:"); sb.append(e6.getMessage()); } } return sb; } private static String a(String str) { if (TextUtils.isEmpty(str) || str.length() <= 80) { return str; } int lastIndexOf = str.lastIndexOf(46); if (lastIndexOf <= 0) { return str.substring(0, 79); } String substring = str.substring(lastIndexOf + 1); return str.substring(0, Math.min(lastIndexOf, 79)) + "." + substring; } public static String a(String str, String str2) { if (str2 != null && str2.startsWith("/")) { try { URI uri = new URI(str); URI uri2 = new URI("https://test.com" + str2); return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri2.getPath(), uri2.getQuery(), uri2.getFragment()).toString(); } catch (Exception e2) { e2.printStackTrace(); } } return str2; } public static String a(String str, String str2, String str3) { if (str2 == null) { str2 = ""; } if (str3 == null) { str3 = ""; } String guessFileName = URLUtil.guessFileName(str, str2, str3); if (TextUtils.isEmpty(guessFileName)) { return b(); } return c(guessFileName); } public static long a() { StatFs statFs = new StatFs(Environment.getDataDirectory().getPath()); return ((long) statFs.getAvailableBlocks()) * ((long) statFs.getBlockSize()); } }