diff --git a/src/main/java/com/github/shyiko/mysql/binlog/io/ByteArrayInputStream.java b/src/main/java/com/github/shyiko/mysql/binlog/io/ByteArrayInputStream.java index 06e8164f..87acd675 100644 --- a/src/main/java/com/github/shyiko/mysql/binlog/io/ByteArrayInputStream.java +++ b/src/main/java/com/github/shyiko/mysql/binlog/io/ByteArrayInputStream.java @@ -28,7 +28,7 @@ public class ByteArrayInputStream extends InputStream { private InputStream inputStream; private int peek = -1; private int pos, markPosition; - private int blockLength = -1; + private int blockLength = -1, markBlockLength = -1; private int initialBlockLength = -1; public ByteArrayInputStream(InputStream inputStream) { @@ -294,6 +294,7 @@ public int getPosition() { @Override public synchronized void mark(int readlimit) { markPosition = pos; + markBlockLength = blockLength; inputStream.mark(readlimit); } @@ -305,6 +306,7 @@ public boolean markSupported() { @Override public synchronized void reset() throws IOException { pos = markPosition; + blockLength = markBlockLength; inputStream.reset(); } diff --git a/src/test/java/com/github/shyiko/mysql/binlog/io/ByteArrayInputStreamTest.java b/src/test/java/com/github/shyiko/mysql/binlog/io/ByteArrayInputStreamTest.java index 8f0eb112..148f4760 100644 --- a/src/test/java/com/github/shyiko/mysql/binlog/io/ByteArrayInputStreamTest.java +++ b/src/test/java/com/github/shyiko/mysql/binlog/io/ByteArrayInputStreamTest.java @@ -99,4 +99,18 @@ public void testPeekAndReadToArray() throws Exception { assertEquals(b[0], 5); assertEquals(b[2], 7); } + + @Test + public void testMarkAndReset() throws Exception { + ByteArrayInputStream in = new ByteArrayInputStream(new byte[] {1, 2, 3, 4}); + in.enterBlock(4); + in.mark(4); + in.readInteger(4); + in.reset(); + + assertEquals(1, in.read()); + assertEquals(2, in.read()); + assertEquals(3, in.read()); + assertEquals(4, in.read()); + } }