ByteBuf implements Recyclable, Sliceable<ByteBuf>, AutoCloseable { @NotNull @Contract("-> new") @Override public ByteBuf slice() { return slice(head, readRemaining()); } private  ByteBuf(@NotNull byte[] array, int head, int tail); @Contract(pure = true) static ByteBuf empty(); @NotNull @Contract("_ -> new") static ByteBuf wrapForWriting(@NotNull byte[] bytes); @NotNull @Contract("_ -> new") static ByteBuf wrapForReading(@NotNull byte[] bytes); @NotNull @Contract("_, _, _ -> new") static ByteBuf wrap(@NotNull byte[] bytes, int head, int tail); @NotNull @Contract("-> new") @Override ByteBuf slice(); @NotNull @Contract("_ -> new") ByteBuf slice(int length); @NotNull @Contract("_, _ -> new") ByteBuf slice(int offset, int length); @Override void recycle(); void addRef(); @Override void close(); void rewind(); ByteBuffer toReadByteBuffer(); ByteBuffer toWriteByteBuffer(); void ofReadByteBuffer(ByteBuffer byteBuffer); void ofWriteByteBuffer(ByteBuffer byteBuffer); @NotNull @Contract(pure = true) byte[] array(); @Contract(pure = true) int limit(); @Contract(pure = true) int head(); void head(int pos); @Contract(pure = true) int tail(); void tail(int pos); void moveHead(int delta); void moveTail(int delta); @Contract(pure = true) int readRemaining(); @Contract(pure = true) int writeRemaining(); @Contract(pure = true) boolean canRead(); @Contract(pure = true) boolean canWrite(); byte get(); @Contract(pure = true) byte at(int index); @Contract(pure = true) byte peek(); @Contract(pure = true) byte peek(int offset); int drainTo(@NotNull byte[] array, int offset, int length); int drainTo(@NotNull ByteBuf buf, int length); void set(int index, byte b); void put(byte b); void put(@NotNull ByteBuf buf); void put(@NotNull byte[] bytes); void put(@NotNull byte[] bytes, int offset, int length); int find(byte b); int find(@NotNull byte[] bytes); int find(@NotNull byte[] bytes, int off, int len); @Contract(pure = true) boolean isContentEqual(@NotNull byte[] array, int offset, int length); @Contract(pure = true) boolean isContentEqual(@NotNull ByteBuf other); @Contract(pure = true) boolean isContentEqual(byte[] array); @Contract(pure = true) @NotNull byte[] getArray(); @Contract(pure = false) @NotNull byte[] asArray(); @Contract(pure = true) String getString(@NotNull Charset charset); @Contract(pure = false) String asString(@NotNull Charset charset); int read(@NotNull byte[] b); int read(@NotNull byte[] b, int off, int len); byte readByte(); boolean readBoolean(); char readChar(); double readDouble(); float readFloat(); int readInt(); int readVarInt(); long readLong(); short readShort(); long readVarLong(); void write(@NotNull byte[] b); void write(@NotNull byte[] b, int off, int len); void writeBoolean(boolean v); void writeByte(byte v); void writeChar(char v); void writeDouble(double v); void writeFloat(float v); void writeInt(int v); void writeLong(long v); void writeShort(short v); void writeVarInt(int v); void writeVarLong(long v); @Override @Contract(pure = true) String toString();  }
@Test public void testSlice() { byte[] bytes = ByteBufStrings.encodeAscii("Hello, World"); ByteBuf buf = ByteBuf.wrapForReading(bytes); ByteBuf slice = buf.slice(7, 5); assertNotSame(buf, slice); assertEquals("World", slice.toString()); buf = createEmptyByteBufOfSize(16); buf.put(bytes); slice = buf.slice(); assertNotSame(buf, slice); assertEquals("Hello, World", slice.toString()); }