简体   繁体   中英

java Netty Retrieve Data from Bytebuf

I am using java Netty 4 to read a external tcp socket to get some information and it returns the results as Bytebuf and pretty print looks as the attached screen shot

在此处输入图片说明

I went through the Bytebuf api and found there lots of methods to parse and read the Bytebuf content. I need to read the String data in column 3 to a java String. So i tried below

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

and it ended up with an outofbound exception and looks like it is not the solutions

What is the best possible way of doing this?

Thanks, Keth

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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