code: @Test public void testBasicDecodingSmallBuffer() throws Exception {
    ReadableByteChannel channel=new ReadableByteChannelMock(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);
    Assert.assertEquals(4,bytesRead);
    Assert.assertEquals("stuf",convert(dst));
    Assert.assertFalse(decoder.isCompleted());
    Assert.assertEquals(4,metrics.getBytesTransferred());
    dst.clear();
    bytesRead=decoder.read(dst);
    Assert.assertEquals(2,bytesRead);
    Assert.assertEquals("f;",convert(dst));
    Assert.assertFalse(decoder.isCompleted());
    Assert.assertEquals(6,metrics.getBytesTransferred());
    dst.clear();
    bytesRead=decoder.read(dst);
    Assert.assertEquals(4,bytesRead);
    Assert.assertEquals("more",convert(dst));
    Assert.assertFalse(decoder.isCompleted());
    Assert.assertEquals(10,metrics.getBytesTransferred());
    dst.clear();
    bytesRead=decoder.read(dst);
    Assert.assertEquals(4,bytesRead);
    Assert.assertEquals(" stu",convert(dst));
    Assert.assertFalse(decoder.isCompleted());
    Assert.assertEquals(14,metrics.getBytesTransferred());
    dst.clear();
    bytesRead=decoder.read(dst);
    Assert.assertEquals(2,bytesRead);
    Assert.assertEquals("ff",convert(dst));
    Assert.assertTrue(decoder.isCompleted());
    Assert.assertEquals(16,metrics.getBytesTransferred());
    dst.clear();
    bytesRead=decoder.read(dst);
    Assert.assertEquals(-1,bytesRead);
    Assert.assertTrue(decoder.isCompleted());
    Assert.assertEquals(16,metrics.getBytesTransferred());
  }
  