如何从ByteBuf
有效地获取下面的代码中的字节数组?我需要获取数组然后序列化它。Netty java从ByteBuf获取数据
package testingNetty;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
public class ServerHandler extends ChannelInboundHandlerAdapter {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
System.out.println("Message receive");
ByteBuf buff = (ByteBuf) msg;
// There is I need get bytes from buff and make serialization
byte[] bytes = BuffConvertor.GetBytes(buff);
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
// Close the connection when an exception is raised.
cause.printStackTrace();
ctx.close();
}
}
你能请张贴的完整代码。还要提到你使用的是哪个版本的netty? –
我使用Netty的4.0.9版本 – NiceTheo
那么问题是什么?在上述背景下,字节量是多少? –