从netty ByteBuf获取字符串

ari*_*ies 8 java bytebuffer netty

如何从netty获取字符串ByteBuf?截至目前,我能够逐字逐句地获得它.有没有办法直接获取字符串对象?

// message is of type ByteBuf
for (int i = 0; i < message.capacity(); i++) {
    byte b = message.payload().getByte(i);
    System.out.print((char) b);
}
Run Code Online (Sandbox Code Playgroud)

mil*_*ert 10

使用提供的方法ByteBuf.toString(Charset).