fun read(buf: ByteArray) { var numToRead = buf.size if (position + numToRead > buffer.length) { numToRead = buffer.length - position System.arraycopy(buffer, position, buf, 0, numToRead) for (i in numToRead until buf.size) { buf[i] = 0 } } else { System.arraycopy(buffer, position, buf, 0, numToRead) } position += numToRead }
Reads up to < tt > buf.length < /tt > bytes from the stream into the given byte buffer .