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());
    }
}

相关文章
|
4月前
|
Java API 容器
《跟闪电侠学Netty》阅读笔记 - 数据载体ByteBuf
《跟闪电侠学Netty》阅读笔记 - 数据载体ByteBuf
111 0
|
Java API 开发者
Netty详解ByteBuf
Netty详解ByteBuf
88 0
|
1月前
|
网络协议 测试技术 Apache
测试Netty高并发工具
测试Netty高并发工具
58 3
|
4月前
|
Java API 索引
Netty Review - ByteBuf 读写索引 详解
Netty Review - ByteBuf 读写索引 详解
142 1
|
4月前
|
API 容器
《跟闪电侠学Netty》阅读笔记 - 数据载体ByteBuf(一)
《跟闪电侠学Netty》阅读笔记 - 数据载体ByteBuf
59 0
《跟闪电侠学Netty》阅读笔记 - 数据载体ByteBuf(一)
|
4月前
|
Java API
《跟闪电侠学Netty》阅读笔记 - 数据载体ByteBuf(二)
《跟闪电侠学Netty》阅读笔记 - 数据载体ByteBuf
48 0
|
11月前
|
Web App开发 监控 数据可视化
可视化Netty channel的工具
可视化Netty channel的工具
234 0
|
Rust Dubbo 网络协议
通过 HTTP/2 协议案例学习 Java & Netty 性能调优:工具、技巧与方法论
通过 HTTP/2 协议案例学习 Java & Netty 性能调优:工具、技巧与方法论
12636 7
|
存储 Java Linux
Netty ByteBuf 的零拷贝(Zero Copy)详解
Netty ByteBuf 的零拷贝(Zero Copy)详解
203 0