Created
September 12, 2014 23:00
-
-
Save massie/72209a3c15166eb4511f to your computer and use it in GitHub Desktop.
Scala SHA-1 Example
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
package example | |
import java.io.FileInputStream | |
import java.security.MessageDigest | |
object Sha1Example { | |
def main(args: Array[String]): Unit = { | |
val start = System.currentTimeMillis() | |
val sha1 = MessageDigest.getInstance("SHA1") | |
val bytes = new Array[Byte](1024 * 1024) | |
val fis = new FileInputStream("/workspace/data/ALL.chr22.phase1_release_v3.20101123.snps_indels_svs.genotypes.vcf.gz") | |
Stream.continually(fis.read(bytes)).takeWhile(-1 !=).foreach(sha1.update(bytes, 0, _)) | |
val hashBytes = sha1.digest() // finalize the hash | |
val sb = new StringBuffer() | |
hashBytes.foreach { a => sb.append(Integer.toString((a & 0xff) + 0x100, 16).substring(1))} | |
val end = System.currentTimeMillis() | |
println(sb.toString) | |
println("%d ms".format(end - start)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
which means my MacBook Pro, Mid 2012 2.3 GHz Intel Core i7 w/ flash storage handle ~180MB/s