Use kotlin rather that JDK9

This commit is contained in:
Him188 2020-02-04 08:49:32 +08:00
parent 6a605156e5
commit 4e57eea779

View File

@ -22,14 +22,15 @@ actual fun crc32(key: ByteArray): Int = CRC32().let { it.update(key); it.value.t
actual fun md5(byteArray: ByteArray): ByteArray = MessageDigest.getInstance("MD5").digest(byteArray)
fun InputStream.md5(): ByteArray = this.use {
val digest = MessageDigest.getInstance("md5")
digest.reset()
this.transferTo(object : OutputStream() {
override fun write(b: Int) {
digest.update(b.toByte())
}
})
this.use {
it.copyTo(object : OutputStream() {
override fun write(b: Int) {
digest.update(b.toByte())
}
})
}
return digest.digest()
}