@Throws(IOException::class) private fun streamToBytes(`in`: InputStream, length: Int): ByteArray? { val bytes = ByteArray(length) var count: Int var pos = 0 while (pos < length && `in`.read(bytes, pos, length - pos).also { count = it } != -1) { pos += count } if (pos != length) { throw IOException("Expected $length bytes, read $pos bytes") } return bytes }
Reads the contents of an InputStream into a byte [ ] .