共计 1770 个字符,预计需要花费 5 分钟才能阅读完成。
@Override
public void channelRead(final ChannelHandlerContext ctx, Object msg) throws IOException {ByteBuf byteBuf = (ByteBuf) msg;
ByteBuf byteBuf1 = Unpooled.copiedBuffer(byteBuf);
byte[] bytes = ByteBufUtil.getBytes(byteBuf1);
boolean flag = byteBuf1.readBoolean();
if (flag) {int str_length1 = byteBuf1.readInt();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes, 5, str_length1);
byte[] new_bytes = new byte[str_length1];
while (inputStream.read(new_bytes) != -1) {inputStream.close();
String plain = new String(new_bytes, CharsetUtil.UTF_8);
if (plain.equalsIgnoreCase("PLAIN")) {int aInt = byteBuf1.getInt(11);
String sql = parseBytesToString(byteBuf1, 11, aInt);
String[] split = sql.split("\u0000");
if (split.length==2){String userName = split[0];
String passWord = split[1];
System.out.println("userName ="+ userName);
System.out.println("passWord ="+ passWord);
}
}
}
}
byteBuf1.resetReaderIndex();
// byte[] bytes = ByteBufUtil.getBytes(byteBuf1);
int size = byteBuf1.readInt();
if (size>0 && byteBuf1.capacity()>=size){short unused = byteBuf1.readShort();
short message_type = byteBuf1.readShort();
int str_length = byteBuf1.readInt();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes,12,str_length);
byte[] new_bytes = new byte[str_length];
while (inputStream.read(new_bytes)!=-1){inputStream.close();
String statement = new String(new_bytes, CharsetUtil.UTF_8);
// System.out.println(statement);
if (statement.equalsIgnoreCase("ExecuteStatement")){byte aByte = byteBuf1.getByte(95);
String sql = parseBytesToString(byteBuf1, 84, aByte);
System.out.println("sql ==== >" + sql);
}
}
}
if (outboundChannel.isActive()) {outboundChannel.writeAndFlush(msg).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {if (future.isSuccess()) {
// was able to flush out data, start to read the next chunk
ctx.channel().read();
} else {future.channel().close();}
}
});
}
}
正文完