@Override
    public long skip(long n) throws IOException {
        int bufSize = (int) Math.min(n, SKIP_SIZE);
        byte[] buf = new byte[bufSize];
        long bytesSkipped = 0;
        int bytesRead = 0;

        while (bytesSkipped < n && bytesRead != -1) {
            int len = (int) Math.min(bufSize, n - bytesSkipped);
            bytesRead = read(buf, 0, len);
            if (bytesRead != -1) {
                bytesSkipped += bytesRead;
            }
        }

        return (bytesRead < 0 && bytesSkipped == 0) ? -1 : bytesSkipped;
    }
@Test
    public void testSkip() throws IOException {
        final int tailSize = 128;
        final int count = 1024;
        final int skipCount = 512;
        TailStream stream = new TailStream(generateStream(0, count), tailSize);
        assertEquals(skipCount, stream.skip(skipCount), "Wrong skip result");
        assertEquals(generateText(skipCount - tailSize, tailSize),
                new String(stream.getTail(), UTF_8), "Wrong buffer");
        stream.close();
    }