Create a ByteBuf in Netty 4.0
28,524
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.
Related videos on Youtube
Author by
Dennis
Updated on February 13, 2020Comments
-
Dennis over 4 years
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
- I have a
-
Ismail Yavuz almost 7 yearsExample: Unpooled.wrappedBuffer(new byte[] { 0x0D, 0X0A })