|
@@ -1,5 +1,6 @@
|
|
|
package com.taobao.tddl.dbsync.binlog;
|
|
|
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.OutputStream;
|
|
|
import java.math.BigDecimal;
|
|
@@ -9,6 +10,9 @@ import java.nio.charset.StandardCharsets;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.BitSet;
|
|
|
|
|
|
+import org.apache.commons.compress.compressors.deflate.DeflateCompressorInputStream;
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
+
|
|
|
/**
|
|
|
* TODO: Document Me!!
|
|
|
*
|
|
@@ -216,7 +220,9 @@ public class LogBuffer {
|
|
|
* Return 8-bit signed int from buffer.
|
|
|
*/
|
|
|
public final int getInt8(final int pos) {
|
|
|
- if (pos >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: " + pos);
|
|
|
+ if (pos >= limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + pos);
|
|
|
+ }
|
|
|
|
|
|
return buffer[origin + pos];
|
|
|
}
|
|
@@ -225,7 +231,9 @@ public class LogBuffer {
|
|
|
* Return next 8-bit signed int from buffer.
|
|
|
*/
|
|
|
public final int getInt8() {
|
|
|
- if (position >= origin + limit) throw new IllegalArgumentException("limit excceed: " + (position - origin));
|
|
|
+ if (position >= origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position - origin));
|
|
|
+ }
|
|
|
|
|
|
return buffer[position++];
|
|
|
}
|
|
@@ -234,7 +242,9 @@ public class LogBuffer {
|
|
|
* Return 8-bit unsigned int from buffer.
|
|
|
*/
|
|
|
public final int getUint8(final int pos) {
|
|
|
- if (pos >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: " + pos);
|
|
|
+ if (pos >= limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + pos);
|
|
|
+ }
|
|
|
|
|
|
return 0xff & buffer[origin + pos];
|
|
|
}
|
|
@@ -243,7 +253,9 @@ public class LogBuffer {
|
|
|
* Return next 8-bit unsigned int from buffer.
|
|
|
*/
|
|
|
public final int getUint8() {
|
|
|
- if (position >= origin + limit) throw new IllegalArgumentException("limit excceed: " + (position - origin));
|
|
|
+ if (position >= origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position - origin));
|
|
|
+ }
|
|
|
|
|
|
return 0xff & buffer[position++];
|
|
|
}
|
|
@@ -256,8 +268,9 @@ public class LogBuffer {
|
|
|
public final int getInt16(final int pos) {
|
|
|
final int position = origin + pos;
|
|
|
|
|
|
- if (pos + 1 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (pos < 0 ? pos : (pos + 1)));
|
|
|
+ if (pos + 1 >= limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + 1)));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return (0xff & buf[position]) | ((buf[position + 1]) << 8);
|
|
@@ -269,8 +282,9 @@ public class LogBuffer {
|
|
|
* @see mysql-5.1.60/include/my_global.h - sint2korr
|
|
|
*/
|
|
|
public final int getInt16() {
|
|
|
- if (position + 1 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (position - origin + 1));
|
|
|
+ if (position + 1 >= origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position - origin + 1));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return (0xff & buf[position++]) | ((buf[position++]) << 8);
|
|
@@ -284,8 +298,9 @@ public class LogBuffer {
|
|
|
public final int getUint16(final int pos) {
|
|
|
final int position = origin + pos;
|
|
|
|
|
|
- if (pos + 1 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (pos < 0 ? pos : (pos + 1)));
|
|
|
+ if (pos + 1 >= limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + 1)));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return (0xff & buf[position]) | ((0xff & buf[position + 1]) << 8);
|
|
@@ -297,8 +312,9 @@ public class LogBuffer {
|
|
|
* @see mysql-5.1.60/include/my_global.h - uint2korr
|
|
|
*/
|
|
|
public final int getUint16() {
|
|
|
- if (position + 1 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (position - origin + 1));
|
|
|
+ if (position + 1 >= origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position - origin + 1));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return (0xff & buf[position++]) | ((0xff & buf[position++]) << 8);
|
|
@@ -311,9 +327,9 @@ public class LogBuffer {
|
|
|
*/
|
|
|
public final int getBeInt16(final int pos) {
|
|
|
final int position = origin + pos;
|
|
|
-
|
|
|
- if (pos + 1 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (pos < 0 ? pos : (pos + 1)));
|
|
|
+ if (pos + 1 >= limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + 1)));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return (0xff & buf[position + 1]) | ((buf[position]) << 8);
|
|
@@ -325,8 +341,9 @@ public class LogBuffer {
|
|
|
* @see mysql-5.1.60/include/my_global.h - mi_sint2korr
|
|
|
*/
|
|
|
public final int getBeInt16() {
|
|
|
- if (position + 1 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (position - origin + 1));
|
|
|
+ if (position + 1 >= origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position - origin + 1));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return (buf[position++] << 8) | (0xff & buf[position++]);
|
|
@@ -339,9 +356,9 @@ public class LogBuffer {
|
|
|
*/
|
|
|
public final int getBeUint16(final int pos) {
|
|
|
final int position = origin + pos;
|
|
|
-
|
|
|
- if (pos + 1 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (pos < 0 ? pos : (pos + 1)));
|
|
|
+ if (pos + 1 >= limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + 1)));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return (0xff & buf[position + 1]) | ((0xff & buf[position]) << 8);
|
|
@@ -353,8 +370,9 @@ public class LogBuffer {
|
|
|
* @see mysql-5.6.10/include/myisampack.h - mi_usint2korr
|
|
|
*/
|
|
|
public final int getBeUint16() {
|
|
|
- if (position + 1 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (position - origin + 1));
|
|
|
+ if (position + 1 >= origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position - origin + 1));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((0xff & buf[position++]) << 8) | (0xff & buf[position++]);
|
|
@@ -368,8 +386,9 @@ public class LogBuffer {
|
|
|
public final int getInt24(final int pos) {
|
|
|
final int position = origin + pos;
|
|
|
|
|
|
- if (pos + 2 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (pos < 0 ? pos : (pos + 2)));
|
|
|
+ if (pos + 2 >= limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + 2)));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return (0xff & buf[position]) | ((0xff & buf[position + 1]) << 8) | ((buf[position + 2]) << 16);
|
|
@@ -381,8 +400,9 @@ public class LogBuffer {
|
|
|
* @see mysql-5.1.60/include/my_global.h - sint3korr
|
|
|
*/
|
|
|
public final int getInt24() {
|
|
|
- if (position + 2 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (position - origin + 2));
|
|
|
+ if (position + 2 >= origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position - origin + 2));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return (0xff & buf[position++]) | ((0xff & buf[position++]) << 8) | ((buf[position++]) << 16);
|
|
@@ -396,8 +416,9 @@ public class LogBuffer {
|
|
|
public final int getBeInt24(final int pos) {
|
|
|
final int position = origin + pos;
|
|
|
|
|
|
- if (pos + 2 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (pos < 0 ? pos : (pos + 2)));
|
|
|
+ if (pos + 2 >= limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + 2)));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return (0xff & buf[position + 2]) | ((0xff & buf[position + 1]) << 8) | ((buf[position]) << 16);
|
|
@@ -409,8 +430,9 @@ public class LogBuffer {
|
|
|
* @see mysql-5.6.10/include/myisampack.h - mi_usint3korr
|
|
|
*/
|
|
|
public final int getBeInt24() {
|
|
|
- if (position + 2 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (position - origin + 2));
|
|
|
+ if (position + 2 >= origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position - origin + 2));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((buf[position++]) << 16) | ((0xff & buf[position++]) << 8) | (0xff & buf[position++]);
|
|
@@ -424,8 +446,9 @@ public class LogBuffer {
|
|
|
public final int getUint24(final int pos) {
|
|
|
final int position = origin + pos;
|
|
|
|
|
|
- if (pos + 2 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (pos < 0 ? pos : (pos + 2)));
|
|
|
+ if (pos + 2 >= limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + 2)));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return (0xff & buf[position]) | ((0xff & buf[position + 1]) << 8) | ((0xff & buf[position + 2]) << 16);
|
|
@@ -437,8 +460,9 @@ public class LogBuffer {
|
|
|
* @see mysql-5.1.60/include/my_global.h - uint3korr
|
|
|
*/
|
|
|
public final int getUint24() {
|
|
|
- if (position + 2 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (position - origin + 2));
|
|
|
+ if (position + 2 >= origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position - origin + 2));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return (0xff & buf[position++]) | ((0xff & buf[position++]) << 8) | ((0xff & buf[position++]) << 16);
|
|
@@ -452,8 +476,9 @@ public class LogBuffer {
|
|
|
public final int getBeUint24(final int pos) {
|
|
|
final int position = origin + pos;
|
|
|
|
|
|
- if (pos + 2 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (pos < 0 ? pos : (pos + 2)));
|
|
|
+ if (pos + 2 >= limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + 2)));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return (0xff & buf[position + 2]) | ((0xff & buf[position + 1]) << 8) | ((0xff & buf[position]) << 16);
|
|
@@ -465,8 +490,9 @@ public class LogBuffer {
|
|
|
* @see mysql-5.6.10/include/myisampack.h - mi_usint3korr
|
|
|
*/
|
|
|
public final int getBeUint24() {
|
|
|
- if (position + 2 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (position - origin + 2));
|
|
|
+ if (position + 2 >= origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position - origin + 2));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((0xff & buf[position++]) << 16) | ((0xff & buf[position++]) << 8) | (0xff & buf[position++]);
|
|
@@ -480,8 +506,9 @@ public class LogBuffer {
|
|
|
public final int getInt32(final int pos) {
|
|
|
final int position = origin + pos;
|
|
|
|
|
|
- if (pos + 3 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (pos < 0 ? pos : (pos + 3)));
|
|
|
+ if (pos + 3 >= limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + 3)));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return (0xff & buf[position]) | ((0xff & buf[position + 1]) << 8) | ((0xff & buf[position + 2]) << 16)
|
|
@@ -496,8 +523,9 @@ public class LogBuffer {
|
|
|
public final int getBeInt32(final int pos) {
|
|
|
final int position = origin + pos;
|
|
|
|
|
|
- if (pos + 3 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (pos < 0 ? pos : (pos + 3)));
|
|
|
+ if (pos + 3 >= limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + 3)));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return (0xff & buf[position + 3]) | ((0xff & buf[position + 2]) << 8) | ((0xff & buf[position + 1]) << 16)
|
|
@@ -510,8 +538,9 @@ public class LogBuffer {
|
|
|
* @see mysql-5.1.60/include/my_global.h - sint4korr
|
|
|
*/
|
|
|
public final int getInt32() {
|
|
|
- if (position + 3 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (position - origin + 3));
|
|
|
+ if (position + 3 >= origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position - origin + 3));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return (0xff & buf[position++]) | ((0xff & buf[position++]) << 8) | ((0xff & buf[position++]) << 16)
|
|
@@ -524,8 +553,9 @@ public class LogBuffer {
|
|
|
* @see mysql-5.6.10/include/myisampack.h - mi_sint4korr
|
|
|
*/
|
|
|
public final int getBeInt32() {
|
|
|
- if (position + 3 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (position - origin + 3));
|
|
|
+ if (position + 3 >= origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position - origin + 3));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((buf[position++]) << 24) | ((0xff & buf[position++]) << 16) | ((0xff & buf[position++]) << 8)
|
|
@@ -540,8 +570,9 @@ public class LogBuffer {
|
|
|
public final long getUint32(final int pos) {
|
|
|
final int position = origin + pos;
|
|
|
|
|
|
- if (pos + 3 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (pos < 0 ? pos : (pos + 3)));
|
|
|
+ if (pos + 3 >= limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + 3)));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((long) (0xff & buf[position])) | ((long) (0xff & buf[position + 1]) << 8)
|
|
@@ -556,8 +587,9 @@ public class LogBuffer {
|
|
|
public final long getBeUint32(final int pos) {
|
|
|
final int position = origin + pos;
|
|
|
|
|
|
- if (pos + 3 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (pos < 0 ? pos : (pos + 3)));
|
|
|
+ if (pos + 3 >= limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + 3)));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((long) (0xff & buf[position + 3])) | ((long) (0xff & buf[position + 2]) << 8)
|
|
@@ -570,8 +602,9 @@ public class LogBuffer {
|
|
|
* @see mysql-5.1.60/include/my_global.h - uint4korr
|
|
|
*/
|
|
|
public final long getUint32() {
|
|
|
- if (position + 3 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (position - origin + 3));
|
|
|
+ if (position + 3 >= origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position - origin + 3));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((long) (0xff & buf[position++])) | ((long) (0xff & buf[position++]) << 8)
|
|
@@ -584,8 +617,9 @@ public class LogBuffer {
|
|
|
* @see mysql-5.6.10/include/myisampack.h - mi_uint4korr
|
|
|
*/
|
|
|
public final long getBeUint32() {
|
|
|
- if (position + 3 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (position - origin + 3));
|
|
|
+ if (position + 3 >= origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position - origin + 3));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((long) (0xff & buf[position++]) << 24) | ((long) (0xff & buf[position++]) << 16)
|
|
@@ -598,8 +632,9 @@ public class LogBuffer {
|
|
|
public final long getUlong40(final int pos) {
|
|
|
final int position = origin + pos;
|
|
|
|
|
|
- if (pos + 4 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (pos < 0 ? pos : (pos + 4)));
|
|
|
+ if (pos + 4 >= limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + 4)));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((long) (0xff & buf[position])) | ((long) (0xff & buf[position + 1]) << 8)
|
|
@@ -611,8 +646,9 @@ public class LogBuffer {
|
|
|
* Return next 40-bit unsigned int from buffer. (little-endian)
|
|
|
*/
|
|
|
public final long getUlong40() {
|
|
|
- if (position + 4 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (position - origin + 4));
|
|
|
+ if (position + 4 >= origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position - origin + 4));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((long) (0xff & buf[position++])) | ((long) (0xff & buf[position++]) << 8)
|
|
@@ -628,8 +664,9 @@ public class LogBuffer {
|
|
|
public final long getBeUlong40(final int pos) {
|
|
|
final int position = origin + pos;
|
|
|
|
|
|
- if (pos + 4 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (pos < 0 ? pos : (pos + 4)));
|
|
|
+ if (pos + 4 >= limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + 4)));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((long) (0xff & buf[position + 4])) | ((long) (0xff & buf[position + 3]) << 8)
|
|
@@ -643,8 +680,9 @@ public class LogBuffer {
|
|
|
* @see mysql-5.6.10/include/myisampack.h - mi_uint5korr
|
|
|
*/
|
|
|
public final long getBeUlong40() {
|
|
|
- if (position + 4 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (position - origin + 4));
|
|
|
+ if (position + 4 >= origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position - origin + 4));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((long) (0xff & buf[position++]) << 32) | ((long) (0xff & buf[position++]) << 24)
|
|
@@ -660,8 +698,9 @@ public class LogBuffer {
|
|
|
public final long getLong48(final int pos) {
|
|
|
final int position = origin + pos;
|
|
|
|
|
|
- if (pos + 5 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (pos < 0 ? pos : (pos + 5)));
|
|
|
+ if (pos + 5 >= limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + 5)));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((long) (0xff & buf[position])) | ((long) (0xff & buf[position + 1]) << 8)
|
|
@@ -677,8 +716,9 @@ public class LogBuffer {
|
|
|
public final long getBeLong48(final int pos) {
|
|
|
final int position = origin + pos;
|
|
|
|
|
|
- if (pos + 5 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (pos < 0 ? pos : (pos + 5)));
|
|
|
+ if (pos + 5 >= limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + 5)));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((long) (0xff & buf[position + 5])) | ((long) (0xff & buf[position + 4]) << 8)
|
|
@@ -692,8 +732,9 @@ public class LogBuffer {
|
|
|
* @see mysql-5.1.60/include/my_global.h - sint6korr
|
|
|
*/
|
|
|
public final long getLong48() {
|
|
|
- if (position + 5 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (position - origin + 5));
|
|
|
+ if (position + 5 >= origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position - origin + 5));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((long) (0xff & buf[position++])) | ((long) (0xff & buf[position++]) << 8)
|
|
@@ -707,8 +748,9 @@ public class LogBuffer {
|
|
|
* @see mysql-5.6.10/include/myisampack.h - mi_sint6korr
|
|
|
*/
|
|
|
public final long getBeLong48() {
|
|
|
- if (position + 5 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (position - origin + 5));
|
|
|
+ if (position + 5 >= origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position - origin + 5));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((long) (buf[position++]) << 40) | ((long) (0xff & buf[position++]) << 32)
|
|
@@ -724,8 +766,9 @@ public class LogBuffer {
|
|
|
public final long getUlong48(final int pos) {
|
|
|
final int position = origin + pos;
|
|
|
|
|
|
- if (pos + 5 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (pos < 0 ? pos : (pos + 5)));
|
|
|
+ if (pos + 5 >= limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + 5)));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((long) (0xff & buf[position])) | ((long) (0xff & buf[position + 1]) << 8)
|
|
@@ -741,8 +784,9 @@ public class LogBuffer {
|
|
|
public final long getBeUlong48(final int pos) {
|
|
|
final int position = origin + pos;
|
|
|
|
|
|
- if (pos + 5 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (pos < 0 ? pos : (pos + 5)));
|
|
|
+ if (pos + 5 >= limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + 5)));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((long) (0xff & buf[position + 5])) | ((long) (0xff & buf[position + 4]) << 8)
|
|
@@ -756,8 +800,9 @@ public class LogBuffer {
|
|
|
* @see mysql-5.1.60/include/my_global.h - uint6korr
|
|
|
*/
|
|
|
public final long getUlong48() {
|
|
|
- if (position + 5 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (position - origin + 5));
|
|
|
+ if (position + 5 >= origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position - origin + 5));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((long) (0xff & buf[position++])) | ((long) (0xff & buf[position++]) << 8)
|
|
@@ -771,8 +816,9 @@ public class LogBuffer {
|
|
|
* @see mysql-5.6.10/include/myisampack.h - mi_uint6korr
|
|
|
*/
|
|
|
public final long getBeUlong48() {
|
|
|
- if (position + 5 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (position - origin + 5));
|
|
|
+ if (position + 5 >= origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position - origin + 5));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((long) (0xff & buf[position++]) << 40) | ((long) (0xff & buf[position++]) << 32)
|
|
@@ -786,8 +832,9 @@ public class LogBuffer {
|
|
|
public final long getUlong56(final int pos) {
|
|
|
final int position = origin + pos;
|
|
|
|
|
|
- if (pos + 6 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (pos < 0 ? pos : (pos + 6)));
|
|
|
+ if (pos + 6 >= limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + 6)));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((long) (0xff & buf[position])) | ((long) (0xff & buf[position + 1]) << 8)
|
|
@@ -800,8 +847,9 @@ public class LogBuffer {
|
|
|
* Return next 56-bit unsigned int from buffer. (little-endian)
|
|
|
*/
|
|
|
public final long getUlong56() {
|
|
|
- if (position + 6 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (position - origin + 6));
|
|
|
+ if (position + 6 >= origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position - origin + 6));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((long) (0xff & buf[position++])) | ((long) (0xff & buf[position++]) << 8)
|
|
@@ -816,8 +864,9 @@ public class LogBuffer {
|
|
|
public final long getBeUlong56(final int pos) {
|
|
|
final int position = origin + pos;
|
|
|
|
|
|
- if (pos + 6 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (pos < 0 ? pos : (pos + 6)));
|
|
|
+ if (pos + 6 >= limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + 6)));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((long) (0xff & buf[position + 6])) | ((long) (0xff & buf[position + 5]) << 8)
|
|
@@ -830,8 +879,9 @@ public class LogBuffer {
|
|
|
* Return next 56-bit unsigned int from buffer. (big-endian)
|
|
|
*/
|
|
|
public final long getBeUlong56() {
|
|
|
- if (position + 6 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (position - origin + 6));
|
|
|
+ if (position + 6 >= origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position - origin + 6));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((long) (0xff & buf[position++]) << 48) | ((long) (0xff & buf[position++]) << 40)
|
|
@@ -848,8 +898,9 @@ public class LogBuffer {
|
|
|
public final long getLong64(final int pos) {
|
|
|
final int position = origin + pos;
|
|
|
|
|
|
- if (pos + 7 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (pos < 0 ? pos : (pos + 7)));
|
|
|
+ if (pos + 7 >= limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + 7)));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((long) (0xff & buf[position])) | ((long) (0xff & buf[position + 1]) << 8)
|
|
@@ -866,8 +917,9 @@ public class LogBuffer {
|
|
|
public final long getBeLong64(final int pos) {
|
|
|
final int position = origin + pos;
|
|
|
|
|
|
- if (pos + 7 >= limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (pos < 0 ? pos : (pos + 7)));
|
|
|
+ if (pos + 7 >= limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (pos < 0 ? pos : (pos + 7)));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((long) (0xff & buf[position + 7])) | ((long) (0xff & buf[position + 6]) << 8)
|
|
@@ -882,8 +934,9 @@ public class LogBuffer {
|
|
|
* @see mysql-5.1.60/include/my_global.h - sint8korr
|
|
|
*/
|
|
|
public final long getLong64() {
|
|
|
- if (position + 7 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (position - origin + 7));
|
|
|
+ if (position + 7 >= origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position - origin + 7));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((long) (0xff & buf[position++])) | ((long) (0xff & buf[position++]) << 8)
|
|
@@ -898,8 +951,9 @@ public class LogBuffer {
|
|
|
* @see mysql-5.6.10/include/myisampack.h - mi_sint8korr
|
|
|
*/
|
|
|
public final long getBeLong64() {
|
|
|
- if (position + 7 >= origin + limit) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (position - origin + 7));
|
|
|
+ if (position + 7 >= origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position - origin + 7));
|
|
|
+ }
|
|
|
|
|
|
byte[] buf = buffer;
|
|
|
return ((long) (buf[position++]) << 56) | ((long) (0xff & buf[position++]) << 48)
|
|
@@ -1506,8 +1560,9 @@ public class LogBuffer {
|
|
|
* @param len The length of MY_BITMAP in bits.
|
|
|
*/
|
|
|
public final void fillBitmap(BitSet bitmap, final int pos, final int len) {
|
|
|
- if (pos + ((len + 7) / 8) > limit || pos < 0) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (pos + (len + 7) / 8));
|
|
|
+ if (pos + ((len + 7) / 8) > limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (pos + (len + 7) / 8));
|
|
|
+ }
|
|
|
|
|
|
fillBitmap0(bitmap, origin + pos, len);
|
|
|
}
|
|
@@ -1518,9 +1573,9 @@ public class LogBuffer {
|
|
|
* @param len The length of MY_BITMAP in bits.
|
|
|
*/
|
|
|
public final void fillBitmap(BitSet bitmap, final int len) {
|
|
|
- if (position + ((len + 7) / 8) > origin + limit) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (position
|
|
|
- + ((len + 7) / 8) - origin));
|
|
|
+ if (position + ((len + 7) / 8) > origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position + ((len + 7) / 8) - origin));
|
|
|
+ }
|
|
|
|
|
|
position = fillBitmap0(bitmap, position, len);
|
|
|
}
|
|
@@ -1596,7 +1651,9 @@ public class LogBuffer {
|
|
|
* Fill n bytes in this buffer.
|
|
|
*/
|
|
|
public final void fillBytes(final int pos, byte[] dest, final int destPos, final int len) {
|
|
|
- if (pos + len > limit || pos < 0) throw new IllegalArgumentException("limit excceed: " + (pos + len));
|
|
|
+ if (pos + len > limit || pos < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (pos + len));
|
|
|
+ }
|
|
|
|
|
|
System.arraycopy(buffer, origin + pos, dest, destPos, len);
|
|
|
}
|
|
@@ -1605,8 +1662,9 @@ public class LogBuffer {
|
|
|
* Fill next n bytes in this buffer.
|
|
|
*/
|
|
|
public final void fillBytes(byte[] dest, final int destPos, final int len) {
|
|
|
- if (position + len > origin + limit) throw new IllegalArgumentException("limit excceed: "
|
|
|
- + (position + len - origin));
|
|
|
+ if (position + len > origin + limit) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position + len - origin));
|
|
|
+ }
|
|
|
|
|
|
System.arraycopy(buffer, position, dest, destPos, len);
|
|
|
position += len;
|
|
@@ -1637,6 +1695,76 @@ public class LogBuffer {
|
|
|
return getData(0, limit);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * mariadb compress log event Get the length of uncompress content.
|
|
|
+ *
|
|
|
+ * @return 0 means error.
|
|
|
+ */
|
|
|
+ public final long getUncompressLong(int lenPad) {
|
|
|
+ long len = 0;
|
|
|
+ switch (lenPad) {
|
|
|
+ case 1:
|
|
|
+ len = getInt8();
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ len = getBeUint16();
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ len = getBeUint24();
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ len = getBeUint32();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ len = 0;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return len;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * uncompress mariadb log event
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public LogBuffer uncompressBuf() {
|
|
|
+ int lenPad = getInt8();
|
|
|
+ long len = getUncompressLong(lenPad & 0x07);
|
|
|
+ int alg = (lenPad & 0x70) >> 4;
|
|
|
+ LogBuffer buffer = null;
|
|
|
+ try {
|
|
|
+ switch (alg) {
|
|
|
+ case 0:
|
|
|
+ buffer = uncompressZlib(limit - position);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ // bad algorithm
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new IllegalArgumentException("uncompress failed ", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (buffer.limit() != len) {
|
|
|
+ throw new IllegalArgumentException(
|
|
|
+ "uncompress lenght not match, expected : " + len + " , but actual : " + buffer.limit());
|
|
|
+ }
|
|
|
+ return buffer;
|
|
|
+ }
|
|
|
+
|
|
|
+ private LogBuffer uncompressZlib(int len) throws Exception {
|
|
|
+ if (position + len > limit || position < 0) {
|
|
|
+ throw new IllegalArgumentException("limit excceed: " + (position + len));
|
|
|
+ }
|
|
|
+
|
|
|
+ try (DeflateCompressorInputStream in = new DeflateCompressorInputStream(
|
|
|
+ new ByteArrayInputStream(buffer, position, position + len))) {
|
|
|
+ byte[] decodeBytes = IOUtils.toByteArray(in);
|
|
|
+ return new LogBuffer(decodeBytes, 0, decodeBytes.length);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Return full hexdump from position.
|
|
|
*/
|