Two simple questions, which I am not able to solve by reading the documentation:
- I have a
byte[]- How can i convert it to a
ByteBuf?
- How can i convert it to a
- I have a NIO
ByteBuffer- How can i convert it to a
ByteBuf?
- How can i convert it to a
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.