diff --git a/cache/src/main/java/dev/openrs2/cache/BufferedFileChannel.kt b/cache/src/main/java/dev/openrs2/cache/BufferedFileChannel.kt index 80a26f2c..c6010163 100644 --- a/cache/src/main/java/dev/openrs2/cache/BufferedFileChannel.kt +++ b/cache/src/main/java/dev/openrs2/cache/BufferedFileChannel.kt @@ -17,12 +17,22 @@ public class BufferedFileChannel( ) : Flushable, Closeable { private var size = channel.size() - private val readBuffer = alloc.buffer(readBufferSize, readBufferSize) + private val readBuffer: ByteBuf private var readPos = -1L - private val writeBuffer = alloc.buffer(writeBufferSize, writeBufferSize) + private val writeBuffer: ByteBuf private var writePos = -1L + init { + val buf = alloc.buffer(readBufferSize, readBufferSize) + try { + writeBuffer = alloc.buffer(writeBufferSize, writeBufferSize) + readBuffer = buf.retain() + } finally { + buf.release() + } + } + public fun read(pos: Long, dest: ByteBuf, len: Int) { require(pos >= 0) require(len <= dest.writableBytes())