ByteBuffer extends AbstractBuffer { @Override public void write(final byte b) throws IndexOutOfBoundsException { checkWriterIndex(this.writerIndex); this.buffer[this.lowerBoundary + this.writerIndex] = b; ++this.writerIndex; } protected  ByteBuffer(final byte[] buffer); protected  ByteBuffer(final int readerIndex, final int lowerBoundary, final int upperBoundary, final byte[] buffer); protected  ByteBuffer(final int readerIndex, final int lowerBoundary, final int upperBoundary,
            final int writerIndex, final byte[] buffer); @Override Buffer slice(final int start, final int stop); @Override Buffer readBytes(final int length); @Override boolean hasReadableBytes(); @Override boolean isEmpty(); @Override byte getByte(final int index); @Override void write(final byte b); @Override void write(final byte[] bytes); @Override byte[] getArray(); @Override byte[] getRawArray(); @Override byte readByte(); @Override byte peekByte(); long unsignedInt(final byte a, final byte b, final byte c, final byte d); @Override long readUnsignedInt(); @Override int readInt(); @Override short readShort(); @Override int readUnsignedShort(); @Override int getInt(final int index); @Override short getShort(final int index); @Override void setUnsignedShort(final int index, final int value); @Override int getUnsignedShort(final int index); @Override short getUnsignedByte(final int index); @Override String dumpAsHex(); @Override Buffer clone(); @Override int hashCode(); @Override boolean equals(final Object other); @Override boolean equalsIgnoreCase(final Object other); @Override void setByte(final int index, final byte value); @Override void setUnsignedByte(final int index, final short value); @Override String toString(); @Override void getBytes(final Buffer dst); @Override void getBytes(final int index, final Buffer dst); @Override void getBytes(final byte[] dst); void getBytes(final int index, final java.nio.ByteBuffer dst); void writeExternal(final ObjectOutput out); void readExternal(final ObjectInput in); @Override boolean hasWriteSupport(); @Override void write(final String s); @Override void write(final String s, final String charset); @Override void setInt(final int index, final int value); @Override void setUnsignedInt(final int index, final long value); @Override void write(final int value); @Override void write(final long value); @Override void writeAsString(final int value); @Override void writeAsString(final long value);  }
@Test public void testWrite() throws Exception { final Buffer buffer = Buffers.createBuffer(100); assertThat(buffer.toString(), is("")); assertThat(buffer.getWritableBytes(), is(100)); final String s = "hello world"; buffer.write(s); assertThat(buffer.getWritableBytes(), is(100 - s.length())); assertThat(buffer.toString(), is(s)); assertThat(buffer.readBytes(6).toString(), is("hello ")); assertThat(buffer.toString(), is("world")); assertThat(buffer.getWritableBytes(), is(100 - s.length())); assertThat(buffer.readLine().toString(), is("world")); assertThat(buffer.toString(), is("")); assertThat(buffer.getReadableBytes(), is(0)); buffer.write((byte) 'a'); buffer.write("boutsip.com"); assertThat(buffer.getWritableBytes(), is(100 - s.length() - "aboutsip.com".length())); assertThat(buffer.toString(), is("aboutsip.com")); final Buffer b = buffer.slice(); assertThat(b.getReadableBytes(), is(12)); assertThat(b.getByte(0), is((byte) 'a')); assertThat(b.getByte(1), is((byte) 'b')); assertThat(b.getByte(2), is((byte) 'o')); assertThat(b.toString(), is("aboutsip.com")); assertThat(b.getWritableBytes(), is(0)); assertThat(b.readLine().toString(), is("aboutsip.com")); assertThat(b.getWritableBytes(), is(0)); try { b.write((byte) 'h'); fail("Should not have been able to write"); } catch (final IndexOutOfBoundsException e) { } buffer.write(" " + s); assertThat(buffer.getWritableBytes(), is(100 - s.length() * 2 - 1 - "aboutsip.com".length())); assertThat(buffer.toString(), is("aboutsip.com hello world")); }