dd0f73ecca087911ab7c88f46c3675ebc2d9340b
[jump.git] / dol / test / src / test / util / Diff.java
1 package test.util;\r
2 \r
3 import java.io.BufferedReader;\r
4 import java.io.FileReader;\r
5 \r
6 /**\r
7  * Class to diff two files\r
8  */\r
9 public class Diff {\r
10 \r
11     /**\r
12      * Main.\r
13      *\r
14      * @param args names of the two files to compare\r
15      */\r
16     public static void main(String[] args) throws Exception {\r
17         if (args.length != 2) {\r
18             //System.out.println("Usage: java Diff file1 file2");\r
19             throw new Exception("Usage: java Diff file1 file2");\r
20         }\r
21 \r
22         try {\r
23           BufferedReader fileOneReader = new BufferedReader(new FileReader(args[0]));\r
24           BufferedReader fileTwoReader = new BufferedReader(new FileReader(args[1]));\r
25 \r
26           String lineOne, lineTwo;\r
27           while ((lineOne = fileOneReader.readLine()) != null) {\r
28               lineTwo = fileTwoReader.readLine();\r
29               if (lineTwo == null)\r
30                   throw new Exception("Files are not equal: "\r
31                           + args[1] + " is shorter.");\r
32               else if (!lineOne.equals(lineTwo))\r
33                   throw new Exception("Files do not match.");\r
34           }\r
35 \r
36           if ((lineTwo = fileTwoReader.readLine()) != null)\r
37               throw new Exception("Files are not equal: "\r
38                       + args[0]  + " is shorter.");\r
39         }\r
40         catch (Exception e) {\r
41           throw e;\r
42         }\r
43 \r
44         //System.out.println("Files are equal.");\r
45     }\r
46 }\r