Created
March 4, 2011 00:37
-
-
Save nobeans/853924 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.security.MessageDigest | |
println "-"*40 | |
println "MessageDigest:" | |
File.metaClass.getMd5 = { | |
MessageDigest.getInstance("md5"). | |
digest(delegate.readBytes()). | |
collect{ String.format("%02x", it) }. | |
join() | |
} | |
File.metaClass.getSha1 = { | |
MessageDigest.getInstance("sha1"). | |
digest(delegate.readBytes()). | |
collect{ String.format("%02x", it) }. | |
join() | |
} | |
println new File(args[0]).md5 | |
println new File(args[0]).sha1 | |
println "-"*40 | |
println "AntBuilder#checksum:" | |
def getMd5(File file) { | |
new AntBuilder().with{ | |
checksum(file: file, algorithm: 'md5', property: 'result') | |
it.project.properties.result | |
} | |
} | |
def getSha1(File file) { | |
new AntBuilder().with{ | |
checksum(file: file, algorithm: 'sha1', property: 'result') | |
it.project.properties.result | |
} | |
} | |
println getMd5(new File(args[0])) | |
println getSha1(new File(args[0])) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
おお。せっかくGroovyベースならGrapeを使えば予備動作なしにJRubyも実行できますね!