1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| package com.redisc;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
import static io.netty.buffer.ByteBufUtil.appendPrettyHexDump; import static io.netty.util.internal.StringUtil.NEWLINE;
@Slf4j public class Run {
public static void main(String[] args) throws IOException { ByteBuf byteBuf = ByteBufAllocator.DEFAULT.directBuffer(); System.out.println(byteBuf);
StringBuilder s = new StringBuilder(); for (int i = 0; i < 300; i++) { s.append(i); }
byteBuf.writeBytes(s.toString().getBytes()); log(byteBuf); }
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()); } }
|