EMMA Coverage Report (generated Mon Mar 20 21:34:30 PST 2006)
[all classes][com.moesol.util]

COVERAGE SUMMARY FOR SOURCE FILE [DumpBytes.java]

nameclass, %method, %block, %line, %
DumpBytes.java100% (1/1)43%  (6/14)42%  (107/256)40%  (24.7/61)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DumpBytes100% (1/1)43%  (6/14)42%  (107/256)40%  (24.7/61)
DumpBytes (): void 0%   (0/1)0%   (0/3)0%   (0/1)
dumpByte (PrintStream, byte): void 0%   (0/1)0%   (0/11)0%   (0/4)
dumpBytes (PrintStream, byte []): void 0%   (0/1)0%   (0/11)0%   (0/4)
dumpBytes (PrintStream, short []): void 0%   (0/1)0%   (0/11)0%   (0/4)
dumpBytes (PrintWriter, byte []): void 0%   (0/1)0%   (0/19)0%   (0/5)
dumpBytes (PrintWriter, short []): void 0%   (0/1)0%   (0/19)0%   (0/5)
dumpHexRow (PrintWriter, byte [], int): void 0%   (0/1)0%   (0/6)0%   (0/2)
dumpHexRow (PrintWriter, short [], int): void 0%   (0/1)0%   (0/55)0%   (0/10)
isPrintable (byte): boolean 100% (1/1)67%  (10/15)83%  (1.7/2)
dumpHexRow (PrintWriter, ByteBuffer, int): void 100% (1/1)83%  (44/53)90%  (9/10)
dumpByte (PrintWriter, byte): void 100% (1/1)100% (7/7)100% (2/2)
dumpBytes (PrintWriter, ByteBuffer): void 100% (1/1)100% (20/20)100% (5/5)
dumpInt (PrintWriter, int): void 100% (1/1)100% (5/5)100% (2/2)
dumpInt (PrintWriter, int, int): void 100% (1/1)100% (21/21)100% (5/5)

1/*
2 * $Id: DumpBytes.java,v 1.1 2005/11/30 06:58:48 hastings Exp $
3 *
4 * (c) Copyright, Moebius Solutions, Inc., 2004
5 *
6 *                       All Rights Reserved
7 *
8 * This material may be reproduced by or for the U. S. Government
9 * pursuant to the copyright license under the clause at
10 * DFARS 252.227-7014 (OCT 2001).
11 */
12package com.moesol.util;
13 
14import java.io.PrintStream;
15import java.io.PrintWriter;
16import java.nio.ByteBuffer;
17 
18/**
19 * Dump an array of bytes to output as hex and ascii.
20 * Since jSegue treats unsigned char as short to hold
21 * the range 0 - 255 dumpBytes also has a short[] form.
22 * 
23 * @author Hastings
24 */
25public class DumpBytes {
26        public static void dumpBytes(PrintStream ps, byte[] b) {
27                PrintWriter pw = new PrintWriter(ps); 
28                dumpBytes(pw, b);
29                pw.flush();
30        }
31    public static void dumpBytes(PrintStream ps, short[] bytes) {
32        PrintWriter pw = new PrintWriter(ps); 
33        dumpBytes(pw, bytes);
34        pw.flush();
35    }
36        public static void dumpBytes(PrintWriter out, byte[] b) {
37                for (int i = 0; i < b.length; i += 16) {
38                        dumpInt(out, i);
39                        out.print(": ");
40                        dumpHexRow(out, b, i);
41                }
42        }
43    public static void dumpBytes(PrintWriter out, ByteBuffer bb) {
44        for (int i = bb.position(); i < bb.limit(); i += 16) {
45            dumpInt(out, i);
46            out.print(": ");
47            dumpHexRow(out, bb, i);
48        }
49    }
50    public static void dumpBytes(PrintWriter out, short[] bytes) {
51        for (int i = 0; i < bytes.length; i += 16) {
52            dumpInt(out, i);
53            out.print(": ");
54            dumpHexRow(out, bytes, i);
55        }
56    }
57    
58        public static void dumpHexRow(PrintWriter out, byte[] b, int current) {
59        dumpHexRow(out, ByteBuffer.wrap(b), current);
60    }
61    
62    public static void dumpHexRow(PrintWriter out, ByteBuffer bb, int current) {
63                int num_bytes = Math.min(16, bb.limit() - current);
64                
65                for (int i = 0; i < num_bytes; i++) {
66                        dumpByte(out, bb.get(current + i));
67                        out.print(' ');
68                }
69                for (int i = 0; i < num_bytes; i++) {
70                        if (isPrintable(bb.get(current + i))) {
71                                out.print( (char) bb.get(current + i));
72                        } else {
73                                out.print('.');
74                        }
75                }
76                out.println();
77        }
78    public static void dumpHexRow(PrintWriter out, short[] bytes, int current) {
79        int num_bytes = Math.min(16, bytes.length - current);
80        
81        for (int i = 0; i < num_bytes; i++) {
82            dumpByte(out, (byte)bytes[current + i]);
83            out.print(' ');
84        }
85        for (int i = 0; i < num_bytes; i++) {
86            if (isPrintable((byte)bytes[current + i])) {
87                out.print( (char) bytes[current + i]);
88            } else {
89                out.print('.');
90            }
91        }
92        out.println();
93    }
94        public static boolean isPrintable(byte v) {
95                char ch = (char)(v & 0xFF);
96                return (ch >= ' ' && ch <= '~');
97        }
98        public static void dumpByte(PrintWriter out, byte v) {
99                dumpInt(out, v & 0xFF, 2);
100        }
101    public static void dumpByte(PrintStream ps, byte v) {
102        PrintWriter pw = new PrintWriter(ps); 
103        dumpByte(pw, v);
104        pw.flush();
105    }
106        public static void dumpInt(PrintWriter out, int v) {
107                dumpInt(out, v, 4);
108        }
109        public static void dumpInt(PrintWriter out, int v, int width) {
110                String s = Integer.toHexString(v);
111                while (s.length() < width) {
112                        s = "0" + s;
113                }
114                out.print(s);
115        }
116}

[all classes][com.moesol.util]
EMMA 2.0.5312 (C) Vladimir Roubtsov