Groovy fileToMd5


/ Published in: Groovy
Save to your folder(s)

Groovy fileToMd5


Copy this code and paste it in your HTML
  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

You need to login to post a comment.