ReadableByteChannel channel = new ReadableByteChannelMockup(
new String[] {"stuff;", "more stuff"}, "US-ASCII");
HttpParams params = new BasicHttpParams();
SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, params);
HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
LengthDelimitedDecoder decoder = new LengthDelimitedDecoder(
channel, inbuf, metrics, 16);
ByteBuffer dst = ByteBuffer.allocate(4);
int bytesRead = decoder.read(dst);
assertEquals(4, bytesRead);
assertEquals("stuf", convert(dst));
assertFalse(decoder.isCompleted());
assertEquals(4, metrics.getBytesTransferred());
dst.clear();
bytesRead = decoder.read(dst);
assertEquals(2, bytesRead);
assertEquals("f;", convert(dst));
assertFalse(decoder.isCompleted());
assertEquals(6, metrics.getBytesTransferred());
dst.clear();
bytesRead = decoder.read(dst);
assertEquals(4, bytesRead);
assertEquals("more", convert(dst));
assertFalse(decoder.isCompleted());
assertEquals(10, metrics.getBytesTransferred());
dst.clear();
bytesRead = decoder.read(dst);
assertEquals(4, bytesRead);
assertEquals(" stu", convert(dst));
assertFalse(decoder.isCompleted());
assertEquals(14, metrics.getBytesTransferred());
dst.clear();
bytesRead = decoder.read(dst);
assertEquals(2, bytesRead);
assertEquals("ff", convert(dst));
assertTrue(decoder.isCompleted());
assertEquals(16, metrics.getBytesTransferred());
dst.clear();
bytesRead = decoder.read(dst);
assertEquals(-1, bytesRead);
assertTrue(decoder.isCompleted());
assertEquals(16, metrics.getBytesTransferred());
}