LengthPrefixedCodec implements ProtocolCodec { public BufferState write(Object value) throws IOException { if (full()) { return BufferState.FULL; } else { boolean wasEmpty = empty(); Buffer buffer = (Buffer) value; next_write_size += buffer.length; next_write_buffers.add(buffer.toByteBuffer()); return wasEmpty ? BufferState.WAS_EMPTY : BufferState.NOT_EMPTY; } }  boolean full(); void setWritableByteChannel(WritableByteChannel channel); BufferState write(Object value); BufferState flush(); long getWriteCounter(); void setReadableByteChannel(ReadableByteChannel channel); Object read(); long getReadCounter();  }
@Test public void testWrite() throws Exception { final Buffer value = Buffer.ascii("TESTDATA"); final BufferState state = codec.write(value); assertEquals(BufferState.WAS_EMPTY, state); assertEquals(false, codec.full()); assertEquals(false, codec.empty()); assertEquals(0L, codec.getWriteCounter()); }
@Test public void testWrite$Twice() throws Exception { final Buffer value1 = Buffer.ascii("TESTDATA"); final Buffer value2 = Buffer.ascii("TESTDATA"); codec.write(value1); final BufferState state = codec.write(value2); assertEquals(BufferState.NOT_EMPTY, state); assertEquals(false, codec.full()); assertEquals(false, codec.empty()); assertEquals(0L, codec.getWriteCounter()); }