code: public static byte[] getHash( String digestName,
                                    File file ) throws NoSuchAlgorithmException, IOException {
          CheckArg.isNotNull(file, "file");
          MessageDigest digest = MessageDigest.getInstance(digestName);
          assert digest != null;
          InputStream in = new BufferedInputStream(new FileInputStream(file));
          boolean error = false;
          try {
              int bufSize = 1024;
              byte[] buffer = new byte[bufSize];
              int n = in.read(buffer, 0, bufSize);
              while (n != -1) {
                  digest.update(buffer, 0, n);
                  n = in.read(buffer, 0, bufSize);
              }
          } catch (IOException e) {
              error = true;
              throw e;
          } finally {
              try {
                  in.close();
              } catch (IOException e) {
                  if (!error) throw e;
              }
          }
          return digest.digest();
      }
docs: Get the hash of the supplied content, using the digest identified by the supplied name.
  
  @param digestName the name of the hashing function (or {@link MessageDigest message digest}) that should be used
  @param file the file whose content is to be hashed; may not be null
  @return the hash of the contents as a byte array
  @throws NoSuchAlgorithmException if the supplied algorithm could not be found
  @throws IOException if there is an error reading the file