dol: initial dol commit
[jump.git] / dol / test / src / test / util / Diff.java
diff --git a/dol/test/src/test/util/Diff.java b/dol/test/src/test/util/Diff.java
new file mode 100644 (file)
index 0000000..dd0f73e
--- /dev/null
@@ -0,0 +1,46 @@
+package test.util;\r
+\r
+import java.io.BufferedReader;\r
+import java.io.FileReader;\r
+\r
+/**\r
+ * Class to diff two files\r
+ */\r
+public class Diff {\r
+\r
+    /**\r
+     * Main.\r
+     *\r
+     * @param args names of the two files to compare\r
+     */\r
+    public static void main(String[] args) throws Exception {\r
+        if (args.length != 2) {\r
+            //System.out.println("Usage: java Diff file1 file2");\r
+            throw new Exception("Usage: java Diff file1 file2");\r
+        }\r
+\r
+        try {\r
+          BufferedReader fileOneReader = new BufferedReader(new FileReader(args[0]));\r
+          BufferedReader fileTwoReader = new BufferedReader(new FileReader(args[1]));\r
+\r
+          String lineOne, lineTwo;\r
+          while ((lineOne = fileOneReader.readLine()) != null) {\r
+              lineTwo = fileTwoReader.readLine();\r
+              if (lineTwo == null)\r
+                  throw new Exception("Files are not equal: "\r
+                          + args[1] + " is shorter.");\r
+              else if (!lineOne.equals(lineTwo))\r
+                  throw new Exception("Files do not match.");\r
+          }\r
+\r
+          if ((lineTwo = fileTwoReader.readLine()) != null)\r
+              throw new Exception("Files are not equal: "\r
+                      + args[0]  + " is shorter.");\r
+        }\r
+        catch (Exception e) {\r
+          throw e;\r
+        }\r
+\r
+        //System.out.println("Files are equal.");\r
+    }\r
+}\r