Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

NIO Buffer case study of Netty

Shulou Source: shulou.com Published: 2022-06-01 23:19:46 10月04日 Update

This article mainly introduces the "NIO Buffer case study of Netty". In the daily operation, I believe that many people have doubts about the NIO Buffer case study of Netty. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "Netty NIO Buffer case Analysis"! Next, please follow the editor to study!

1. Buffer concept

1. Buffer acquisition

A Buffer buffer is an array with different data types: ByteBuffer, CharBuffer, ShortBuffer, IntBuffer, LongBuffer, FloatBuffer, DoubleBuffer, and then these data types can get the buffer through allocate ().

Static XxxBuffer allocate (int capacity): create a XxxBuffer object with the capacity of capacity, as follows:

/ / 1. Allocate a buffer of type Byte of specified size ByteBuffer byteBuffer = ByteBuffer.allocate (1024)

2. Two core methods of buffer access to data.

Put (): save data to a buffer

Put (byte b) writes a given single byte to the current location of the buffer

Put (byte [] src)

Writes bytes from src to the current location of the buffer

Put (int index, byte b)

Writes the specified byte to the index position of the buffer (position is not moved)

Get (): get the data in the buffer

Get ()

Read a single byte

Get (byte [] dst)

Read multiple bytes into dst in batch

Get (int index)

Reads the bytes at the specified index location (position is not moved)

ByteBuffer.put ("Mujiutian"); byteBuffer.get ()

3. Four core attributes in the buffer

0

Tags: Buffer buffer data location method byte type allocation case case study analysis subscript capacity mode learning content size result switch that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Docker MariaDB Redmi MySQL