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(1024);
int bytesRead = decoder.read(dst);
assertEquals(6, bytesRead);
assertEquals("stuff;", convert(dst));
assertFalse(decoder.isCompleted());
assertEquals(6, metrics.getBytesTransferred());
dst.clear();
bytesRead = decoder.read(dst);
assertEquals(10, bytesRead);
assertEquals("more stuff", 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());
}