in lib/src/main/kotlin/org/jetbrains/zip/signer/datasource/SeekableByteChannelDataSource.kt [41:64]
override fun feed(writableByteChannel: WritableByteChannel, offset: Long, size: Long) {
val sourceSize = size()
checkChunkValid(offset, size, sourceSize)
if (size == 0L) return
var chunkOffsetInFile = this.offset + offset
var remaining = size
val buf = ByteBuffer.allocateDirect(remaining.toInt().coerceAtMost(MAX_READ_CHUNK_SIZE))
while (remaining > 0) {
val chunkSize = remaining.coerceAtMost(buf.capacity().toLong()).toInt()
var chunkRemaining = chunkSize
buf.limit(chunkSize)
channel.position(chunkOffsetInFile)
while (chunkRemaining > 0) {
val read = channel.read(buf)
if (read < 0) throw IOException("Unexpected EOF encountered")
chunkRemaining -= read
}
buf.flip()
writableByteChannel.write(buf)
buf.clear()
chunkOffsetInFile += chunkSize.toLong()
remaining -= chunkSize.toLong()
}
}