📄 filecompare.java
字号:
public boolean doDiff2(BufferedReader outFile, BufferedReader masterFile, PrintWriter pwDiff) throws IOException { return ((new SimpleDiff()).doWork(masterFile,outFile,pwDiff)); } public boolean doSysDiff(InputStream masterIS, String testBase, String outfile, File outDir, PrintWriter pwDiff) throws IOException { // Create a temp file to copy the master (located as an InputStream) BufferedReader in = new BufferedReader(new InputStreamReader(masterIS)); File tempMaster = new File((new File(outDir,testBase + ".master")).getCanonicalPath()); // Create a PrintWriter for copying the master temporarily for the diff PrintWriter pwMaster = new PrintWriter( new BufferedWriter (new FileWriter(tempMaster.getPath()), 10000), true ); String str = ""; while ( (str = in.readLine()) != null ) { pwMaster.println(str); } pwMaster.close(); pwMaster = null; in = null; String diffs = "0"; // Now create a process and do the system diff, capture to .out Process pr = null; try { StringBuffer sb = new StringBuffer(); sb.append("diff "); sb.append(tempMaster.getCanonicalPath()); sb.append(" "); sb.append(outfile); String diffCmd = sb.toString(); //System.out.println("diffCmd = " + diffCmd); pr = Runtime.getRuntime().exec(diffCmd); // We need the process inputstream to capture into the diff file //System.out.println("Capture the process InputStream..."); BackgroundStreamDrainer stdout = new BackgroundStreamDrainer(pr.getInputStream(), null); BackgroundStreamDrainer stderr = new BackgroundStreamDrainer(pr.getErrorStream(), null); pr.waitFor(); String result = HandleResult.handleResult(pr.exitValue(), stdout.getData(), stderr.getData(), pwDiff); diffs = result.substring( result.lastIndexOf(',')+1 ); //System.out.println("diffs: " + diffs); pr.destroy(); pr = null; } catch(Throwable t) { System.out.println("Process exception: " + t); if (pr != null) { pr.destroy(); pr = null; } } tempMaster.delete(); if ( diffs.equals("0") ) return false; else return true; } public boolean doDiff(BufferedReader outFile, BufferedReader masterFile, PrintWriter pwDiff) throws IOException { String str1; String str2; boolean diff = false; int line = 0; int diffnum = 0; int diffline = 0; while ( (str1 = outFile.readLine()) != null ) { line++; str1 = str1.trim(); //System.out.println("Reading line: " + line); // Read the line from the master file and compare if ( (str2 = masterFile.readLine()) != null ) { str2 = str2.trim(); if (!str1.equals(str2)) { // Some lines diff because of too many spaces StringBuffer sb1 = new StringBuffer(); StringBuffer sb2 = new StringBuffer(); StringTokenizer st1 = new StringTokenizer(str1); while (st1.hasMoreTokens()) { sb1.append(st1.nextToken()); } //System.out.println("Out line: " + sb1.toString()); StringTokenizer st2 = new StringTokenizer(str2); while (st2.hasMoreTokens()) { sb2.append(st2.nextToken()); } //System.out.println("Master line: " + sb2.toString()); if ( sb1.toString().equals(sb2.toString()) ) diff = false; // If the two lines are dashes, but wrong #, just ignore else if ( (str1.startsWith("-----")) && (str1.endsWith("-----")) ) { if ( (str2.startsWith("-----")) && (str2.endsWith("-----")) ) diff = false; } else { diff = true; diffnum++; System.out.println("Diff occurred at line: " + line); pwDiff.println("Diff occurred at line: " + line); pwDiff.flush(); break; } } else { diff = false; } } } // end while outFile.close(); masterFile.close(); return diff; }// end exec private void searchCanondir(String canondir) { String prefix = canondir + '/'; if (master == null && searchFrame) searchFramework(prefix); if (master == null) searchJvm(prefix); if (master == null && searchDriverVersion) searchDriverVersion(prefix); if (master == null) getmaster(prefix); if (master == null && canondir != "master") searchCanondir("master"); } private void searchJvm(String prefix) { // The JVM search follows the following pattern, with one exception: // first search jvmName (to support unnamed/non-IBM or Sun JVMs) // if vendor == IBM, search ibm+rev then jdk+rev, decrementing rev by one until rev=13, // in each dir, search framework and driver version if applicable. // BUT, if it's j9, first j9_foundation, then search j9_22 for 22, otherwise, j9_13 then // the normal ibm13 search pattern: ibm13 then jdk13. String newprefix; if (jvmName.startsWith("j9") || (serverJvm != null && serverJvm.startsWith("j9"))) { if (jvmName.startsWith("j9_foundation")) { newprefix = prefix + "j9_foundation" + '/'; if (master == null && searchDriverVersion) searchDriverVersion(newprefix); if (master == null) getmaster(newprefix); } else { newprefix = prefix + jvmName + '/'; if ((!jvmName.equals("j9_13")) && (iminor > 1)) { for (int i = iminor; i > 1; i--) { if (master == null) { newprefix = prefix + "j9_2" + i + '/'; getmaster(newprefix); } } } if (master == null) newprefix = prefix + "j9_13" + '/'; } if (master == null && searchDriverVersion) searchDriverVersion(newprefix); if (master == null) getmaster(newprefix); } for (int i = iminor; i >= 2; i--) { if (jvmName.startsWith("ibm")) { newprefix = prefix + "ibm1" + i + '/'; if (master == null && searchDriverVersion) searchDriverVersion(newprefix); if (master == null) getmaster(newprefix); } newprefix = prefix + "jdk1" + i + '/'; if (master == null && searchDriverVersion) searchDriverVersion(newprefix); if (master == null) getmaster(newprefix); } } private void searchFramework(String prefix) { String newprefix; newprefix = prefix + framework + '/'; if (master == null) searchJvm(newprefix); if (master == null && searchDriverVersion) searchDriverVersion(newprefix); if (master == null) getmaster(newprefix); } private void searchDriverVersion(String prefix) { // It is not sufficient to simply search the current driver version. // We must search down through the versions to find the newest applicable master. String newprefix; for (int j = ((driverVersionMajor * 10) + driverVersionMinor); j >= 10; j--) { newprefix = prefix + "ver" + j / 10 + "." + j % 10 + '/'; if (master == null) getmaster(newprefix); } } private void getmaster(String prefix) { String fullname = prefix + testBase + ".out"; master = RunTest.loadTestResource(fullname); if (master != null) if (verbose) System.out.println("MasterFileName = "+fullname); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -