Assert.assertEquals("header\r\nstuff;more stuff", s);
}
@Test
public void testCodingFromFileChannelSaturated() throws Exception {
final WritableByteChannelMock channel = new WritableByteChannelMock(64, 4);
final SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128);
final HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
final LengthDelimitedEncoder encoder = new LengthDelimitedEncoder(
channel, outbuf, metrics, 16);
outbuf.writeLine("header");
createTempFile();
RandomAccessFile testfile = new RandomAccessFile(this.tmpfile, "rw");
try {
testfile.write("stuff".getBytes(Consts.ASCII));
} finally {
testfile.close();
}
testfile = new RandomAccessFile(this.tmpfile, "rw");
try {
final FileChannel fchannel = testfile.getChannel();
encoder.transfer(fchannel, 0, 20);
encoder.transfer(fchannel, 0, 20);
} finally {
testfile.close();
}
final String s = channel.dump(Consts.ASCII);
Assert.assertFalse(encoder.isCompleted());
Assert.assertEquals("head", s);
}