Skip to content

Commit 02f1eda

Browse files
committed
Add support for blocks
1 parent d475cb4 commit 02f1eda

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/main/java/com/github/shyiko/mysql/binlog/io/ByteArrayInputStream.java

+20-3
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,25 @@ public synchronized void reset() throws IOException {
242242
inputStream.reset();
243243
}
244244

245+
/**
246+
* This method implements fast-forward skipping in the stream.
247+
* It can be used if and only if the underlying stream is fully available till its end.
248+
* In other cases the regular {@link #skip(long)} method must be used.
249+
*
250+
* @param n - number of bytes to skip
251+
* @return number of bytes skipped
252+
* @throws IOException
253+
*/
245254
public synchronized long fastSkip(long n) throws IOException {
246-
pos += (int) n;
247-
return inputStream.skip(n);
248-
}
255+
long skipOf = n;
256+
if (blockLength != -1) {
257+
skipOf = Math.min(blockLength, skipOf);
258+
blockLength -= skipOf;
259+
if (blockLength == 0) {
260+
blockLength = -1;
261+
}
262+
}
263+
pos += (int) skipOf;
264+
return inputStream.skip(skipOf);
265+
}
249266
}

0 commit comments

Comments
 (0)