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