Netty之ByteBuf读写字符串

1、pom 

     
            io.netty
            netty-all
            4.1.75.Final
        

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()) {
  

你可能感兴趣的:(netty,netty)