package com.baidu.tts.tools; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.nio.channels.FileChannel; import java.security.MessageDigest; public class MD5 { private static volatile MD5 a; private char[] b = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; private MD5() { } public static MD5 getInstance() { if (a == null) { synchronized (MD5.class) { if (a == null) { a = new MD5(); } } } return a; } public String getMD5(byte[] bArr) { try { MessageDigest instance = MessageDigest.getInstance("MD5"); instance.update(bArr); byte[] digest = instance.digest(); int length = digest.length; char[] cArr = new char[(length * 2)]; int i = 0; for (int i2 = 0; i2 < length; i2++) { int i3 = i + 1; cArr[i] = this.b[(digest[i2] >>> 4) & 15]; i = i3 + 1; cArr[i3] = this.b[digest[i2] & 15]; } return new String(cArr); } catch (Exception unused) { return null; } } /* JADX WARNING: Removed duplicated region for block: B:21:0x0035 A[SYNTHETIC, Splitter:B:21:0x0035] */ /* JADX WARNING: Removed duplicated region for block: B:30:0x0041 A[SYNTHETIC, Splitter:B:30:0x0041] */ public String getBigFileMd5(File file) { FileInputStream fileInputStream; Throwable th; if (file == null) { return null; } try { MessageDigest instance = MessageDigest.getInstance("MD5"); fileInputStream = new FileInputStream(file); try { byte[] bArr = new byte[8192]; while (true) { int read = fileInputStream.read(bArr); if (read == -1) { break; } instance.update(bArr, 0, read); } String a2 = a(instance.digest()); try { fileInputStream.close(); } catch (IOException e) { e.printStackTrace(); } return a2; } catch (Exception unused) { if (fileInputStream != null) { try { fileInputStream.close(); } catch (IOException e2) { e2.printStackTrace(); } } return null; } catch (Throwable th2) { th = th2; if (fileInputStream != null) { try { fileInputStream.close(); } catch (IOException e3) { e3.printStackTrace(); } } throw th; } } catch (Exception unused2) { fileInputStream = null; if (fileInputStream != null) { } return null; } catch (Throwable th3) { th = th3; fileInputStream = null; if (fileInputStream != null) { } throw th; } } public String getBigFileMd5(String str) { return getBigFileMd5(new File(str)); } /* JADX WARNING: Removed duplicated region for block: B:24:0x004d A[SYNTHETIC, Splitter:B:24:0x004d] */ /* JADX WARNING: Removed duplicated region for block: B:29:0x0055 A[Catch:{ IOException -> 0x0051 }] */ /* JADX WARNING: Removed duplicated region for block: B:36:0x0061 A[SYNTHETIC, Splitter:B:36:0x0061] */ /* JADX WARNING: Removed duplicated region for block: B:41:0x0069 A[Catch:{ IOException -> 0x0065 }] */ public String getFileMd5(String str) { FileInputStream fileInputStream; FileChannel fileChannel; Throwable th; FileInputStream fileInputStream2; FileChannel fileChannel2 = null; try { MessageDigest instance = MessageDigest.getInstance("MD5"); File file = new File(str); fileInputStream = new FileInputStream(file); try { fileChannel = fileInputStream.getChannel(); try { instance.update(fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, file.length())); String a2 = a(instance.digest()); if (fileChannel != null) { try { fileChannel.close(); } catch (IOException e) { e.printStackTrace(); } } fileInputStream.close(); return a2; } catch (Exception unused) { if (fileChannel != null) { } if (fileInputStream != null) { } return null; } catch (Throwable th2) { fileInputStream2 = fileInputStream; th = th2; fileChannel2 = fileChannel; if (fileChannel2 != null) { } if (fileInputStream2 != null) { } throw th; } } catch (Exception unused2) { fileChannel = null; if (fileChannel != null) { try { fileChannel.close(); } catch (IOException e2) { e2.printStackTrace(); return null; } } if (fileInputStream != null) { fileInputStream.close(); } return null; } catch (Throwable th3) { fileInputStream2 = fileInputStream; th = th3; if (fileChannel2 != null) { try { fileChannel2.close(); } catch (IOException e3) { e3.printStackTrace(); throw th; } } if (fileInputStream2 != null) { fileInputStream2.close(); } throw th; } } catch (Exception unused3) { fileInputStream = null; fileChannel = null; if (fileChannel != null) { } if (fileInputStream != null) { } return null; } catch (Throwable th4) { th = th4; fileInputStream2 = null; if (fileChannel2 != null) { } if (fileInputStream2 != null) { } throw th; } } private String a(byte[] bArr) { return a(bArr, 0, bArr.length); } private String a(byte[] bArr, int i, int i2) { StringBuffer stringBuffer = new StringBuffer(i2 * 2); int i3 = i2 + i; while (i < i3) { a(bArr[i], stringBuffer); i++; } return stringBuffer.toString(); } private void a(byte b2, StringBuffer stringBuffer) { char[] cArr = this.b; char c = cArr[(b2 & 240) >> 4]; char c2 = cArr[b2 & 15]; stringBuffer.append(c); stringBuffer.append(c2); } }