EMMA Coverage Report (generated Tue Dec 20 11:01:01 KST 2005)
[all classes][org.apache.mina.common]

COVERAGE SUMMARY FOR SOURCE FILE [ByteBufferHexDumper.java]

nameclass, %method, %block, %line, %
ByteBufferHexDumper.java100% (1/1)67%  (2/3)97%  (173/178)92%  (24/26)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ByteBufferHexDumper100% (1/1)67%  (2/3)97%  (173/178)92%  (24/26)
ByteBufferHexDumper (): void 0%   (0/1)0%   (0/3)0%   (0/1)
getHexdump (ByteBuffer): String 100% (1/1)97%  (72/74)94%  (15/16)
<static initializer> 100% (1/1)100% (101/101)100% (9/9)

1/*
2 *   @(#) $Id: ByteBufferHexDumper.java 357871 2005-12-20 01:56:40Z trustin $
3 *
4 *   Copyright 2004 The Apache Software Foundation
5 *
6 *   Licensed under the Apache License, Version 2.0 (the "License");
7 *   you may not use this file except in compliance with the License.
8 *   You may obtain a copy of the License at
9 *
10 *       http://www.apache.org/licenses/LICENSE-2.0
11 *
12 *   Unless required by applicable law or agreed to in writing, software
13 *   distributed under the License is distributed on an "AS IS" BASIS,
14 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 *   See the License for the specific language governing permissions and
16 *   limitations under the License.
17 *
18 */
19package org.apache.mina.common;
20 
21import org.apache.mina.common.ByteBuffer;
22 
23/**
24 * Provides utility methods for ByteBuffers.
25 * 
26 * @author The Apache Directory Project (dev@directory.apache.org)
27 * @version $Rev: 357871 $, $Date: 2005-12-20 10:56:40 +0900 (Tue, 20 Dec 2005) $
28 */
29class ByteBufferHexDumper
30{
31    private static final byte[] highDigits;
32 
33    private static final byte[] lowDigits;
34 
35    // initialize lookup tables
36    static
37    {
38        final byte[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
39                               '9', 'A', 'B', 'C', 'D', 'E', 'F' };
40 
41        int i;
42        byte[] high = new byte[ 256 ];
43        byte[] low = new byte[ 256 ];
44 
45        for( i = 0; i < 256; i++ )
46        {
47            high[ i ] = digits[ i >>> 4 ];
48            low[ i ] = digits[ i & 0x0F ];
49        }
50 
51        highDigits = high;
52        lowDigits = low;
53    }
54 
55    static String getHexdump( ByteBuffer in )
56    {
57        int size = in.remaining();
58 
59        if( size == 0 )
60        {
61            return "empty";
62        }
63 
64        StringBuffer out = new StringBuffer( ( in.remaining() * 3 ) - 1 );
65 
66        int mark = in.position();
67 
68        // fill the first
69        int byteValue = in.get() & 0xFF;
70        out.append( ( char ) highDigits[ byteValue ] );
71        out.append( ( char ) lowDigits[ byteValue ] );
72        size--;
73 
74        // and the others, too
75        for( ; size > 0; size-- )
76        {
77            out.append( ' ' );
78            byteValue = in.get() & 0xFF;
79            out.append( ( char ) highDigits[ byteValue ] );
80            out.append( ( char ) lowDigits[ byteValue ] );
81        }
82 
83        in.position( mark );
84 
85        return out.toString();
86    }
87}

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