use of com.alibaba.cobar.exception.UnknownCharsetException in project cobar by alibaba.
the class MySQLChannel method handshake.
private MySQLChannel handshake() throws IOException {
// 读取握手数据包
BinaryPacket initPacket = new BinaryPacket();
initPacket.read(in);
HandshakePacket hsp = new HandshakePacket();
hsp.read(initPacket);
// 设置通道参数
this.threadId = hsp.threadId;
int ci = hsp.serverCharsetIndex & 0xff;
if ((dbCharset = CharsetUtil.getDbCharset(ci)) != null) {
this.charsetIndex = ci;
this.charset = CharsetUtil.getCharset(ci);
} else {
throw new UnknownCharsetException("charset:" + ci);
}
// 发送认证数据包
BinaryPacket bin = null;
try {
bin = sendAuth411(hsp);
} catch (NoSuchAlgorithmException e) {
throw new IllegalArgumentException(e.getMessage());
}
switch(bin.data[0]) {
case OkPacket.FIELD_COUNT:
afterSuccess();
break;
case ErrorPacket.FIELD_COUNT:
ErrorPacket err = new ErrorPacket();
err.read(bin);
throw new ErrorPacketException(new String(err.message, charset));
case EOFPacket.FIELD_COUNT:
auth323(bin.packetId, hsp.seed);
break;
default:
throw new UnknownPacketException(bin.toString());
}
return this;
}
Aggregations