UnsyncBufferedInputStream extends UnsyncFilterInputStream { @Override public long skip(long skip) throws IOException { if (inputStream == null) { throw new IOException("Input stream is null"); } if (skip <= 0) { return 0; } long available = _firstInvalidIndex - _index; if (available <= 0) { if (_markLimitIndex < 0) { return inputStream.skip(skip); } _fillInBuffer(); available = _firstInvalidIndex - _index; if (available <= 0) { return 0; } } if (available < skip) { skip = available; } _index += skip; return skip; } UnsyncBufferedInputStream(InputStream inputStream);  UnsyncBufferedInputStream(InputStream inputStream, int size); @Override int available(); @Override void close(); @Override void mark(int readLimit); @Override boolean markSupported(); @Override int read(); @Override int read(byte[] bytes); @Override int read(byte[] bytes, int offset, int length); @Override void reset(); @Override long skip(long skip);  }
@Test public void testSkip() throws IOException { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( _BUFFER); int size = 10; UnsyncBufferedInputStream unsyncBufferedInputStream = new UnsyncBufferedInputStream(byteArrayInputStream, size); Assert.assertEquals(0, unsyncBufferedInputStream.skip(0)); Assert.assertEquals(_SIZE, byteArrayInputStream.available()); Assert.assertEquals(_SIZE, unsyncBufferedInputStream.available()); Assert.assertEquals(0, unsyncBufferedInputStream.skip(-1)); Assert.assertEquals(_SIZE, byteArrayInputStream.available()); Assert.assertEquals(_SIZE, unsyncBufferedInputStream.available()); Assert.assertEquals(0, unsyncBufferedInputStream.read()); Assert.assertEquals(_SIZE - size, byteArrayInputStream.available()); Assert.assertEquals(_SIZE - 1, unsyncBufferedInputStream.available()); Assert.assertEquals(size - 1, unsyncBufferedInputStream.skip(size * 2)); Assert.assertEquals(10, unsyncBufferedInputStream.read()); Assert.assertEquals(size - 1, unsyncBufferedInputStream.skip(size * 2)); Assert.assertEquals(size * 2, unsyncBufferedInputStream.skip(size * 2)); Assert.assertEquals(40, unsyncBufferedInputStream.read()); Assert.assertEquals(size - 1, unsyncBufferedInputStream.skip(size)); unsyncBufferedInputStream.mark(size * 2); Assert.assertEquals(size, unsyncBufferedInputStream.skip(size * 2)); Assert.assertEquals(size / 2, unsyncBufferedInputStream.skip(size / 2)); unsyncBufferedInputStream.reset(); Assert.assertEquals(50, unsyncBufferedInputStream.read()); Assert.assertEquals( (size * 2) - 1, unsyncBufferedInputStream.skip(size * 2)); unsyncBufferedInputStream.mark(_SIZE); while (unsyncBufferedInputStream.read() != -1); Assert.assertEquals(0, unsyncBufferedInputStream.skip(1)); }