@Test public void testCalculateMd5ForInputStream() throws Exception { Assert.assertEquals("2a66a876a40630539e220890dc897550", FileUtils.calculateMd5(getInputStream("com.wlqq.phantom.plugin.sample1_1.0.0.apk"))); }
@Nullable static String calculateMd5(@NonNull InputStream inputStream) { MessageDigest digest; try { digest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { VLog.w(e, "Exception while getting digest"); return null; } byte[] buffer = new byte[8192]; int read; try { while ((read = inputStream.read(buffer)) > 0) { digest.update(buffer, 0, read); } byte[] md5sum = digest.digest(); BigInteger bigInt = new BigInteger(1, md5sum); String output = bigInt.toString(16); output = String.format("%32s", output).replace(' ', '0'); return output; } catch (IOException e) { VLog.w(e, "Unable to process file for MD5"); return null; } finally { IoUtils.closeQuietly(inputStream); } }
FileUtils { @Nullable static String calculateMd5(@NonNull InputStream inputStream) { MessageDigest digest; try { digest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { VLog.w(e, "Exception while getting digest"); return null; } byte[] buffer = new byte[8192]; int read; try { while ((read = inputStream.read(buffer)) > 0) { digest.update(buffer, 0, read); } byte[] md5sum = digest.digest(); BigInteger bigInt = new BigInteger(1, md5sum); String output = bigInt.toString(16); output = String.format("%32s", output).replace(' ', '0'); return output; } catch (IOException e) { VLog.w(e, "Unable to process file for MD5"); return null; } finally { IoUtils.closeQuietly(inputStream); } } }
FileUtils { @Nullable static String calculateMd5(@NonNull InputStream inputStream) { MessageDigest digest; try { digest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { VLog.w(e, "Exception while getting digest"); return null; } byte[] buffer = new byte[8192]; int read; try { while ((read = inputStream.read(buffer)) > 0) { digest.update(buffer, 0, read); } byte[] md5sum = digest.digest(); BigInteger bigInt = new BigInteger(1, md5sum); String output = bigInt.toString(16); output = String.format("%32s", output).replace(' ', '0'); return output; } catch (IOException e) { VLog.w(e, "Unable to process file for MD5"); return null; } finally { IoUtils.closeQuietly(inputStream); } } private  FileUtils(); }
FileUtils { @Nullable static String calculateMd5(@NonNull InputStream inputStream) { MessageDigest digest; try { digest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { VLog.w(e, "Exception while getting digest"); return null; } byte[] buffer = new byte[8192]; int read; try { while ((read = inputStream.read(buffer)) > 0) { digest.update(buffer, 0, read); } byte[] md5sum = digest.digest(); BigInteger bigInt = new BigInteger(1, md5sum); String output = bigInt.toString(16); output = String.format("%32s", output).replace(' ', '0'); return output; } catch (IOException e) { VLog.w(e, "Unable to process file for MD5"); return null; } finally { IoUtils.closeQuietly(inputStream); } } private  FileUtils(); static boolean isDirectoryEmpty(@NonNull File directory); static byte[] toByteArray(InputStream inStream); static File ensureDirectoryCreated(@NonNull File folder); static boolean deleteDir(@Nullable File dir); static void cleanDir(File dir); static void copyInputStreamToFile(@NonNull InputStream source, @NonNull File destination); static long copyStream(InputStream input, OutputStream output); static long copyStream(InputStream input, OutputStream output, byte[] buffer); static void copyFile(File srcFile, File destFile); static void closeZipFileQuietly(@Nullable ZipFile zipFile); static int readFileToInt(final File file); static void writeIntToFile(final File file, int data); @Nullable static String calculateMd5(@NonNull File file); }
FileUtils { @Nullable static String calculateMd5(@NonNull InputStream inputStream) { MessageDigest digest; try { digest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { VLog.w(e, "Exception while getting digest"); return null; } byte[] buffer = new byte[8192]; int read; try { while ((read = inputStream.read(buffer)) > 0) { digest.update(buffer, 0, read); } byte[] md5sum = digest.digest(); BigInteger bigInt = new BigInteger(1, md5sum); String output = bigInt.toString(16); output = String.format("%32s", output).replace(' ', '0'); return output; } catch (IOException e) { VLog.w(e, "Unable to process file for MD5"); return null; } finally { IoUtils.closeQuietly(inputStream); } } private  FileUtils(); static boolean isDirectoryEmpty(@NonNull File directory); static byte[] toByteArray(InputStream inStream); static File ensureDirectoryCreated(@NonNull File folder); static boolean deleteDir(@Nullable File dir); static void cleanDir(File dir); static void copyInputStreamToFile(@NonNull InputStream source, @NonNull File destination); static long copyStream(InputStream input, OutputStream output); static long copyStream(InputStream input, OutputStream output, byte[] buffer); static void copyFile(File srcFile, File destFile); static void closeZipFileQuietly(@Nullable ZipFile zipFile); static int readFileToInt(final File file); static void writeIntToFile(final File file, int data); @Nullable static String calculateMd5(@NonNull File file); static final long ONE_KB; static final long ONE_MB; }