Code example for RandomAccessFile

Methods: close, getChannel, length

0
                        "more stuff; and a lot more stuff"}, Consts.ASCII); 
 
        final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, Consts.ASCII);
        final HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
        final LengthDelimitedDecoder decoder = new LengthDelimitedDecoder(
                channel, inbuf, metrics, 16);
 
        createTempFile(); 
        final RandomAccessFile testfile  = new RandomAccessFile(this.tmpfile, "rw");
        try { 
            final FileChannel fchannel = testfile.getChannel();
 
            long bytesRead = decoder.transfer(fchannel, 0, 6);
            Assert.assertEquals(6, bytesRead);
            Assert.assertFalse(decoder.isCompleted());
            Assert.assertEquals(6, metrics.getBytesTransferred());
 
            bytesRead = decoder.transfer(fchannel,0 , 10);
            Assert.assertEquals(10, bytesRead);
            Assert.assertTrue(decoder.isCompleted());
            Assert.assertEquals(16, metrics.getBytesTransferred());