EMMA Coverage Report (generated Mon Oct 04 21:03:19 MDT 2004)
[all classes][biz.xsoftware.buildtemplate]

COVERAGE SUMMARY FOR SOURCE FILE [Util.java]

nameclass, %method, %block, %line, %
Util.java100% (1/1)100% (8/8)84%  (159/189)81%  (39.9/49)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class Util100% (1/1)100% (8/8)84%  (159/189)81%  (39.9/49)
getFile (URL): File 100% (1/1)64%  (28/44)70%  (7/10)
inputsAreTheSame (long, InputStream, InputStream): boolean 100% (1/1)80%  (28/35)70%  (7/10)
arraysEqual (byte [], byte []): boolean 100% (1/1)85%  (22/26)67%  (4/6)
<static initializer> 100% (1/1)92%  (11/12)92%  (0.9/1)
readInWholeFile (byte [], InputStream): byte [] 100% (1/1)93%  (28/30)88%  (7/8)
Util (): void 100% (1/1)100% (3/3)100% (1/1)
copyFile (File, File): void 100% (1/1)100% (21/21)100% (7/7)
copyInToOut (InputStream, OutputStream): void 100% (1/1)100% (18/18)100% (6/6)

1/*
2 * Created on Sep 5, 2004
3 *
4 * TODO To change the template for this generated file go to
5 * Window - Preferences - Java - Code Style - Code Templates
6 */
7package biz.xsoftware.buildtemplate;
8 
9import java.io.File;
10import java.io.FileInputStream;
11import java.io.FileOutputStream;
12import java.io.IOException;
13import java.io.InputStream;
14import java.io.OutputStream;
15import java.net.URL;
16import java.util.logging.Logger;
17 
18/**
19 * @author Dean Hiller
20 *
21 * TODO To change the template for this generated type comment go to
22 * Window - Preferences - Java - Code Style - Code Templates
23 */
24public class Util implements FileLocator {
25 
26        private final static Logger log = Logger.getLogger(Util.class.getName());
27        
28        public static void copyInToOut(InputStream in, OutputStream out) throws IOException {
29                byte[] buffer = new byte[10000];
30                int bytesRead = 0;
31                while(bytesRead >= 0) {
32                        out.write(buffer, 0, bytesRead);
33                        bytesRead = in.read(buffer);
34                }        
35        }
36            
37        public File getFile(URL url) {
38                String filePart = url.getFile();
39                String nameWithClass = filePart.substring(5, filePart.length());
40                int index = nameWithClass.indexOf("!");
41                String fileName = nameWithClass.substring(0, index);
42                
43                File f = new File(fileName);
44                
45                if(!f.exists()) {
46                        log.warning("Problem with buildtemplate.jar, contact owner.");
47                        log.warning("Could not find file="+fileName);
48                        log.warning("This message comes from a class in buildtemplate.jar");
49//                        System.exit(1);
50                }
51 
52                return f;
53        }
54        
55        public static void copyFile(File src, File dest) throws IOException {        
56                dest.createNewFile();
57                
58                FileInputStream in = new FileInputStream(src);
59                FileOutputStream out = new FileOutputStream(dest);
60                Util.copyInToOut(in, out);
61                in.close();
62                out.close();
63        }
64        
65        /**
66         * @param in1
67         * @param in2
68         * @return
69         * @throws IOException
70         */
71        public static boolean inputsAreTheSame(long size, InputStream in1, InputStream in2) throws IOException {
72                //lie here as we dont' want to compare
73                if(size > Integer.MAX_VALUE)
74                        return true;
75                
76                byte[] buffer1 = new byte[(int)size];
77                byte[] buffer2 = new byte[(int)size];
78 
79                buffer1 = readInWholeFile(buffer1, in1);
80                buffer2 = readInWholeFile(buffer2, in2);
81                if(buffer1 == null || buffer2 == null) {
82                        log.finer("can't compare the two files, replacing it");
83                        return false;
84                }
85                
86                return arraysEqual(buffer1, buffer2);
87        }
88        
89        /**
90         * Returns the byte buffer array unless it is the incorrect size.
91         * 
92         * @param b
93         * @param in
94         * @return
95         * @throws IOException
96         */
97        private static byte[] readInWholeFile(byte[] b, InputStream in) throws IOException {
98                int read = 0;
99                int totalRead = 0;
100                while(totalRead < b.length && read >= 0) {
101                        read = in.read(b, totalRead, b.length-totalRead);
102                        totalRead += read;
103                }
104                if(read >= 0) //if we got end of stream, we read one too many bytes.
105                        return b;
106                return null;
107        }
108        
109        private static boolean arraysEqual(byte[] b1, byte[] b2) {
110                if(b1.length != b2.length)
111                        return false;
112                
113                for(int i = 0; i < b1.length; i++) {
114                        if(b1[i] != b2[i])
115                                return false;
116                }
117                return true;
118        }
119}

[all classes][biz.xsoftware.buildtemplate]
EMMA 2.0.4217 (C) Vladimir Roubtsov