Two simple questions, which I am not able to solve by reading the documentation:
byte[]
ByteBuf
?ByteBuffer
ByteBuf
?The documentation seems pretty clear to me:
Creation of a buffer
It is recommended to create a new buffer using the helper methods in Unpooled rather than calling an individual implementation's constructor.
Then in Unpooled
, you've got options of wrapping or copying. For example:
Unpooled.copiedBuffer(ByteBuffer)
Unpooled.copiedBuffer(byte[])
Unpooled.wrappedBuffer(ByteBuffer)
Unpooled.wrappedBuffer(byte[])
Choose whichever method is appropriate based on whether you want changes made in the returned ByteBuf
to be passed through to the original byte array/buffer.