1 23 24 package com.sun.enterprise.cli.framework; 25 26 import java.io.PrintStream ; 27 import java.io.OutputStream ; 28 29 30 33 class NullOutput implements IOutput 34 { 35 NullOutput( ) 36 { 37 } 38 39 public void print( String msg ) 40 { 41 } 43 44 public void print( Object msg ) 45 { 46 } 48 49 public void println( String msg ) 50 { 51 } 53 54 public void println( Object msg ) 55 { 56 } 58 59 public void close() 60 { 61 } 63 64 public void flush() 65 { 66 } 68 } 69 70 71 class Output implements IOutput 72 { 73 OutputStream mOutputStream = null; 74 PrintStream mPrint = null; 75 boolean mCloseWhenDone = false; 76 77 public Output( OutputStream outputStream, boolean closeWhenDone ) 78 throws Exception 79 { 80 mPrint = new PrintStream ( outputStream ); 81 82 mOutputStream = outputStream; 84 mCloseWhenDone = closeWhenDone; 85 } 86 87 91 public void close() 92 { 93 if ( mCloseWhenDone ) 94 { 95 try 96 { 97 mOutputStream.close(); 98 } 99 catch( Exception e ) 100 { 101 } 102 } 103 mOutputStream = null; 104 mPrint = null; 105 mCloseWhenDone = false; 106 } 107 108 109 public void print( String msg ) 110 { 111 mPrint.print( msg ); 112 } 113 114 115 public void print( Object msg ) 116 { 117 mPrint.println( msg.toString() ); 118 } 119 120 121 public void println( String msg ) 122 { 123 mPrint.println( msg ); 124 } 125 126 127 public void println( Object msg ) 128 { 129 mPrint.println( msg.toString() ); 130 } 131 132 133 public void flush() 134 { 135 try 136 { 137 mOutputStream.flush(); 138 } 139 catch( Exception e ) 140 { 141 } 142 } 143 } 144 145 146 149 public abstract class GenericOutput implements IOutput 150 { 151 private IOutput mOutput = null; 152 153 154 160 protected GenericOutput( OutputStream out, boolean closeWhenDone ) 161 { 162 try 163 { 164 if ( out != null ) 165 { 166 mOutput = new Output( out, closeWhenDone ); 167 } 168 else 169 { 170 mOutput = new NullOutput(); 171 } 172 173 } 174 catch ( Exception e ) 175 { 176 mOutput = new NullOutput(); 177 } 178 } 179 180 181 186 public void print( String message ) 187 { 188 mOutput.print( message ); 189 } 190 191 192 197 public void print( Object msg ) 198 { 199 mOutput.print( msg.toString() ); 200 } 201 202 203 208 public void println( String message ) 209 { 210 mOutput.println( message ); 211 } 212 213 214 219 public void println( Object msg ) 220 { 221 mOutput.println( msg.toString() ); 222 } 223 224 225 228 public void close() 229 { 230 mOutput.close(); 231 mOutput = new NullOutput(); 232 } 233 234 235 239 public void flush() 240 { 241 mOutput.flush(); 242 } 243 244 245 } 246 | Popular Tags |