Posted By

laurenceosx on 02/14/13


Tagged

groovy


Versions (?)

Groovy fileToMd5


 / Published in: Groovy
 

Groovy fileToMd5

  1. def fileToMd5(File aFile) {
  2. def digest = java.security.MessageDigest.getInstance("MD5");
  3. aFile.withInputStream{ inpStream ->
  4. byte[] buffer = new byte[8192];
  5. int read = 0;
  6. while( (read=inpStream.read(buffer)) > 0 ) {
  7. digest.update(buffer, 0, read);
  8. }
  9. }
  10. byte[] md5sumByteArray = digest.digest();
  11. def bigInt = new BigInteger(1, md5sumByteArray);
  12. return bigInt.toString(16).padLeft(32, '0');
  13. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: drivesafetoday on February 15, 2013

The reference made to instance MD5 is Direct or Indirect?

You need to login to post a comment.