ByteBuf buf = Unpooled.buffer(10); byte[] data = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; buf.writeBytes(data);
ByteBuf buf = Unpooled.buffer(10); String message = "Hello world"; buf.writeBytes(message.getBytes());This example creates a ByteBuf with a capacity of 10 bytes and writes a string into it using the writeBytes method. The string is first converted to bytes using the getBytes method. Overall, the io.netty.buffer package library provides powerful tools for handling binary data in high-performance network communication.