UnsyncBufferedReader extends Reader { @Override public long skip(long skip) throws IOException { if (skip < 0) { throw new IllegalArgumentException("Skip is less than 0"); } if (_reader == null) { throw new IOException("Reader is null"); } if (skip == 0) { return 0; } long available = _firstInvalidIndex - _index; if (available <= 0) { if (_markLimitIndex < 0) { return _reader.skip(skip); } _fillInBuffer(); available = _firstInvalidIndex - _index; if (available <= 0) { return 0; } } if (available < skip) { skip = available; } _index += skip; return skip; } UnsyncBufferedReader(Reader reader);  UnsyncBufferedReader(Reader reader, int size); @Override void close(); @Override void mark(int markLimit); @Override boolean markSupported(); @Override int read(); @Override int read(char[] chars); @Override int read(char[] chars, int offset, int length); String readLine(); @Override boolean ready(); @Override void reset(); @Override long skip(long skip);  }
@Override @Test public void testSkip() throws Exception { int size = 10; UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader( new StringReader(new String(_BUFFER)), size); Assert.assertEquals(0, unsyncBufferedReader.skip(0)); try { unsyncBufferedReader.skip(-1); Assert.fail(); } catch (IllegalArgumentException illegalArgumentException) { Assert.assertEquals( "Skip is less than 0", illegalArgumentException.getMessage()); } Assert.assertEquals('a', unsyncBufferedReader.read()); Assert.assertEquals(1, _indexField.getInt(unsyncBufferedReader)); Assert.assertEquals( size, _firstInvalidIndexField.getInt(unsyncBufferedReader)); Assert.assertEquals(size - 1, unsyncBufferedReader.skip(size * 2)); Assert.assertEquals('a' + 10, unsyncBufferedReader.read()); Assert.assertEquals(size - 1, unsyncBufferedReader.skip(size * 2)); Assert.assertEquals(size * 2, unsyncBufferedReader.skip(size * 2)); Assert.assertEquals('a' + (40 % 26), unsyncBufferedReader.read()); Assert.assertEquals(size - 1, unsyncBufferedReader.skip(size)); unsyncBufferedReader.mark(size * 2); Assert.assertEquals(size, unsyncBufferedReader.skip(size * 2)); Assert.assertEquals(size / 2, unsyncBufferedReader.skip(size / 2)); unsyncBufferedReader.reset(); Assert.assertEquals('a' + (50 % 26), unsyncBufferedReader.read()); Assert.assertEquals( (size * 2) - 1, unsyncBufferedReader.skip(size * 2)); unsyncBufferedReader.mark(_SIZE); while (unsyncBufferedReader.read() != -1); Assert.assertEquals(0, unsyncBufferedReader.skip(1)); }