| Home >> All >> com >> thermidor >> xml >> [ output Javadoc ] |
Source code: com/thermidor/xml/output/PrintWriterHandler.java
1 package com.thermidor.xml.output; 2 import java.io.IOException; 3 import java.io.File; 4 import java.io.FileOutputStream; 5 import java.io.PrintWriter; 6 import com.thermidor.util.Assert; 7 public class PrintWriterHandler extends OutputHandler { 8 /** 9 * Construct a new default instance of a PrintWriterHandler. 10 */ 11 public PrintWriterHandler() { 12 super(); 13 } 14 /** 15 * <code>start</code> is called on the output handler to initialize it 16 * ready to start processing output. 17 * @param data the initialization data. 18 * @throws InvalidInitializationParameter is raised if the initialization 19 * data was invalid for this instance. 20 * @throws IOException is raised if there was an IO related error. 21 */ 22 public void start(Object initializationData) 23 throws InvalidInitializationParameter, 24 IOException { 25 try { 26 Assert.notNull(initializationData, 27 "initialization parameter for handler type [" + 28 PrintWriterHandler.class + 29 "] must be non null"); 30 Assert.instanceOf(initializationData, 31 PrintWriter.class, 32 "initialization parameter for handler type [" + 33 PrintWriterHandler.class + 34 "] must be java.io.PrintWriter, but was [" + 35 initializationData.getClass()+"]"); 36 } 37 catch(Assert.AssertException ae) { 38 throw new InvalidInitializationParameter(ae); 39 } 40 _writer = (PrintWriter)initializationData; 41 } 42 /** 43 * Handle the provided string data . 44 * @param data the text data that is to be output. 45 */ 46 public void handle(String data) throws IOException{ 47 _writer.print(data); 48 } 49 /** 50 * The responsibilty of the finished member function is to handle clean up 51 * when the output is popped from the output stack. 52 * @return any relevant string data that was collected will the handler 53 * is in operation. 54 */ 55 public String finish() throws IOException { 56 _writer.flush(); 57 return EMPTY; 58 } 59 60 }