1、pom
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.75.Final</version>
</dependency>
package com.example.demo.util;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.Random;
public class NettyLearn {
public static void main(String[] args) {
//普通的buff 固定大小的堆buff
ByteBuf heapBuffer = Unpooled.buffer(128);
System.out.println(heapBuffer.readerIndex());
System.out.println(heapBuffer.writerIndex());
while (heapBuffer.isWritable()) {
//一个int类型占四字节
heapBuffer.writeInt(new Random().nextInt());
System.out.println(heapBuffer.writerIndex());
System.out.println(heapBuffer.readerIndex());
}
while (heapBuffer.isReadable()) {