📄 sed.java
字号:
/* Derby - Class org.apache.derbyTesting.functionTests.harness.Sed 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;/*** * Sed.java * * This is a version of "sed" in Java for the Derby Function Tests, * written using the OROMatcher Perl5 regular expression classes. * The substitutions/deletions are based on the original kornshell tests. * ***/import java.io.*;import java.util.Vector;import org.apache.oro.text.regex.*;import java.util.Enumeration;import java.util.Properties;import java.util.StringTokenizer;public class Sed{ public Sed() { } public static void main(String[] args) throws Exception { if (args == null || args.length != 2) { System.err.println("Usage: Sed sourcefile targetfile"); System.exit(1); } File src = new File(args[0]); File tgt = new File(args[1]); new Sed().exec(src,tgt,null, false, false); } // The arguments should be the names of the input and output files public void exec(File srcFile, File dstFile, InputStream isSed, boolean isJCC, boolean isI18N) throws IOException { // Vector for storing lines to be deleted Vector deleteLines = new Vector(); deleteLines.addElement("^ij version.*$"); deleteLines.addElement("^\\*\\*\\*\\* Test Run Started .* \\*\\*\\*\\*$"); deleteLines.addElement("^\\*\\*\\*\\* Test Run Completed .* \\*\\*\\*\\*$"); deleteLines.addElement("^ELAPSED TIME = [0-9]* milliseconds$"); deleteLines.addElement("^\\^\\?$"); //deleteLines.addElement("^\\.$"); // originally to remove lines with a dot deleteLines.addElement("^S.*ij> $"); deleteLines.addElement("^ *$"); deleteLines.addElement("^Server StackTrace:$"); deleteLines.addElement("^\\[ *$"); deleteLines.addElement("^\\] *$"); deleteLines.addElement("^\\[$"); deleteLines.addElement("^\\]$"); deleteLines.addElement("^<not available>\\]$"); deleteLines.addElement("^(.*at .*)\\(.*:[0-9].*\\)$"); deleteLines.addElement("^(.*at .*)\\(*.java\\)$"); deleteLines.addElement("^(.*at .*)\\(Compiled Code\\)$"); deleteLines.addElement("^(.*at .*)\\(Interpreted Code\\)$"); deleteLines.addElement("^(.*at .*)\\(Unknown Source\\)$"); deleteLines.addElement("^(.*at .*)\\(Native Method\\)$"); deleteLines.addElement("^\\tat $"); // rare case of incomplete stack trace line deleteLines.addElement("optimizer estimated cost"); deleteLines.addElement("optimizer estimated row count"); deleteLines.addElement("Using executables built for native_threads"); deleteLines.addElement("Estimate of memory used"); deleteLines.addElement("Size of merge runs"); deleteLines.addElement("Number of merge runs"); deleteLines.addElement("Sort type"); deleteLines.addElement("Optimization started at .*$"); deleteLines.addElement("WARNING 02000: No row was found for FETCH, UPDATE or DELETE"); // deleteLines for stack traces from j9 jvm to match those above for other jvms deleteLines.addElement("Stack trace:"); deleteLines.addElement("^.*java/.*\\<init\\>\\(.*\\)V"); deleteLines.addElement("^.*org/apache/derby/.*\\(.*\\).*$"); // next for j9 stack trace with jarfiles test run. deleteLines.addElement("^.*java/.*\\(.*\\).*$"); deleteLines.addElement("^\\[.*db2jcc.jar\\] [0-9].[1-9] - .*$"); deleteLines.addElement("^\\[.*db2jcc_license_c.jar\\] [1-9].[0-9] - .*$"); deleteLines.addElement("^XSDB.*$"); // Vectors for substitutions Vector searchStrings = new Vector(); searchStrings.addElement("^Transaction:\\(.*\\) *\\|"); searchStrings.addElement("^Read [0-9]* of [0-9]* bytes$"); searchStrings.addElement("Directory .*connect.wombat.seg0"); // Filter for constraint names - bug 5622 - our internal constraint names are too long. To be db2 compatible, we have reworked them. StringBuffer constraintNameFilter = new StringBuffer(); constraintNameFilter.append("SQL[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]"); searchStrings.addElement(constraintNameFilter.toString()); // Filter for uuids StringBuffer uuidFilter = new StringBuffer(); uuidFilter.append("[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]-"); uuidFilter.append("[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-"); uuidFilter.append("[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-"); uuidFilter.append("[0-9a-f][0-9a-f][0-9a-f][0-9a-f]-"); uuidFilter.append("[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]"); searchStrings.addElement(uuidFilter.toString()); // Filter for timestamps StringBuffer timestampFilter = new StringBuffer(); timestampFilter.append( "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] " ); timestampFilter.append( "[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9]* *" ); searchStrings.addElement( timestampFilter.toString() ); // 3 digit year timestampFilter = new StringBuffer(); timestampFilter.append( "[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] " ); timestampFilter.append( "[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9]* *" ); searchStrings.addElement( timestampFilter.toString() ); // ibm13 year timestampFilter = new StringBuffer(); timestampFilter.append( "[0-9]-[0-9][0-9]-[0-9][0-9] " ); timestampFilter.append( "[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9]* *" ); searchStrings.addElement( timestampFilter.toString() ); // Filter remove transaction id's from deadlock messages searchStrings.addElement("^ Waiting XID : {.*}"); searchStrings.addElement("^ Granted XID : .*$"); searchStrings.addElement("^The selected victim is XID : .*"); // Filters for build numbers searchStrings.addElement("(beta - )\\(([0-9]*)\\)"); searchStrings.addElement("Level2CostEstimateImpl: .*"); // Filter for xa tests for the numbers representing the db name (it can change) searchStrings.addElement("^Transaction ([0-9])* : \\(([0-9]*)\\,([0-9a-f]*)\\,([0-9a-f]*)\\)"); // Filter for optimizer number for zindexesLevel1 test (due to a change in display width for the test) searchStrings.addElement("^Modifying access paths using optimizer .[0-9]*"); searchStrings.addElement("CDWS[0-9]*"); searchStrings.addElement("IXWS[0-9]*"); // for j9, to eliminate intermittent failures due to this problem in j9: searchStrings.addElement("FAILED STACK MAP"); if (isJCC) { searchStrings.addElement("[ ]*\\|"); searchStrings.addElement("^--*"); } //Filter to suppress absould paths in error message for roll forward recovery tests searchStrings.addElement("Directory.*.wombat.already.exists"); // Filter for "DB2ConnectionCorrelator" text that can be printed as // part of some JCC error messages. searchStrings.addElement(" DB2ConnectionCorrelator: [0-9A-Z.]*"); Vector subStrings = new Vector(); subStrings.addElement("Transaction:(XXX)|"); subStrings.addElement("Read ... bytes"); subStrings.addElement("Directory DBLOCATION/seg0"); subStrings.addElement("xxxxGENERATED-IDxxxx"); subStrings.addElement("xxxxFILTERED-UUIDxxxx"); subStrings.addElement("xxxxxxFILTERED-TIMESTAMPxxxxx"); subStrings.addElement("xxxxxxFILTERED-TIMESTAMPxxxxx"); subStrings.addElement("xxxxxxFILTERED-TIMESTAMPxxxxx"); // remove transaction id's from deadlock messages subStrings.addElement(" Waiting XID : {WWW,QQQ}"); subStrings.addElement(" Granted XID : {GGG.QQQ}..."); subStrings.addElement("The selected victim is XID : VVV"); // sub build numbers subStrings.addElement("$1(xxXXxxFILTERED-BUILD-NUMBERxxXXxx)"); subStrings.addElement("Level2CostEstimateImpl: xxXXxxFILTERED-INFORMATIONxxXXxx"); // sub for db name in xa tests (it can change) subStrings.addElement("Transaction $1 : ($2,FILTERED,FILTERED)"); // sub for optimizer number for zindexesLevel1 test subStrings.addElement("Modifying access paths using optimizer FILTERED_NUMBER"); subStrings.addElement("CDWSno"); subStrings.addElement("IXWSno"); // for j9, to eliminate intermittent failures due to this problem in j9: subStrings.addElement(""); // for JCC replace multiple blanks with one blank to handle differences // in display width if (isJCC) { subStrings.addElement(" |"); subStrings.addElement("-----"); } subStrings.addElement("Directory DBLOCATION/wombat already exists"); // ignore the 'DB2ConnectionCorrelator' thing altogether. subStrings.addElement(""); doWork(srcFile, dstFile, null, deleteLines, searchStrings, subStrings, isSed, isI18N); } // end exec // This just does JCC changes on the output master file public void execJCC(InputStream is, File dstFile) throws IOException { // Vector for storing lines to be deleted Vector deleteLines = new Vector(); // Vectors for substitutions Vector searchStrings = new Vector(); searchStrings.addElement("[ ]*\\|"); searchStrings.addElement("^--*"); Vector subStrings = new Vector(); // true and false show up as 1 and 0 in JCC. //because they have no boolean support subStrings.addElement(" |"); subStrings.addElement("-----"); doWork(null, dstFile, is, deleteLines, searchStrings, subStrings, null); } private void doWork(File srcFile, File dstFile, InputStream is, Vector deleteLines, Vector searchStrings, Vector subStrings, InputStream isSed) throws IOException { doWork(srcFile, dstFile, is, deleteLines, searchStrings, subStrings, isSed, false); } private void doWork(File srcFile, File dstFile, InputStream is, Vector deleteLines, Vector searchStrings, Vector subStrings, InputStream isSed, boolean isI18N) throws IOException { boolean lineDeleted = false; PatternMatcher matcher; Perl5Compiler pcompiler; PatternMatcherInput input; BufferedReader inFile; PrintWriter outFile;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -