使NettyByteBuffer支持release

This commit is contained in:
tursom 2020-05-17 01:07:15 +08:00
parent 09699dc619
commit 066d78bbed

View File

@ -31,6 +31,7 @@ class NettyByteBuffer(
byteBuf.readerIndex(value) byteBuf.readerIndex(value)
} }
override val resized: Boolean get() = false override val resized: Boolean get() = false
override var closed: Boolean = false
override fun readBuffer(): java.nio.ByteBuffer { override fun readBuffer(): java.nio.ByteBuffer {
return byteBuf.internalNioBuffer(readPosition, readable).slice() return byteBuf.internalNioBuffer(readPosition, readable).slice()
@ -129,4 +130,11 @@ class NettyByteBuffer(
override fun toString(): String { override fun toString(): String {
return "Nettyjava.nio.ByteBuffer(byteBuf=$byteBuf)" return "Nettyjava.nio.ByteBuffer(byteBuf=$byteBuf)"
} }
override fun close() {
if (closed) {
closed = true
byteBuf.release()
}
}
} }