Java ByteBuffer vs ChannelBuffer

Java ByteBuffer vs ChannelBuffer,java,asynchronous,netty,bytebuffer,Java,Asynchronous,Netty,Bytebuffer,我正在使用一些在netty之上实现的框架。我使用以下两个选项从客户端向服务器发送消息。我认为这两个代码段应该向套接字写入相同的字节,因为服务器端的行为是不同的。有什么不同 选项1:好的 ChannelBuffer buf = ChannelBuffers.buffer(1); buf.writeByte(0x1c); e.getChannel().write(buf); 选项2:失败 ByteBuffer buf = ByteBuffer.allocate(1); buf.put(0x1c);

我正在使用一些在netty之上实现的框架。我使用以下两个选项从客户端向服务器发送消息。我认为这两个代码段应该向套接字写入相同的字节,因为服务器端的行为是不同的。有什么不同

选项1:好的

ChannelBuffer buf = ChannelBuffers.buffer(1);
buf.writeByte(0x1c);
e.getChannel().write(buf);
选项2:失败

ByteBuffer buf = ByteBuffer.allocate(1);
buf.put(0x1c);
e.getChannel().write(ChannelBuffers.wrappedBuffer(buf));

在将ByteBuffer写入频道之前,必须先调用

buf.flip();

这使得写入时字节可见。

是的,现在它产生相同的结果。我在哪里可以更多地了解这个问题的性质。谢谢@尼古拉·库兹涅佐夫:你可以在