groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gerald Wiltse <jerrywil...@gmail.com>
Subject Groovy Hash Calculations
Date Fri, 04 Mar 2016 14:18:12 GMT
Hello All,

I have this block, it's pretty compressed, just wondering if there is a
more groovy way to handle reading the buffer and computing the hash.

        def messageDigest = MessageDigest.getInstance("SHA1")
        def dis = new DigestInputStream(content, messageDigest)
        byte[] buffer = new byte[1024];
        while (dis.read(buffer) != -1) {}
        def sha1Hex = new BigInteger(1,
messageDigest.digest()).toString(16).padLeft(40, '0')


Gerald R. Wiltse
jerrywiltse@gmail.com

Mime
View raw message