EMMA Coverage Report (generated Sat Nov 12 08:39:53 KST 2005)
[all classes][org.apache.mina.protocol]

COVERAGE SUMMARY FOR SOURCE FILE [SimpleProtocolEncoderOutput.java]

nameclass, %method, %block, %line, %
SimpleProtocolEncoderOutput.java0%   (0/1)0%   (0/4)0%   (0/69)0%   (0/22)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SimpleProtocolEncoderOutput0%   (0/1)0%   (0/4)0%   (0/69)0%   (0/22)
SimpleProtocolEncoderOutput (): void 0%   (0/1)0%   (0/8)0%   (0/3)
getBufferQueue (): Queue 0%   (0/1)0%   (0/3)0%   (0/1)
mergeAll (): void 0%   (0/1)0%   (0/53)0%   (0/16)
write (ByteBuffer): void 0%   (0/1)0%   (0/5)0%   (0/2)

1/**
2 * 
3 */
4package org.apache.mina.protocol;
5 
6import org.apache.mina.common.ByteBuffer;
7import org.apache.mina.protocol.ProtocolEncoderOutput;
8import org.apache.mina.util.Queue;
9 
10/**
11 * A {@link ProtocolEncoderOutput} based on queue.
12 *
13 * @author The Apache Directory Project (dev@directory.apache.org)
14 * @version $Rev: 332218 $, $Date: 2005-11-10 12:52:42 +0900 $
15 */
16public class SimpleProtocolEncoderOutput implements ProtocolEncoderOutput
17{
18 
19    private final Queue bufferQueue = new Queue();
20    
21    public SimpleProtocolEncoderOutput()
22    {
23    }
24    
25    public Queue getBufferQueue()
26    {
27        return bufferQueue;
28    }
29    
30    public void write( ByteBuffer buf )
31    {
32        bufferQueue.push( buf );
33    }
34    
35    public void mergeAll()
36    {
37        int sum = 0;
38        final int size = bufferQueue.size();
39        
40        if( size < 2 )
41        {
42            // no need to merge!
43            return;
44        }
45        
46        // Get the size of merged BB
47        for( int i = size - 1; i >= 0; i -- )
48        {
49            sum += ( ( ByteBuffer ) bufferQueue.get( i ) ).remaining();
50        }
51        
52        // Allocate a new BB that will contain all fragments
53        ByteBuffer newBuf = ByteBuffer.allocate( sum );
54        
55        // and merge all.
56        for( ;; )
57        {
58            ByteBuffer buf = ( ByteBuffer ) bufferQueue.pop();
59            if( buf == null )
60            {
61                break;
62            }
63    
64            newBuf.put( buf );
65            buf.release();
66        }
67        
68        // Push the new buffer finally.
69        newBuf.flip();
70        bufferQueue.push(newBuf);
71    }
72}

[all classes][org.apache.mina.protocol]
EMMA 2.0.4217 (C) Vladimir Roubtsov