Skip to content

Instantly share code, notes, and snippets.

@dwijnand
Created November 27, 2014 01:46
Show Gist options
  • Save dwijnand/0338fccc9bf69313a059 to your computer and use it in GitHub Desktop.
Save dwijnand/0338fccc9bf69313a059 to your computer and use it in GitHub Desktop.
def digest(in: InputStream, md: MessageDigest): Array[Byte] = {
val buffer = new Array[Byte](0x1000)
@tailrec
def loop(count: Int): Array[Byte] = {
if (count == -1)
md.digest
else {
md.update(buffer, 0, count)
loop(in read buffer)
}
}
try loop(in read buffer) finally md.reset()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment