AbstractBuffer extends BaseBuffer { @Override public Buffer slice(final int stop) { return this.slice(getReaderIndex(), stop); } protected  AbstractBuffer(final int readerIndex, final int lowerBoundary, final int upperBoundary,
            final int writerIndex); @Override abstract Buffer clone(); @Override int getLowerBoundary(); @Override int getUpperBoundary(); @Override int getReaderIndex(); @Override int getWriterIndex(); @Override void setWriterIndex(final int index); @Override void setReaderIndex(final int index); @Override int capacity(); @Override int getWritableBytes(); @Override void markReaderIndex(); @Override Buffer slice(final int stop); @Override Buffer slice(); @Override int getReadableBytes(); @Override void resetReaderIndex(); @Override final short readUnsignedByte(); @Override boolean hasWriteSupport(); @Override void write(final byte b); @Override void write(final String s); @Override void write(final String s, final String charset); @Override abstract boolean equals(Object other); @Override abstract int hashCode();  }
@Test public void testSlice() throws Exception { final Buffer buffer = createBuffer(allocateByteArray(100)); final Buffer b1 = buffer.slice(50, 70); assertThat(b1.capacity(), is(20)); assertThat(b1.readByte(), is((byte) 50)); assertThat(b1.getByte(0), is((byte) 50)); assertThat(b1.readByte(), is((byte) 51)); assertThat(b1.getByte(1), is((byte) 51)); assertThat(b1.getByte(19), is((byte) 69)); try { b1.getByte(20); fail("Expected an IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException e) { } try { b1.getByte(21); fail("Expected an IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException e) { } final Buffer b2 = b1.slice(b1.capacity()); assertThat(b2.readByte(), is((byte) 52)); assertThat(b2.readByte(), is((byte) 53)); assertThat(b2.capacity(), is(18)); assertThat(b2.getByte(17), is((byte) 69)); try { b2.getByte(18); fail("Expected an IndexOutOfBoundsException"); } catch (final IndexOutOfBoundsException e) { } final Buffer b3 = b2.slice(0, 18); assertThat(b3.capacity(), is(18)); assertThat(b3.readByte(), is((byte) 52)); assertThat(b3.getByte(b3.capacity() - 1), is((byte) 69)); }