31

Two simple questions, which I am not able to solve by reading the documentation:

  1. I have a byte[]
    • How can i convert it to a ByteBuf?
  2. I have a NIO ByteBuffer
    • How can i convert it to a ByteBuf?
Uvuvwevwevwe
  • 971
  • 14
  • 30
Dennis
  • 4,011
  • 7
  • 36
  • 50

1 Answers1

60

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:

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.

Community
  • 1
  • 1
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194