简体   繁体   中英

Create a ByteBuf in Netty 4.0

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM