View Javadoc
1 ////////////////////////////////////////////////////////////////////////////// 2 // Clirr: compares two versions of a java library for binary compatibility 3 // Copyright (C) 2003 - 2004 Lars Kühne 4 // 5 // This library is free software; you can redistribute it and/or 6 // modify it under the terms of the GNU Lesser General Public 7 // License as published by the Free Software Foundation; either 8 // version 2.1 of the License, or (at your option) any later version. 9 // 10 // This library is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 // Lesser General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public 16 // License along with this library; if not, write to the Free Software 17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 ////////////////////////////////////////////////////////////////////////////// 19 20 package net.sf.clirr.event; 21 22 import java.io.FileNotFoundException; 23 import java.io.FileOutputStream; 24 import java.io.OutputStream; 25 import java.io.PrintStream; 26 27 /*** 28 * Abstract DiffListener that writes output to some textual 29 * output stream. That stream can either be System.out or a textfile. 30 * 31 * @author lkuehne 32 */ 33 abstract class FileDiffListener extends DiffListenerAdapter 34 { 35 private PrintStream outputStream; 36 37 /*** 38 * Initializes the outputstream. 39 * @param outFile the filename (System.out is used if null is provided here) 40 * @throws FileNotFoundException if there are problems with 41 */ 42 FileDiffListener(String outFile) throws FileNotFoundException 43 { 44 if (outFile == null) 45 { 46 outputStream = System.out; 47 } 48 else 49 { 50 final OutputStream out = new FileOutputStream(outFile); 51 outputStream = new PrintStream(out); 52 } 53 54 } 55 56 /*** 57 * Returns the output stream so subclasses can write data. 58 * @return the output stream 59 */ 60 protected final PrintStream getOutputStream() 61 { 62 return outputStream; 63 } 64 65 66 /*** 67 * Writes a footer and closes the 68 * output stream if necessary. 69 * 70 * @see #writeFooter() 71 */ 72 public final void stop() 73 { 74 writeFooter(); 75 76 if (outputStream != System.out) 77 { 78 outputStream.close(); 79 } 80 super.stop(); 81 } 82 83 /*** 84 * A hook to write footer info to the output stream. 85 * This implementation does nothing, subclasses can override 86 * this method if necessary. 87 * 88 * @see #stop() 89 */ 90 protected void writeFooter() 91 { 92 } 93 }

This page was automatically generated by Maven