class FileUtil {

  public static final String getDigest(File _file, DigestAlgorithm _alg) {
    try {
      if (!_file.canRead()) throw new IOException("Cannot read file");

      // Digest preparation
      final MessageDigest md = MessageDigest.getInstance(_alg.toString());
      try (final InputStream is = new FileInputStream(_file);
          final DigestInputStream dis = new DigestInputStream(is, md); ) {
        byte[] bytes = new byte[1024];
        while (dis.read(bytes, 0, 1024) != -1) {
          ;
        } // read()
        byte[] digest = md.digest();
        return DigestUtil.bytesToHex(digest);
      }
    } catch (NoSuchAlgorithmException e) {
      FileUtil.log.error("Error while instantiating [" + _alg + "] digest: " + e.getMessage());
    } catch (IOException e) {
      FileUtil.log.error("IO Error while computing [" + _alg + "] digest: " + e.getMessage());
    } catch (ArrayIndexOutOfBoundsException be) {
      FileUtil.log.error("Error while computing [" + _alg + "] digest: " + be.getMessage());
    }
    return null;
  }

}