RollingBuffer implements ReadableByteBuffer { public boolean advance(int bytes) throws IOException { if (bytes < 0) { throw new IllegalArgumentException("Cannot advance window backwards"); } if (bytes > this.length) { throw new IllegalArgumentException("Cannot advance window beyond current end position"); } if (!ensureBuffered(bytes)) { return false; } this.buffer.position(this.buffer.position() + bytes); return true; } RollingBuffer(ReadableByteChannel channel, int windowSize, int bufferSize); boolean advance(int bytes); @Override int length(); @Override byte get(int i); @Override void write(WritableByteChannel channel); @Override void write(WritableByteChannel channel, int offset, int length);  }
@Test(expected = IllegalArgumentException.class) public void testAdvanceBackwards() throws IOException { final ReadableByteChannel c = Channels.newChannel(new ByteArrayInputStream(new byte[1024])); final RollingBuffer b = new RollingBuffer(c, 256, 512); b.advance(-1); }
@Test(expected = IllegalArgumentException.class) public void testAdvanceBeyondWindow() throws IOException { final ReadableByteChannel c = Channels.newChannel(new ByteArrayInputStream(new byte[1024])); final RollingBuffer b = new RollingBuffer(c, 256, 512); b.advance(257); }