提交 0995889f 编写于 作者: 檀越@新空间's avatar 檀越@新空间 🐭

fix:分类

上级 007e4230
package com.kwan.shuyu.netty;
import com.kwan.shuyu.netty.handler.IProtocalHandler;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.util.CharsetUtil;
import io.netty.util.concurrent.DefaultEventExecutorGroup;
public class Server {
private static void start(int port) throws InterruptedException {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();//Bootstrap for client
b.group(bossGroup, workerGroup);
b.channel(NioServerSocketChannel.class);//always
b.childHandler(new ChannelInitializer() {
@Override
protected void initChannel(Channel ch) throws Exception {
//ch.pipeline().addLast(new PrintInboundHandler("id1"));
// ch.pipeline().addLast(new LineBasedFrameDecoder(80,false,false));
// ch.pipeline().addLast(new StringDecoder());
// ch.pipeline().addLast(new EchoHandler());
ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(1024, 2, 2, -2, 0));
ch.pipeline().addLast(new DefaultEventExecutorGroup(16), new IProtocalHandler());
ch.pipeline().addLast(new StringEncoder(CharsetUtil.UTF_8));
}
});
ChannelFuture f = b.bind(port).sync();
f.channel().closeFuture().sync();
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
public static void main(String[] args) throws InterruptedException {
start(8084);
}
}
\ No newline at end of file
package com.kwan.shuyu.netty;
public class TestNetty {
public static void main(String[] args) {
}
}
package com.kwan.shuyu.netty.handler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
public class EchoHandler extends ChannelInboundHandlerAdapter {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
String in = (String) msg;
ctx.channel().writeAndFlush(in);
}
}
package com.kwan.shuyu.netty.handler;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.CharsetUtil;
import java.util.Random;
public class IProtocalHandler extends ChannelInboundHandlerAdapter {
@Override
public void channelRead(ChannelHandlerContext ctx, final Object msg) throws Exception {
int sleep = 500 * new Random().nextInt(5);
System.out.println("sleep:" + sleep);
Thread.sleep(sleep);
final ByteBuf buf = (ByteBuf) msg;
char c1 = (char) buf.readByte();
char c2 = (char) buf.readByte();
if (c1 != 'J' || c2 != 'W') {
ctx.fireExceptionCaught(new Exception("magic error"));
return ;
}
buf.readShort();//skip length
String outputStr = buf.toString(CharsetUtil.UTF_8);
System.out.println(outputStr);
ctx.channel().writeAndFlush(outputStr+"\n");
}
}
package com.kwan.shuyu.netty.handler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandler;
public class PrintInboundHandler implements ChannelInboundHandler {
private final String id;
public PrintInboundHandler(String id) {
this.id = id;
}
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
System.out.println("handlerAdded " + id);
}
@Override
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
System.out.println("handlerRemoved " + id);
}
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
System.out.println("channelRegistered " + id);
ctx.fireChannelRegistered();
}
@Override
public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
System.out.println("channelUnregistered " + id);
ctx.fireChannelUnregistered();
}
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
System.out.println("channelActive " + id);
ctx.fireChannelActive();
}
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
System.out.println("channelInactive " + id);
ctx.fireChannelInactive();
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
System.out.println("channelRead " + id);
ctx.fireChannelRead(msg);
//ctx.channel().pipeline().fireChannelRead(msg);
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
System.out.println("channelReadComplete " + id);
ctx.fireChannelReadComplete();
}
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
System.out.println("userEventTriggered " + id);
}
@Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
System.out.println("channelWritabilityChanged " + id);
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
System.out.println("exceptionCaught " + id);
}
}
\ No newline at end of file
package com.kwan.shuyu.heima.netty_01_bytebuffer; package com.kwan.shuyu.netty_01_bytebuffer;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
......
package com.kwan.shuyu.heima.netty_01_bytebuffer; package com.kwan.shuyu.netty_01_bytebuffer;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
......
package com.kwan.shuyu.heima.netty_01_bytebuffer; package com.kwan.shuyu.netty_01_bytebuffer;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
......
package com.kwan.shuyu.heima.netty_01_bytebuffer; package com.kwan.shuyu.netty_01_bytebuffer;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
......
package com.kwan.shuyu.heima.netty_01_bytebuffer; package com.kwan.shuyu.netty_01_bytebuffer;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
......
package com.kwan.shuyu.heima.netty_01_bytebuffer; package com.kwan.shuyu.netty_01_bytebuffer;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
......
package com.kwan.shuyu.heima.netty_01_bytebuffer; package com.kwan.shuyu.netty_01_bytebuffer;
import com.kwan.shuyu.until.ByteBufferUtil; import com.kwan.shuyu.until.ByteBufferUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
......
package com.kwan.shuyu.heima.netty_01_bytebuffer; package com.kwan.shuyu.netty_01_bytebuffer;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
......
package com.kwan.shuyu.heima.netty_01_bytebuffer; package com.kwan.shuyu.netty_01_bytebuffer;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
......
package com.kwan.shuyu.heima.netty_01_bytebuffer; package com.kwan.shuyu.netty_01_bytebuffer;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
......
package com.kwan.shuyu.heima.netty_01_bytebuffer; package com.kwan.shuyu.netty_01_bytebuffer;
import com.kwan.shuyu.until.ByteBufferUtil; import com.kwan.shuyu.until.ByteBufferUtil;
......
package com.kwan.shuyu.heima.netty_01_bytebuffer; package com.kwan.shuyu.netty_01_bytebuffer;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
......
package com.kwan.shuyu.heima.netty_01_bytebuffer; package com.kwan.shuyu.netty_01_bytebuffer;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
......
package com.kwan.shuyu.heima.netty_02_file; package com.kwan.shuyu.netty_02_file;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
......
package com.kwan.shuyu.heima.netty_02_file; package com.kwan.shuyu.netty_02_file;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
......
package com.kwan.shuyu.heima.netty_02_file; package com.kwan.shuyu.netty_02_file;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
......
package com.kwan.shuyu.heima.netty_02_file; package com.kwan.shuyu.netty_02_file;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
......
package com.kwan.shuyu.heima.netty_02_file; package com.kwan.shuyu.netty_02_file;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
......
package com.kwan.shuyu.heima.netty_02_file; package com.kwan.shuyu.netty_02_file;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
......
package com.kwan.shuyu.heima.netty_02_file; package com.kwan.shuyu.netty_02_file;
import java.io.IOException; import java.io.IOException;
import java.nio.file.*; import java.nio.file.*;
......
package com.kwan.shuyu.heima.netty_02_file; package com.kwan.shuyu.netty_02_file;
import java.io.IOException; import java.io.IOException;
import java.nio.file.*; import java.nio.file.*;
......
package com.kwan.shuyu.heima.netty_02_file; package com.kwan.shuyu.netty_02_file;
import java.io.IOException; import java.io.IOException;
import java.nio.file.*; import java.nio.file.*;
......
package com.kwan.shuyu.heima.netty_02_file; package com.kwan.shuyu.netty_02_file;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
......
package com.kwan.shuyu.heima.netty_03_nio.c1_阻塞; package com.kwan.shuyu.netty_03_nio.c1_阻塞;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
......
package com.kwan.shuyu.heima.netty_03_nio.c1_阻塞; package com.kwan.shuyu.netty_03_nio.c1_阻塞;
import com.kwan.shuyu.until.ByteBufferUtil; import com.kwan.shuyu.until.ByteBufferUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
......
package com.kwan.shuyu.heima.netty_03_nio.c3_Selector; package com.kwan.shuyu.netty_03_nio.c2_非阻塞;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
......
package com.kwan.shuyu.heima.netty_03_nio.c2_非阻塞; package com.kwan.shuyu.netty_03_nio.c2_非阻塞;
import com.kwan.shuyu.until.ByteBufferUtil; import com.kwan.shuyu.until.ByteBufferUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
......
package com.kwan.shuyu.heima.netty_03_nio.c2_非阻塞; package com.kwan.shuyu.netty_03_nio.c3_Selector;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
......
package com.kwan.shuyu.heima.netty_03_nio.c3_Selector; package com.kwan.shuyu.netty_03_nio.c3_Selector;
import com.kwan.shuyu.until.ByteBufferUtil; import com.kwan.shuyu.until.ByteBufferUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
......
package com.kwan.shuyu.heima.netty_03_nio.c4_attachment; package com.kwan.shuyu.netty_03_nio.c4_attachment;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
......
package com.kwan.shuyu.heima.netty_03_nio.c4_attachment; package com.kwan.shuyu.netty_03_nio.c4_attachment;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
......
package com.kwan.shuyu.heima.netty_03_nio.c5_attach; package com.kwan.shuyu.netty_03_nio.c5_attach;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
......
package com.kwan.shuyu.heima.netty_03_nio.c5_attach; package com.kwan.shuyu.netty_03_nio.c5_attach;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
......
package com.kwan.shuyu.heima.netty_03_nio.c6_write; package com.kwan.shuyu.netty_03_nio.c6_write;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
......
package com.kwan.shuyu.heima.netty_03_nio.c6_write; package com.kwan.shuyu.netty_03_nio.c6_write;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
......
package com.kwan.shuyu.heima.netty_03_nio.c7_optimization; package com.kwan.shuyu.netty_03_nio.c7_optimization;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
......
package com.kwan.shuyu.heima.netty_03_nio.c7_optimization; package com.kwan.shuyu.netty_03_nio.c7_optimization;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
......
package com.kwan.shuyu.heima.netty_03_nio.c7_optimization; package com.kwan.shuyu.netty_03_nio.c7_optimization;
import com.kwan.shuyu.until.ByteBufferUtil; import com.kwan.shuyu.until.ByteBufferUtil;
......
package com.kwan.shuyu.heima.netty_03_nio.c7_optimization; package com.kwan.shuyu.netty_03_nio.c7_optimization;
import com.kwan.shuyu.until.ByteBufferUtil; import com.kwan.shuyu.until.ByteBufferUtil;
......
package com.kwan.shuyu.heima.netty_03_nio.c8_aio; package com.kwan.shuyu.netty_03_nio.c8_aio;
import com.kwan.shuyu.until.ByteBufferUtil; import com.kwan.shuyu.until.ByteBufferUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
......
package com.kwan.shuyu.heima.netty_04_netty.c10_listener; package com.kwan.shuyu.netty_04_netty.c10_listener;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
......
package com.kwan.shuyu.heima.netty_04_netty.c10_listener; package com.kwan.shuyu.netty_04_netty.c10_listener;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
......
package com.kwan.shuyu.heima.netty_04_netty.c11_Scanner; package com.kwan.shuyu.netty_04_netty.c11_Scanner;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
......
package com.kwan.shuyu.heima.netty_04_netty.c11_Scanner; package com.kwan.shuyu.netty_04_netty.c11_Scanner;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
......
package com.kwan.shuyu.heima.netty_04_netty.c12_closesync; package com.kwan.shuyu.netty_04_netty.c12_closesync;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
......
package com.kwan.shuyu.heima.netty_04_netty.c12_closesync; package com.kwan.shuyu.netty_04_netty.c12_closesync;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
......
package com.kwan.shuyu.heima.netty_04_netty.c13_closefeature; package com.kwan.shuyu.netty_04_netty.c13_closefeature;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
......
package com.kwan.shuyu.heima.netty_04_netty.c13_closefeature; package com.kwan.shuyu.netty_04_netty.c13_closefeature;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
......
package com.kwan.shuyu.heima.netty_04_netty.c1_basic; package com.kwan.shuyu.netty_04_netty.c1_basic;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
......
package com.kwan.shuyu.heima.netty_04_netty.c1_basic; package com.kwan.shuyu.netty_04_netty.c1_basic;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
......
package com.kwan.shuyu.heima.netty_04_netty.c2_ByteBuf; package com.kwan.shuyu.netty_04_netty.c2_ByteBuf;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
......
package com.kwan.shuyu.heima.netty_04_netty.c2_ByteBuf; package com.kwan.shuyu.netty_04_netty.c2_ByteBuf;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
......
package com.kwan.shuyu.heima.netty_04_netty.c3_fireChannelRead; package com.kwan.shuyu.netty_04_netty.c3_fireChannelRead;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
......
package com.kwan.shuyu.heima.netty_04_netty.c3_fireChannelRead; package com.kwan.shuyu.netty_04_netty.c3_fireChannelRead;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
......
package com.kwan.shuyu.heima.netty_04_netty.c4_EventLoopGroup; package com.kwan.shuyu.netty_04_netty.c4_EventLoopGroup;
import io.netty.channel.DefaultEventLoopGroup; import io.netty.channel.DefaultEventLoopGroup;
......
package com.kwan.shuyu.heima.netty_04_netty.c4_EventLoopGroup; package com.kwan.shuyu.netty_04_netty.c4_EventLoopGroup;
import io.netty.channel.DefaultEventLoopGroup; import io.netty.channel.DefaultEventLoopGroup;
......
package com.kwan.shuyu.heima.netty_04_netty.c5_schedule; package com.kwan.shuyu.netty_04_netty.c5_schedule;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
......
package com.kwan.shuyu.heima.netty_04_netty.c6_codec; package com.kwan.shuyu.netty_04_netty.c6_codec;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
......
package com.kwan.shuyu.heima.netty_04_netty.c6_codec; package com.kwan.shuyu.netty_04_netty.c6_codec;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
......
package com.kwan.shuyu.heima.netty_04_netty.c9_sync; package com.kwan.shuyu.netty_04_netty.c7_channel;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
......
package com.kwan.shuyu.heima.netty_04_netty.c7_channel; package com.kwan.shuyu.netty_04_netty.c7_channel;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
......
package com.kwan.shuyu.heima.netty_04_netty.c8_log; package com.kwan.shuyu.netty_04_netty.c8_log;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
......
package com.kwan.shuyu.heima.netty_04_netty.c8_log; package com.kwan.shuyu.netty_04_netty.c8_log;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
......
package com.kwan.shuyu.heima.netty_04_netty.c7_channel; package com.kwan.shuyu.netty_04_netty.c9_sync;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
......
package com.kwan.shuyu.heima.netty_04_netty.c9_sync; package com.kwan.shuyu.netty_04_netty.c9_sync;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
......
package com.kwan.shuyu.heima.netty_05_future; package com.kwan.shuyu.netty_05_future;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
......
package com.kwan.shuyu.heima.netty_05_future; package com.kwan.shuyu.netty_05_future;
import io.netty.channel.EventLoop; import io.netty.channel.EventLoop;
import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup;
......
package com.kwan.shuyu.heima.netty_05_future; package com.kwan.shuyu.netty_05_future;
import io.netty.channel.EventLoop; import io.netty.channel.EventLoop;
import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup;
......
package com.kwan.shuyu.heima.netty_05_future; package com.kwan.shuyu.netty_05_future;
import io.netty.channel.EventLoop; import io.netty.channel.EventLoop;
import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup;
......
package com.kwan.shuyu.heima.netty_05_future; package com.kwan.shuyu.netty_05_future;
import io.netty.channel.EventLoop; import io.netty.channel.EventLoop;
import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup;
......
package com.kwan.shuyu.heima.netty_06_pipeline; package com.kwan.shuyu.netty_06_pipeline;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
......
package com.kwan.shuyu.heima.netty_06_pipeline; package com.kwan.shuyu.netty_06_pipeline;
import io.netty.bootstrap.ServerBootstrap; import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
......
package com.kwan.shuyu.heima.netty_06_pipeline; package com.kwan.shuyu.netty_06_pipeline;
import lombok.Data; import lombok.Data;
......
package com.kwan.shuyu.heima.netty_06_pipeline; package com.kwan.shuyu.netty_06_pipeline;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
...@@ -69,11 +69,11 @@ public class TestEmbeddedChannel { ...@@ -69,11 +69,11 @@ public class TestEmbeddedChannel {
/** /**
* 输出结果 * 输出结果
* [main] INFO com.kwan.shuyu.heima.netty_06_pipeline.TestEmbeddedChannel - 1 * [main] INFO com.kwan.shuyu.netty_06_pipeline.TestEmbeddedChannel - 1
* [main] INFO com.kwan.shuyu.heima.netty_06_pipeline.TestEmbeddedChannel - 2 * [main] INFO com.kwan.shuyu.netty_06_pipeline.TestEmbeddedChannel - 2
* [main] INFO com.kwan.shuyu.heima.netty_06_pipeline.TestEmbeddedChannel - 3333333333333333 * [main] INFO com.kwan.shuyu.netty_06_pipeline.TestEmbeddedChannel - 3333333333333333
* [main] INFO com.kwan.shuyu.heima.netty_06_pipeline.TestEmbeddedChannel - 5 * [main] INFO com.kwan.shuyu.netty_06_pipeline.TestEmbeddedChannel - 5
* [main] INFO com.kwan.shuyu.heima.netty_06_pipeline.TestEmbeddedChannel - 4 * [main] INFO com.kwan.shuyu.netty_06_pipeline.TestEmbeddedChannel - 4
* hello * hello
*/ */
} }
......
package com.kwan.shuyu.heima.netty_07_bytebuf; package com.kwan.shuyu.netty_07_bytebuf;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
......
package com.kwan.shuyu.heima.netty_07_bytebuf; package com.kwan.shuyu.netty_07_bytebuf;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
......
package com.kwan.shuyu.heima.netty_07_bytebuf; package com.kwan.shuyu.netty_07_bytebuf;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
...@@ -27,9 +27,9 @@ public class ByteBuf_03 { ...@@ -27,9 +27,9 @@ public class ByteBuf_03 {
log(buffer); log(buffer);
//上面代码创建了一个默认的ByteBuf(池化基于直接内存的 ByteBuf),初始容量是10 //上面代码创建了一个默认的ByteBuf(池化基于直接内存的 ByteBuf),初始容量是10
/** /**
[main] INFO com.kwan.shuyu.heima.netty_07_bytebuf.ByteBuf_03 - PooledUnsafeDirectByteBuf [main] INFO com.kwan.shuyu.netty_07_bytebuf.ByteBuf_03 - PooledUnsafeDirectByteBuf
[main] INFO com.kwan.shuyu.heima.netty_07_bytebuf.ByteBuf_03 - PooledUnsafeHeapByteBuf [main] INFO com.kwan.shuyu.netty_07_bytebuf.ByteBuf_03 - PooledUnsafeHeapByteBuf
[main] INFO com.kwan.shuyu.heima.netty_07_bytebuf.ByteBuf_03 - PooledUnsafeDirectByteBuf [main] INFO com.kwan.shuyu.netty_07_bytebuf.ByteBuf_03 - PooledUnsafeDirectByteBuf
read index:0 write index:0 capacity:10 read index:0 write index:0 capacity:10
*/ */
} }
......
package com.kwan.shuyu.heima.netty_07_bytebuf; package com.kwan.shuyu.netty_07_bytebuf;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
......
package com.kwan.shuyu.heima.netty_07_bytebuf; package com.kwan.shuyu.netty_07_bytebuf;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
......
package com.kwan.shuyu.heima.netty_07_bytebuf; package com.kwan.shuyu.netty_07_bytebuf;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
......
package com.kwan.shuyu.heima.netty_07_bytebuf; package com.kwan.shuyu.netty_07_bytebuf;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
......
package com.kwan.shuyu.heima.netty_07_bytebuf; package com.kwan.shuyu.netty_07_bytebuf;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
...@@ -79,8 +79,8 @@ public class ByteBuf_08 { ...@@ -79,8 +79,8 @@ public class ByteBuf_08 {
* at io.netty.buffer.ByteBufUtil$HexUtil.access$500(ByteBufUtil.java:1420) * at io.netty.buffer.ByteBufUtil$HexUtil.access$500(ByteBufUtil.java:1420)
* at io.netty.buffer.ByteBufUtil.appendPrettyHexDump(ByteBufUtil.java:1416) * at io.netty.buffer.ByteBufUtil.appendPrettyHexDump(ByteBufUtil.java:1416)
* at io.netty.buffer.ByteBufUtil.appendPrettyHexDump(ByteBufUtil.java:1407) * at io.netty.buffer.ByteBufUtil.appendPrettyHexDump(ByteBufUtil.java:1407)
* at com.kwan.shuyu.heima.netty_07_bytebuf.ByteBuf_08.log(ByteBuf_08.java:79) * at com.kwan.shuyu.netty_07_bytebuf.ByteBuf_08.log(ByteBuf_08.java:79)
* at com.kwan.shuyu.heima.netty_07_bytebuf.ByteBuf_08.main(ByteBuf_08.java:67) * at com.kwan.shuyu.netty_07_bytebuf.ByteBuf_08.main(ByteBuf_08.java:67)
*/ */
} }
......
package com.kwan.shuyu.heima.netty_07_bytebuf; package com.kwan.shuyu.netty_07_bytebuf;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
......
package com.kwan.shuyu.heima.netty_07_bytebuf; package com.kwan.shuyu.netty_07_bytebuf;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
......
package com.kwan.shuyu.heima.netty_07_bytebuf; package com.kwan.shuyu.netty_07_bytebuf;
import io.netty.buffer.*; import io.netty.buffer.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
......
package com.kwan.shuyu.heima.netty_08_socket; package com.kwan.shuyu.netty_08_socket;
import java.io.*; import java.io.*;
import java.net.Socket; import java.net.Socket;
......
package com.kwan.shuyu.heima.netty_08_socket; package com.kwan.shuyu.netty_08_socket;
import java.io.*; import java.io.*;
import java.net.ServerSocket; import java.net.ServerSocket;
......
package com.kwan.shuyu.old; package com.kwan.shuyu.netty_09_io;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
......
package com.kwan.shuyu.old; package com.kwan.shuyu.netty_09_io;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
......
package com.kwan.shuyu.old; package com.kwan.shuyu.netty_09_io;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.DataOutputStream; import java.io.DataOutputStream;
......
package com.kwan.shuyu.old; package com.kwan.shuyu.netty_09_io;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
......
package com.kwan.shuyu.until; package com.kwan.shuyu.until;
import io.netty.buffer.ByteBuf;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import static io.netty.util.internal.MathUtil.isOutOfBounds; import static io.netty.util.internal.MathUtil.isOutOfBounds;
import static io.netty.util.internal.StringUtil.NEWLINE;
/** /**
* ByteBuffer工具类 * ByteBuffer工具类
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册