netty查看ByteBuf工具

简介: netty查看ByteBuf工具

log方法

 
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
 
import static io.netty.buffer.ByteBufUtil.appendPrettyHexDump;
import static io.netty.util.internal.StringUtil.NEWLINE;
 
public class nettyxxx {
    public static void main(String[] args) {
        ByteBuf buf= ByteBufAllocator.DEFAULT.buffer(10);
            buf.writeBytes(new byte[]{'a','b','c','d','e','f','g','h'});
            log(buf);
    }
    private static void log(ByteBuf buffer){
        int length=buffer.readableBytes();
        int rows=length/16+(length%15==0?0:1)+4;
        StringBuilder buf=new StringBuilder(rows*80*2)
                .append("read index:").append(buffer.readerIndex())
                .append(" write index:").append(buffer.writerIndex())
                .append(" capacity:").append(buffer.capacity())
                .append(NEWLINE);
        appendPrettyHexDump(buf,buffer);
        System.out.println(buf.toString());
    }
}

目录
打赏
0
0
0
0
139
分享
相关文章
《跟闪电侠学Netty》阅读笔记 - 数据载体ByteBuf
《跟闪电侠学Netty》阅读笔记 - 数据载体ByteBuf
230 0
Netty Review - ByteBuf 读写索引 详解
Netty Review - ByteBuf 读写索引 详解
267 1
《跟闪电侠学Netty》阅读笔记 - 数据载体ByteBuf(二)
《跟闪电侠学Netty》阅读笔记 - 数据载体ByteBuf
152 0
《跟闪电侠学Netty》阅读笔记 - 数据载体ByteBuf(一)
《跟闪电侠学Netty》阅读笔记 - 数据载体ByteBuf
112 0
《跟闪电侠学Netty》阅读笔记 - 数据载体ByteBuf(一)
Netty ByteBuf 的零拷贝(Zero Copy)详解
Netty ByteBuf 的零拷贝(Zero Copy)详解
356 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等

登录插画

登录以查看您的控制台资源

管理云资源
状态一览
快捷访问