📄 filecompare.java
字号:
/* Derby - Class org.apache.derbyTesting.functionTests.harness.FileCompare Copyright 1999, 2004 The Apache Software Foundation or its licensors, as applicable. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */package org.apache.derbyTesting.functionTests.harness;/*** * FileCompare.java * * Compare two files using SimpleDiff * Purpose: simulate diff * Note: if usesysdiff=true, we execute the system's diff ***/import java.io.*;import java.lang.reflect.*;import java.util.StringTokenizer;import java.util.Properties;public class FileCompare{ private String testBase; private String framework; private String jvmName; private String jvmString; private String serverJvm; private int iminor; private boolean searchJdk12 = false; private boolean searchJdk13 = false; private boolean searchJdk14 = false; private int driverVersionMajor = 0; private int driverVersionMinor = 0; private boolean searchFrame; private boolean searchDriverVersion; private InputStream master = null; private boolean verbose; public FileCompare() { verbose = Boolean.getBoolean("verbose"); } // The arguments should be the names of the input and output files public boolean exec(String outfile, File outDir, PrintWriter pwDiff, String testBaseOrig, String framework, String jvmName, int iminor, boolean useprocess, boolean usesysdiff, String canondir, String canonpath, String serverJvm) throws IOException, ClassNotFoundException { testBase = testBaseOrig; this.framework = framework; this.jvmName = jvmName; this.iminor = iminor; this.jvmString = jvmName; this.serverJvm = serverJvm; BufferedReader outFile; BufferedReader masterFile; StringBuffer sb = new StringBuffer(); // If framework is DerbyNet, we may need to check subdirs of the master canon dir // for specific masters by client we're running against. So, get version // for later use if that is the case. if (framework.startsWith("DerbyNet")) { Class c = null; Method m = null; Object o = null; Integer i = null; try { c = Class.forName(NetServer.getDriverName(framework)); o = c.newInstance(); m = c.getMethod("getMajorVersion", null); i = (Integer)m.invoke(o, null); driverVersionMajor = i.intValue(); m = c.getMethod("getMinorVersion", null); i = (Integer)m.invoke(o, null); driverVersionMinor = i.intValue(); if (framework.startsWith("DerbyNet")) searchDriverVersion = true; } catch ( Exception e ) { //if anything goes wrong, make sure the driver version values are set to zero //forget about it. System.out.println("Cannot determine driver version:" + e); driverVersionMinor = 0; driverVersionMajor = 0; searchDriverVersion = false; } } // The outfile name is known -- outfile // But the master canon needs to be located // The user can set canondir (or it defaults to "master") String topdir = ""; if ( (canondir != null) && (canondir.length()>0) ) topdir = canondir; else { // if this is using product jars, use product_master first Class c = FileCompare.class; // get our class loader InputStream is = c.getResourceAsStream("/org/apache/derby/info/DBMS.properties"); Properties dbprop = new Properties(); dbprop.load(is); is.close(); String filename=dbprop.getProperty("derby.product.file"); if (filename != null) { //looks like it might be one of our jars? if (filename.startsWith("derby") && filename.endsWith(".jar")) { canondir = "product_master"; // remember redirection topdir = "product_master"; } else topdir = "master"; } else topdir = "master"; } // There can be subdirs under the master for framework, jvm String subdir = ""; boolean searchDefault = true; // if no framework or special jvm boolean searchBoth = false; boolean searchJvm = false; if ( (framework != null) && (framework.length()>0) ) { searchFrame = true; subdir = framework; } if ( (jvmName != null) && (jvmName.length()>0) & (!jvmName.equals("currentjvm")) ) { searchJvm = true; if (searchFrame) searchBoth = true; if ( iminor >= 2 ) // jdk12 or higher may use jdk12 masters jvmString = "jdk12"; if ( iminor >= 2 ) searchJdk12 = true; if ( iminor >= 3 ) searchJdk13 = true; if ( iminor >= 4 ) searchJdk14 = true; subdir += jvmName; } if ( searchFrame || searchJvm || searchBoth ) searchDefault = false; sb.append(topdir); if (subdir.length()>0) sb.append(subdir + '/'); sb.append(testBase + ".out"); String masterfilename = sb.toString(); InputStream is = null; // Now try to locate the master file if (is == null) { searchCanondir(topdir); is = master; } // If the master is still not found, print an error and return if ( is == null ) { System.out.println("No master file was found."); pwDiff.println("No master file was found."); pwDiff.flush(); return true; } // compress blanks in output columns to make up for column width differences // for JCC output if (NetServer.isClientConnection(framework)) { try { Sed sed = new Sed(); File JCCOutFile = new File(outDir, testBase + ".tmpmstr"); sed.execJCC(is, JCCOutFile); is = new FileInputStream(JCCOutFile); } catch (ClassFormatError cfe) { System.out.println("SED Error: " + cfe.getMessage()); } } else { // read in in fixed format, but write out relying on default encoding File encodedOutFile = new File(outDir, testBase + ".tmpmstr"); BufferedReader inFile = new BufferedReader(new InputStreamReader(is, "UTF-8")); PrintWriter pw = new PrintWriter ( new BufferedWriter(new FileWriter(encodedOutFile), 10000), true ); int c; while ((c = inFile.read()) != -1) pw.write(c); pw.flush(); pw.close(); is = new FileInputStream(encodedOutFile); } // Define the input and output files outFile = new BufferedReader(new FileReader(outfile)); masterFile = new BufferedReader(new InputStreamReader(is)); // Do the comparison (diff) if (usesysdiff == true) return doSysDiff(is, testBase, outfile, outDir, pwDiff); else { return doDiff2(outFile,masterFile, pwDiff); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -