mwomack     2002/12/18 23:55:29

  Modified:    tests/src/java/org/apache/log4j/util Compare.java
  Log:
  Added code to output the contents of the files when a difference is detected.
  
  Revision  Changes    Path
  1.6       +32 -4     jakarta-log4j/tests/src/java/org/apache/log4j/util/Compare.java
  
  Index: Compare.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/tests/src/java/org/apache/log4j/util/Compare.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Compare.java      9 May 2002 15:43:44 -0000       1.5
  +++ Compare.java      19 Dec 2002 07:55:29 -0000      1.6
  @@ -32,21 +32,49 @@
         lineCounter++;
         String s2 = in2.readLine();
         if(!s1.equals(s2)) {
  -     System.out.println("Files ["+file1+"] and ["+file2+"] differ on line " 
  +        System.out.println("Files ["+file1+"] and ["+file2+"] differ on line " 
                           +lineCounter);
  -     System.out.println("One reads:  ["+s1+"].");
  -     System.out.println("Other reads:["+s2+"].");
  -     return false;
  +             System.out.println("One reads:  ["+s1+"].");
  +             System.out.println("Other reads:["+s2+"].");
  +             outputFile(file1);
  +             outputFile(file2);
  +             return false;
         }
       }
       
       // the second file is longer
       if(in2.read() != -1) {
         System.out.println("File ["+file2+"] longer than file ["+file1+"].");
  +     outputFile(file1);
  +     outputFile(file2);
         return false;
       }
       
       return true;
  +  }
  +  
  +  private static void outputFile(String file) throws FileNotFoundException, 
  +                                                            IOException {
  +    BufferedReader in1 = new BufferedReader(new FileReader(file));
  +    
  +    String s1;
  +    int lineCounter = 0;
  +    System.out.println("--------------------------------");
  +    System.out.println("Contents of " + file + ":");
  +    while((s1 = in1.readLine()) != null) {
  +      lineCounter++;
  +      System.out.print(lineCounter);
  +      if (lineCounter < 10) {
  +        System.out.print("   : ");
  +      } else if (lineCounter < 100) {
  +        System.out.print("  : ");
  +      } else if (lineCounter < 1000) {
  +        System.out.print(" : ");
  +      } else {
  +        System.out.print(": ");
  +      }
  +      System.out.println(s1);
  +    }
     }
     
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to