    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17
    18  package org.apache.log4j.util;
    19
    20  import java.io.BufferedReader;
    21  import java.io.FileNotFoundException;
    22  import java.io.FileReader;
    23  import java.io.IOException;
    24
    25  public class Compare {
    26
    27    static final int B1_NULL = -1;
    28    static final int B2_NULL = -2;
    29
    30    static
    31    public
    32    boolean compare(String file1, String file2) throws FileNotFoundException,
    33                                                              IOException {
    34      BufferedReader in1 = new BufferedReader(new FileReader(file1));
    35      BufferedReader in2 = new BufferedReader(new FileReader(file2));
    36
    37      String s1;
    38      int lineCounter = 0;
    39      while((s1 = in1.readLine()) != null) {
    40        lineCounter++;
    41        String s2 = in2.readLine();
    42        if(!s1.equals(s2)) {
    43  	System.out.println("Files ["+file1+"] and ["+file2+"] differ on line "
    44  			   +lineCounter);
    45  	System.out.println("One reads:  ["+s1+"].");
    46  	System.out.println("Other reads:["+s2+"].");
    47  	return false;
    48        }
    49      }
    50
    51      // the second file is longer
    52      if(in2.read() != -1) {
    53        System.out.println("File ["+file2+"] longer than file ["+file1+"].");
    54        return false;
    55      }
    56
    57      return true;
    58    }
    59
    60  }