和通讯录 v3.9.6版本的 MD5 值为:669178e2ee1b2311daf378bd20c6bbe1

以下内容为反编译后的 CommonUtil.java 源代码,内容仅作参考


package com.huawei.mcs.util;

import android.util.Log;
import com.cmcc.sso.sdk.util.SsoSdkConstants;
import com.google.android.mms.pdu.EncodedStringValue;
import com.huawei.mcs.base.constant.Constant;
import com.huawei.tep.utils.FileUtil;
import com.huawei.tep.utils.Logger;
import com.huawei.tep.utils.StringUtil;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class CommonUtil {
    public static final String DEF_IP = "127.0.0.1";
    public static final String TAG = "CommonUtil";
    private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
    private static Map<String, String> fileTypeMap = null;

    public static String addCDATA(String str) {
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("<![CDATA[");
        stringBuffer.append(str.replaceAll("]]>", "]]]]><![CDATA[>"));
        stringBuffer.append("]]>");
        return stringBuffer.toString();
    }

    public static boolean containPathSpecialStrs(String str) {
        for (String str2 : new String[]{"\\", ":", "*", "?", "\"", "<", ">", "|"}) {
            if (str.contains(str2)) {
                return true;
            }
        }
        return false;
    }

    public static boolean containSpecialStrs(String str) {
        for (String str2 : new String[]{"\\", Constant.FilePath.IDND_PATH, ":", "*", "?", "\"", "<", ">", "|"}) {
            if (str.contains(str2)) {
                return true;
            }
        }
        return false;
    }

    public static String[] copyArray(String[] strArr, int i, int i2) {
        if (i2 > strArr.length) {
            i2 = strArr.length;
        }
        String[] strArr2 = new String[i2];
        for (int i3 = 0; i3 < i2; i3++) {
            strArr2[i3] = strArr[i3 + i];
        }
        return strArr2;
    }

    public static String getBase64Token(String str, String str2) {
        if (str == null || str2 == null) {
            return null;
        }
        String concat = str2.concat(":" + str);
        try {
            return Base64.encodeToString(concat.getBytes(EncodedStringValue.StringEncoding.UTF_8), 2);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return Base64.encodeToString(concat.getBytes(), 2);
        }
    }

    public static String getLocalIpAddress() {
        String str;
        String str2 = "";
        try {
            Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
            while (networkInterfaces.hasMoreElements()) {
                Enumeration<InetAddress> inetAddresses = networkInterfaces.nextElement().getInetAddresses();
                while (inetAddresses.hasMoreElements()) {
                    InetAddress nextElement = inetAddresses.nextElement();
                    str2 = (nextElement.isLoopbackAddress() || !(nextElement instanceof Inet4Address)) ? str2 : nextElement.getHostAddress();
                }
            }
            str = str2;
        } catch (SocketException e) {
            str = str2;
            Log.e("TEPDemoActivity", "SocketException");
        }
        return StringUtil.isNullOrEmpty(str) ? DEF_IP : str;
    }

    public static String getMD5(String str) {
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            messageDigest.update(str.getBytes());
            byte[] digest = messageDigest.digest();
            StringBuffer stringBuffer = new StringBuffer("");
            for (int i = 0; i < digest.length; i++) {
                int i2 = digest[i];
                if (i2 < 0) {
                    i2 += 256;
                }
                if (i2 < 16) {
                    stringBuffer.append("0");
                }
                stringBuffer.append(Integer.toHexString(i2));
            }
            return stringBuffer.toString();
        } catch (NoSuchAlgorithmException e) {
            Logger.e(TAG, "COUNT MD5 failed! str :" + str);
            e.printStackTrace();
            return null;
        }
    }

    public static String getMD5File(String str) {
        Throwable th;
        FileInputStream fileInputStream;
        String str2 = 0;
        str2 = 0;
        str2 = 0;
        str2 = 0;
        if (new File(str).exists()) {
            byte[] bArr = new byte[1024];
            try {
                try {
                    fileInputStream = new FileInputStream(str);
                    try {
                        MessageDigest messageDigest = MessageDigest.getInstance("MD5");
                        while (true) {
                            int read = fileInputStream.read(bArr);
                            if (read <= 0) {
                                break;
                            }
                            messageDigest.update(bArr, 0, read);
                        }
                        String hexString = toHexString(messageDigest.digest());
                        str2 = hexString;
                        if (fileInputStream != null) {
                            try {
                                fileInputStream.close();
                                str2 = hexString;
                            } catch (IOException e) {
                                Logger.e("MD5", "读取文件IOException", e);
                                str2 = hexString;
                            }
                        }
                    } catch (Exception e2) {
                        e = e2;
                        Logger.e("MD5", "读取文件md5失败", e);
                        if (fileInputStream != null) {
                            try {
                                fileInputStream.close();
                            } catch (IOException e3) {
                                Logger.e("MD5", "读取文件IOException", e3);
                            }
                        }
                        return str2;
                    }
                } catch (Throwable th2) {
                    th = th2;
                    if (0 != 0) {
                        try {
                            str2.close();
                        } catch (IOException e4) {
                            Logger.e("MD5", "读取文件IOException", e4);
                        }
                    }
                    throw th;
                }
            } catch (Exception e5) {
                e = e5;
                fileInputStream = null;
            } catch (Throwable th3) {
                th = th3;
                if (0 != 0) {
                }
                throw th;
            }
        }
        return str2;
    }

    public static String getStringToday() {
        String format = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        Logger.i(TAG, "getStringToday data = " + format);
        return format;
    }

    public static String getTimesLater(long j) {
        Date date = new Date();
        date.setTime(date.getTime() + (24 * j * 60 * 60 * 1000));
        String format = new SimpleDateFormat("yyyyMMddHHmmss").format(date);
        Logger.i(TAG, "getTimesLater data = " + format);
        return format;
    }

    public static synchronized int getTypeByFileName(String str) {
        int i;
        synchronized (CommonUtil.class) {
            String fileTypeString = FileUtil.getFileTypeString(str);
            if (fileTypeString == null) {
                i = -1;
            } else {
                if (fileTypeMap == null) {
                    fileTypeMap = new HashMap();
                    initFileTypeMap();
                }
                String str2 = fileTypeMap.get(fileTypeString);
                if (str2 != null && str2.equals("1")) {
                    i = 1;
                } else if (str2 == null || !str2.equals("2")) {
                    if (str2 != null) {
                        if (str2.equals(SsoSdkConstants.BUSI_TYPE_SMSLOGIN)) {
                            i = 3;
                        }
                    }
                    i = 5;
                } else {
                    i = 2;
                }
            }
        }
        return i;
    }

    private static void initFileTypeMap() {
        fileTypeMap.put("png", "1");
        fileTypeMap.put("jpg", "1");
        fileTypeMap.put("gif", "1");
        fileTypeMap.put("jpeg", "1");
        fileTypeMap.put("bmp", "1");
        fileTypeMap.put("mp3", "2");
        fileTypeMap.put("wav", "2");
        fileTypeMap.put("wma", "2");
        fileTypeMap.put("aac", "2");
        fileTypeMap.put("amr", "2");
        fileTypeMap.put("mp4", SsoSdkConstants.BUSI_TYPE_SMSLOGIN);
        fileTypeMap.put("3gp", SsoSdkConstants.BUSI_TYPE_SMSLOGIN);
    }

    public static boolean isObjArrayNullOrEmpty(Object[] objArr) {
        return objArr == null || objArr.length == 0;
    }

    public static boolean isStrArrayNullOrEmpty(String[] strArr) {
        return strArr == null || strArr.length == 0;
    }

    public static String map2Json(Map<String, String> map) {
        if (map == null) {
            return null;
        }
        StringBuffer stringBuffer = new StringBuffer();
        boolean z = false;
        stringBuffer.append("{");
        Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
        while (true) {
            boolean z2 = z;
            if (!it.hasNext()) {
                stringBuffer.append("}");
                return stringBuffer.toString();
            }
            Map.Entry<String, String> next = it.next();
            if (z2) {
                stringBuffer.append(",");
            }
            stringBuffer.append("\"").append(next.getKey()).append("\":");
            stringBuffer.append("\"").append(next.getValue()).append("\"");
            z = true;
        }
    }

    public static String map2Str(Map<String, String> map) {
        if (map == null) {
            return null;
        }
        StringBuffer stringBuffer = new StringBuffer();
        for (Map.Entry<String, String> entry : map.entrySet()) {
            stringBuffer.append("<").append(entry.getKey()).append(">");
            stringBuffer.append(entry.getValue());
            stringBuffer.append("</").append(entry.getKey()).append(">");
        }
        return stringBuffer.toString();
    }

    public static List<String> removeDuplicateWithOrder(List<String> list) {
        HashSet hashSet = new HashSet();
        ArrayList arrayList = new ArrayList();
        for (String str : list) {
            if (hashSet.add(str)) {
                arrayList.add(str);
            }
        }
        return arrayList;
    }

    public static String replaceSpecialStrs(String str) {
        if (str != null) {
            return str.replace("&amp;", "&");
        }
        return null;
    }

    public static String toHexString(byte[] bArr) {
        StringBuilder sb = new StringBuilder(bArr.length * 2);
        for (int i = 0; i < bArr.length; i++) {
            sb.append(HEX_DIGITS[(bArr[i] & 240) >>> 4]);
            sb.append(HEX_DIGITS[bArr[i] & 15]);
        }
        return sb.toString();
    }
}