MD5FileUtils { public static MD5Hash computeMd5ForFile(File dataFile) throws IOException { InputStream in = new FileInputStream(dataFile); try { MessageDigest digester = MD5Hash.getDigester(); DigestInputStream dis = new DigestInputStream(in, digester); IOUtils.copyBytes(dis, new IOUtils.NullOutputStream(), 128 * 1024); return new MD5Hash(digester.digest()); } finally { IOUtils.closeStream(in); } }  static void verifySavedMD5(File dataFile, MD5Hash expectedMD5); static MD5Hash readStoredMd5ForFile(File dataFile); static MD5Hash computeMd5ForFile(File dataFile); static void saveMD5File(File dataFile, MD5Hash digest); static void renameMD5File(File oldDataFile, File newDataFile); static File getDigestFileForFile(File file); static final String MD5_SUFFIX; }
@Test public void testComputeMd5ForFile() throws Exception { MD5Hash computedDigest = MD5FileUtils.computeMd5ForFile(TEST_FILE); assertEquals(TEST_MD5, computedDigest); }