Return to Snippet

Revision: 8262
at January 31, 2009 11:56 by narkisr


Updated Code
import java.security.MessageDigest

def generateMD5(final file) {
   MessageDigest digest = MessageDigest.getInstance("MD5")
   file.withInputStream(){is->
   byte[] buffer = new byte[8192]
   int read = 0
      while( (read = is.read(buffer)) > 0) {
             digest.update(buffer, 0, read);
         }
     }
   byte[] md5sum = digest.digest()
   BigInteger bigInt = new BigInteger(1, md5sum)
   return bigInt.toString(16)
}

Revision: 8261
at September 11, 2008 05:29 by narkisr


Initial Code
def generateMD5(final file) {
   MessageDigest digest = MessageDigest.getInstance("MD5")
   file.withInputStream(){is->
   byte[] buffer = new byte[8192]
   int read = 0
      while( (read = is.read(buffer)) > 0) {
             digest.update(buffer, 0, read);
         }
     }
   byte[] md5sum = digest.digest()
   BigInteger bigInt = new BigInteger(1, md5sum)
   return bigInt.toString(16)
}

Initial URL

                                

Initial Description
Generating MD5 HEX string from either URL or File instance in Groovy (more elegant than the Java version).

Initial Title
Groovy File and URL MD5

Initial Tags
groovy

Initial Language
Groovy