1 /* Copyright 2004 The Apache Software Foundation 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 package org.apache.xmlbeans.impl.util; 17 18 import java.io.IOException; 19 import java.io.LineNumberReader; 20 import java.io.Reader; 21 import java.util.List; 22 23 /** 24 * This needs to be here so that it can be accessed by FilerImpl 25 */ 26 public class Diff 27 { 28 public static void readersAsText(Reader r1, String name1, Reader r2, String name2, 29 List diffs) 30 throws IOException 31 { 32 LineNumberReader reader1 = new LineNumberReader(r1); 33 LineNumberReader reader2 = new LineNumberReader(r2); 34 String line1 = reader1.readLine(); 35 String line2 = reader2.readLine(); 36 while (line1 != null && line2 != null) 37 { 38 if (!line1.equals(line2)) 39 { 40 diffs.add("File \"" + name1 + "\" and file \"" + 41 name2 + "\" differ at line " + reader1.getLineNumber() + 42 ":" + "\n" + line1 + "\n========\n" + line2); 43 break; 44 } 45 line1 = reader1.readLine(); 46 line2 = reader2.readLine(); 47 } 48 if (line1 == null && line2 != null) 49 diffs.add("File \"" + name2 + "\" has extra lines at line " + 50 reader2.getLineNumber() + ":\n" + line2); 51 if (line1 != null && line2 == null) 52 diffs.add("File \"" + name1 + "\" has extra lines at line " + 53 reader1.getLineNumber() + ":\n" + line1); 54 } 55 }