package com.mbridge.msdk.foundation.tools; import com.applovin.exoplayer2.common.base.Ascii; import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; /* loaded from: classes4.dex */ public class ac { protected static MessageDigest b; protected static char[] a = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; private static String c = "SameFileMD5"; static { b = null; try { b = MessageDigest.getInstance(SameMD5.TAG); } catch (NoSuchAlgorithmException e) { System.err.println(ac.class.getName() + "初始化失败,MessageDigest不支持MD5Util."); e.printStackTrace(); } } public static String a(File file) throws IOException { MessageDigest messageDigest; RandomAccessFile randomAccessFile; if (file == null || !file.exists()) { return ""; } RandomAccessFile randomAccessFile2 = null; try { messageDigest = MessageDigest.getInstance(SameMD5.TAG); randomAccessFile = new RandomAccessFile(file, "r"); } catch (Throwable th) { th = th; } try { byte[] bArr = new byte[10485760]; while (true) { int read = randomAccessFile.read(bArr); if (read == -1) { break; } messageDigest.update(bArr, 0, read); } byte[] digest = messageDigest.digest(); String a2 = a(digest, 0, digest.length); try { randomAccessFile.close(); } catch (IOException e) { af.b(c, e.getMessage()); } return a2; } catch (Throwable th2) { th = th2; randomAccessFile2 = randomAccessFile; try { af.b(c, th.getMessage()); return ""; } finally { if (randomAccessFile2 != null) { try { randomAccessFile2.close(); } catch (IOException e2) { af.b(c, e2.getMessage()); } } } } } private static String a(byte[] bArr, int i, int i2) { StringBuffer stringBuffer = new StringBuffer(i2 * 2); int i3 = i2 + i; while (i < i3) { byte b2 = bArr[i]; char[] cArr = a; char c2 = cArr[(b2 & 240) >> 4]; char c3 = cArr[b2 & Ascii.SI]; stringBuffer.append(c2); stringBuffer.append(c3); i++; } return stringBuffer.toString(); } }