【问题标题】:java Netty Retrieve Data from Bytebufjava Netty 从 Bytebuf 中检索数据
【发布时间】:2017-02-18 11:22:24
【问题描述】:

我正在使用 java Netty 4 读取外部 tcp 套接字以获取一些信息,它以 Bytebuf 的形式返回结果,并且漂亮的打印看起来像所附的屏幕截图

我浏览了 Bytebuf api,发现有很多方法可以解析和读取 Bytebuf 内容。我需要将第 3 列中的字符串数据读取到 java 字符串。 所以我在下面尝试了

int startWritableIndex = (capacity-numberOFWritableBytes);
    for(int i = startWritableIndex; startWritableIndex < capacity; i++){
        System.out.println(buf.getByte(i));
    }

最后出现了出站异常,看起来不是解决方案

最好的方法是什么?

谢谢, 凯斯

【问题讨论】:

  • 看起来您正在从缓冲区的可写部分读取数据。我建议只阅读或写作。

标签: java netty bytebuffer


【解决方案1】:

使用ByteBuf.toString(int, int, Charset)

【讨论】:

    猜你喜欢
    • 2013-10-18
    • 1970-01-01
    • 2016-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多