3 import java.io.BufferedReader;
5 import java.io.FileNotFoundException;
6 import java.io.FileReader;
7 import java.io.IOException;
8 import java.util.regex.Pattern;
11 public class FileComparator
13 private final File basedir;
14 private BufferedReader expectedReader;
15 private BufferedReader foundReader;
17 public FileComparator(File basedir)
19 this.basedir = basedir;
22 public boolean isEqual(final String expectedFile, final String foundFile)
24 FileNotFoundException,
28 String expected, found;
30 file = new File(basedir, expectedFile);
31 expectedReader = new BufferedReader(new FileReader(file));
33 file = new File(basedir, foundFile);
34 foundReader = new BufferedReader(new FileReader(file));
37 while ((expected = expectedReader.readLine()) != null)
39 found = foundReader.readLine();
42 System.err.println("Found less content than expected!");
43 System.err.println("First missing line: " + expected);
47 expected = expected.trim();
49 if (!expected.equals(found))
51 System.err.println("Mismatch!");
52 System.err.println("Expected: " + expected);
53 System.err.println("Found: " + found);
58 if ((found = foundReader.readLine()) != null)
60 System.err.println("Found more content than expected!");
61 System.err.println("Starting with: " + found);