1 19 package org.enhydra.zeus.result; 20 21 import java.io.IOException ; 22 import java.io.OutputStream ; 23 import java.io.OutputStreamWriter ; 24 import java.io.Writer ; 25 26 import org.enhydra.zeus.Result; 28 29 46 public class StreamResult extends BaseResult { 47 48 49 private Writer writer; 50 51 63 public StreamResult(OutputStream outputStream, String systemID) { 64 if (outputStream == null) { 65 throw new IllegalArgumentException ("A StreamResult cannot have " + 66 "a null OutputStream."); 67 } 68 69 this.writer = new OutputStreamWriter (outputStream); 70 setSystemID(systemID); 71 } 72 73 84 public StreamResult(OutputStream outputStream) { 85 this(outputStream, null); 86 } 87 88 100 public StreamResult(Writer writer, String systemID) { 101 if (writer == null) { 102 throw new IllegalArgumentException ("A StreamResult cannot have " + 103 "a null Writer."); 104 } 105 106 this.writer = writer; 107 setSystemID(systemID); 108 } 109 110 121 public StreamResult(Writer writer) { 122 this(writer, null); 123 } 124 125 137 public void write(String output) throws IOException { 138 if (writer != null) { 139 writer.write(output); 140 writer.flush(); 141 } else { 142 throw new IOException ("No output source to write to!"); 143 } 144 } 145 146 155 public Writer getWriter() throws IOException { 156 if (writer != null) { 157 return writer; 158 } else { 159 throw new IOException ("No output source supplied."); 160 } 161 } 162 } 163 | Popular Tags |