繁体   English   中英

Netty io.netty.buffer.ByteBuf.array()引发异常-直接缓冲区

[英]Netty io.netty.buffer.ByteBuf.array() throws exception - direct buffer

我想将io.netty.buffer.ByteBuf打印为字符串。 但是io.netty.buffer.ByteBuf.array()引发如下异常。

java.lang.UnsupportedOperationException:io.netty.buffer.PooledUnsafeDirectByteBuf.array(PooledUnsafeDirectByteBuf.java:343)上的直接缓冲区

有人可以帮助我从io.netty.buffer.ByteBuf字节中获取byte []吗?

谢谢。

好的,我找到了一种打印值的方法。 如果有人感兴趣

byte[] bytes = new byte[buf.readableBytes()];
buf.duplicate().readBytes(bytes);
System.out.println(new String(bytes));

要将ByteBuf的内容打印为字符串,可以使用buf.toString(java.nio.charset.Charset)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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