001: /*
002: * Copyright (C) 2001, 2002 Robert MacGrogan
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: *
019: * $Archive: SourceJammer$
020: * $FileName: DiffTextPrinter.java$
021: * $FileID: 4286$
022: *
023: * Last change:
024: * $AuthorName: Rob MacGrogan$
025: * $VerID: 8879$
026: * $Date: 5/6/03 8:31 PM$
027: * $Comment: Just some main method modifications for testing.$
028: */
029: package JLibDiff;
030:
031: import java.io.File;
032: import java.io.FileOutputStream;
033: import java.io.PrintStream;
034:
035: /**
036: * Title: $FileName: DiffTextPrinter.java$
037: * @author $AuthorName: Rob MacGrogan$
038: * @version $VerNum: 5$
039: *
040: * $KeyWordsOff: $<br/><br/>
041: *
042: * Prints diff text to a stream
043: */
044: public class DiffTextPrinter extends HunkVisitor {
045:
046: private PrintStream out = null;
047:
048: public DiffTextPrinter(PrintStream out) {
049: this .out = out;
050: }
051:
052: /**
053: * @see JLibDiff.HunkVisitor#visitHunkAdd(HunkAdd)
054: */
055: public void visitHunkAdd(HunkAdd hunk) {
056: out.print(Builder.buildHunkString(hunk));
057: }
058:
059: /**
060: * @see JLibDiff.HunkVisitor#visitHunkChange(HunkChange)
061: */
062: public void visitHunkChange(HunkChange hunk) {
063: out.print(Builder.buildHunkString(hunk));
064: }
065:
066: /**
067: * @see JLibDiff.HunkVisitor#visitHunkDel(HunkDel)
068: */
069: public void visitHunkDel(HunkDel hunk) {
070: out.print(Builder.buildHunkString(hunk));
071: }
072:
073: public static void main(String[] args) {
074: try {
075: String fileOne = args[0];
076: String fileTwo = args[1];
077: String fileResult = args[2];
078:
079: diff dOld = new diff(fileOne, fileTwo,
080: "JLibDiff.GnuDiffAlgorithm");
081:
082: //GNU
083: //dOld.setDiffAlgorithmClass("JLibDiff.GnuDiffAlgorithm");
084: File flOut = new File(fileResult + ".gnu");
085: FileOutputStream stmOut = new FileOutputStream(flOut);
086: try {
087: PrintStream out = new PrintStream(stmOut);
088: try {
089: DiffTextPrinter printer = new DiffTextPrinter(out);
090: dOld.accept(printer);
091: } finally {
092: out.flush();
093: out.close();
094: }
095: } finally {
096: stmOut.close();
097: }
098:
099: // dOld = new diff(fileOne, fileTwo);
100: //
101: // //JLibDiff
102: // dOld.setDiffAlgorithmClass("JLibDiff.JLibDiffAlgorithm");
103: // flOut = new File(fileResult + ".gnu");
104: // stmOut = new FileOutputStream(flOut);
105: // try{
106: // PrintStream out = new PrintStream(stmOut);
107: // try{
108: // DiffTextPrinter printer = new DiffTextPrinter(out);
109: // dOld.accept(printer);
110: // }
111: // finally{
112: // out.flush();
113: // out.close();
114: // }
115: // }
116: // finally{
117: // stmOut.close();
118: // }
119:
120: dOld = new diff(fileOne, fileTwo,
121: "JLibDiff.JRCSMyersAlgorithm");
122:
123: //JRCS
124: //dOld.setDiffAlgorithmClass("JLibDiff.JRCSMyersAlgorithm");
125: flOut = new File(fileResult + ".jrcs");
126: stmOut = new FileOutputStream(flOut);
127: try {
128: PrintStream out = new PrintStream(stmOut);
129: try {
130: DiffTextPrinter printer = new DiffTextPrinter(out);
131: dOld.accept(printer);
132: } finally {
133: out.flush();
134: out.close();
135: }
136: } finally {
137: stmOut.close();
138: }
139:
140: } catch (Throwable thr) {
141: thr.printStackTrace();
142: }
143: }
144:
145: }
|