示例解析
package com.leolee.nio;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.Arrays;
/**
* @ClassName ScatteringAndGatheringTest
* @Description: TODO
* @Author LeoLee
* @Date 2020/9/20
* @Version V1.0
**/
public class ScatteringAndGatheringTest {
public static void test () throws IOException {
ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
InetSocketAddress inetSocketAddress = new InetSocketAddress(8899);
serverSocketChannel.socket().bind(inetSocketAddress);
SocketChannel socketChannel = serverSocketChannel.accept();
int messageLength = 2 + 3 + 4;
ByteBuffer[] byteBuffers = new ByteBuffer[3];
byteBuffers[0] = ByteBuffer.allocate(2);
byteBuffers[1]