InputStream API says that the skip method may, for a variety of reasons, end up skipping over some smaller number of bytes. Try this
...
long n = in.skip(GAP_SIZE);
System.out.println(n);
...
it prints 8191 instead of expected 8192. This is related to BufferedInputStream implementation details, if you remove it (it doesn't improove performance in this concrete case anyway) you will get the expected result
...
InputStream in = new FileInputStream(tmp);
...
output
1
2