public static String calcMD5(final File file) throws IOException {
    // TODO: This method read the entire file in RAM. Make it iterative and
    // use a BufferedReader

    final FileInputStream reader = new FileInputStream(file);
    final byte[] data = new byte[(int) file.length()];

    reader.read(data);
    reader.close();

    final MessageDigest md;
    try {
      md = MessageDigest.getInstance("MD5");
    } catch (final NoSuchAlgorithmException e) {
      assert false : "MD5 not in list of algorithms";
      throw new RuntimeException(e);
    }

    md.update(data);

    final byte[] digest = md.digest();

    final StringBuilder md5 = new StringBuilder();

    for (final byte b : digest) {
      md5.append(String.format("%02X", b));
    }

    return md5.toString();
  }
Calculates the MD5 value of a file.

@param file The file in question.
@return A string that holds the MD5 sum of the file.
@throws IOException
java/zylib/src/main/java/com/google/security/zynamics/zylib/io/FileUtils.java