code: public String calculate( File file )
          throws DigesterException, NoSuchAlgorithmException
      {
          // Try to open the file.
          FileInputStream fis;
          try
          {
              fis = new FileInputStream( file );
          }
          catch ( Exception e )
          {
              throw new DigesterException( "Unable not read " + file.getPath() + ": " + e.getMessage() );
          }
  
          String result;
  
          try
          {
              MessageDigest messageDigest = MessageDigest.getInstance( algorithm );
  
              // Stream the file contents to the MessageDigest.
              byte[] buffer = new byte[STREAMING_BUFFER_SIZE];
              int size = fis.read( buffer, 0, STREAMING_BUFFER_SIZE );
              while ( size >= 0 )
              {
                  messageDigest.update( buffer, 0, size );
                  size = fis.read( buffer, 0, STREAMING_BUFFER_SIZE );
              }
  
              result = new String( Hex.encode( messageDigest.digest() ) );
          }
          catch ( IOException e )
          {
              throw new DigesterException(
                  "Unable to calculate the " + getAlgorithm() + " hashcode for " + file.getPath() + ": "
                      + e.getMessage() );
          }
          finally
          {
              try
              {
                  fis.close();
              }
              catch ( IOException e )
              {
                  // Don't take any chance, return an empty string if something went wrong.
                  result = "";
              }
          }
          return result;
      }
docs: {@inheritDoc}