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

目录
相关文章
|
1月前
|
Java API 容器
《跟闪电侠学Netty》阅读笔记 - 数据载体ByteBuf
《跟闪电侠学Netty》阅读笔记 - 数据载体ByteBuf
97 0
|
9月前
|
Java API 开发者
Netty详解ByteBuf
Netty详解ByteBuf
57 0
|
8天前
|
机器学习/深度学习 缓存 算法
netty源码解解析(4.0)-25 ByteBuf内存池:PoolArena-PoolChunk
netty源码解解析(4.0)-25 ByteBuf内存池:PoolArena-PoolChunk
|
1月前
|
Java API 索引
Netty Review - ByteBuf 读写索引 详解
Netty Review - ByteBuf 读写索引 详解
83 1
|
1月前
|
API 容器
《跟闪电侠学Netty》阅读笔记 - 数据载体ByteBuf(一)
《跟闪电侠学Netty》阅读笔记 - 数据载体ByteBuf
47 0
《跟闪电侠学Netty》阅读笔记 - 数据载体ByteBuf(一)
|
1月前
|
Java API
《跟闪电侠学Netty》阅读笔记 - 数据载体ByteBuf(二)
《跟闪电侠学Netty》阅读笔记 - 数据载体ByteBuf
34 0
|
8月前
|
Web App开发 监控 数据可视化
可视化Netty channel的工具
可视化Netty channel的工具
160 0
|
11月前
|
存储 Java API
Netty实战(五)ByteBuf—Netty的数据容器
网络数据的基本单位总是字节。Java NIO 提供了 ByteBuffer 作为它的字节容器,但是这个类使用起来过于复杂,而且也有些繁琐。**ByteBuffer 替代品是 ByteBuf**,一个强大的实现,既解决了 JDK API 的局限性,又为网络应用程序的开发者提供了更好的 API。
158 0
|
11月前
|
存储 Java Linux
Netty ByteBuf 的零拷贝(Zero Copy)详解
Netty ByteBuf 的零拷贝(Zero Copy)详解
157 0
|
11月前
Netty之ByteBuf解读(下)
Netty之ByteBuf解读(下)