File tree 1 file changed +10
-4
lines changed
src/main/java/com/github/shyiko/mysql/binlog/io
1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -55,11 +55,17 @@ public RawBinaryLogEvent nextRawEvent() throws IOException {
55
55
}
56
56
57
57
private int readPacketLength () throws IOException {
58
- // Read size and skip sequence number.
59
- int packetLength = inputStream .readInteger (3 );
60
- inputStream .skip (1 );
58
+ // Read packet size (3 bytes), sequence number (1 byte, ignored) and marker (1 byte).
59
+ // We read all data at once to reduce the number of reads from Socket stream.
60
+ byte [] packetHeaderBytes = new byte [5 ];
61
+ inputStream .fill (packetHeaderBytes , 0 , packetHeaderBytes .length );
62
+
63
+ int packetLength = 0 ;
64
+ for (int i = 0 ; i < 3 ; ++i ) {
65
+ packetLength |= (packetHeaderBytes [i ] & 0xFF ) << (i << 3 );
66
+ }
61
67
62
- int marker = inputStream . read () ;
68
+ int marker = packetHeaderBytes [ 4 ] & 0xFF ;
63
69
if (marker == 0xFF ) {
64
70
ErrorPacket errorPacket = new ErrorPacket (inputStream .read (packetLength - 1 ));
65
71
throw new ServerException (errorPacket .getErrorMessage (), errorPacket .getErrorCode (),
You can’t perform that action at this time.
0 commit comments