You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ca...@apache.org on 2007/06/30 00:52:43 UTC

svn commit: r552054 - in /logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j: Compare.java util/Compare.java

Author: carnold
Date: Fri Jun 29 15:52:42 2007
New Revision: 552054

URL: http://svn.apache.org/viewvc?view=rev&rev=552054
Log:
Bug 42783: Remove duplicate o.a.l.util.Compare

Removed:
    logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/Compare.java
Modified:
    logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/Compare.java

Modified: logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/Compare.java
URL: http://svn.apache.org/viewvc/logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/Compare.java?view=diff&rev=552054&r1=552053&r2=552054
==============================================================================
--- logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/Compare.java (original)
+++ logging/log4j/companions/extras/trunk/src/test/java/org/apache/log4j/util/Compare.java Fri Jun 29 15:52:42 2007
@@ -18,12 +18,14 @@
 package org.apache.log4j.util;
 
 import java.io.BufferedReader;
+import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.io.*;
+import java.util.zip.GZIPInputStream;
 
 
 public class Compare {
@@ -135,4 +137,66 @@
     }
     in1.close();
   }
+
+
+    public static boolean gzCompare(final Class testClass,
+                                    final String actual,
+                                    final String expected)
+      throws FileNotFoundException, IOException {
+      String resourceName = expected;
+      int lastSlash = expected.lastIndexOf("/");
+      if (lastSlash >= 0) {
+          resourceName = expected.substring(lastSlash + 1);
+      }
+      InputStream resourceStream = testClass.getResourceAsStream(resourceName);
+      if (resourceStream == null) {
+          throw new FileNotFoundException("Could not locate resource " + resourceName);
+      }
+
+      BufferedReader in1 = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(actual))));
+      BufferedReader in2 = new BufferedReader(new InputStreamReader(new GZIPInputStream(resourceStream)));
+      try {
+        return gzCompare(testClass, actual, expected, in1, in2);
+      } finally {
+        in1.close();
+        in2.close();
+      }
+    }
+
+    public static boolean gzCompare(Class testClass, String file1, String file2, BufferedReader in1, BufferedReader in2) throws IOException {
+
+      String s1;
+      int lineCounter = 0;
+
+      while ((s1 = in1.readLine()) != null) {
+        lineCounter++;
+
+        String s2 = in2.readLine();
+
+        if (!s1.equals(s2)) {
+          System.out.println(
+            "Files [" + file1 + "] and [" + file2 + "] differ on line "
+            + lineCounter);
+          System.out.println("One reads:  [" + s1 + "].");
+          System.out.println("Other reads:[" + s2 + "].");
+          outputFile(testClass, file1);
+          outputFile(testClass, file2);
+
+          return false;
+        }
+      }
+
+      // the second file is longer
+      if (in2.read() != -1) {
+        System.out.println(
+          "File [" + file2 + "] longer than file [" + file1 + "].");
+        outputFile(testClass, file1);
+        outputFile(testClass, file2);
+
+        return false;
+      }
+
+      return true;
+    }
+
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org