1 64 65 package com.jcorporate.expresso.core.misc; 66 67 72 73 import java.io.BufferedOutputStream ; 74 import java.io.FilterOutputStream ; 75 import java.io.IOException ; 76 import java.io.OutputStream ; 77 78 79 82 public class InetOutputStream 83 extends FilterOutputStream { 84 private boolean linemode; 85 86 91 public InetOutputStream(OutputStream out) { 92 this(out, true); 93 } 94 95 101 public InetOutputStream(OutputStream out, boolean linemode) { 102 super((out instanceof BufferedOutputStream ) 103 ? out : new BufferedOutputStream (out)); 104 this.linemode = linemode; 105 } 106 107 110 public OutputStream getOutputStream() { 111 return out; 112 } 113 114 117 synchronized public void print(char[] a) 118 throws IOException { 119 for (int i = 0; i < a.length; i++) { 120 write(a[i]); 121 } 122 } 123 124 125 128 public void print(char chr) 129 throws IOException { 130 print(String.valueOf(chr)); 131 } 132 133 134 137 public void print(double dval) 138 throws IOException { 139 print(String.valueOf(dval)); 140 } 141 142 143 146 public void print(float fval) 147 throws IOException { 148 print(String.valueOf(fval)); 149 } 150 151 152 155 public void print(int i) 156 throws IOException { 157 print(String.valueOf(i)); 158 } 159 160 161 164 public void print(long lval) 165 throws IOException { 166 print(String.valueOf(lval)); 167 } 168 169 170 173 public void print(Object obj) 174 throws IOException { 175 print(String.valueOf(obj)); 176 } 177 178 179 182 synchronized public void print(String str) 183 throws IOException { 184 int length = str.length(); 185 186 for (int i = 0; i < length; i++) { 187 write(str.charAt(i)); 188 } 189 } 190 191 192 195 synchronized public void println() 196 throws IOException { 197 write('\r'); 198 write('\n'); 199 } 200 201 202 205 synchronized public void println(char[] a) 206 throws IOException { 207 print(a); 208 println(); 209 } 210 211 212 215 synchronized public void println(char chr) 216 throws IOException { 217 print(chr); 218 println(); 219 } 220 221 222 225 synchronized public void println(double dval) 226 throws IOException { 227 print(dval); 228 println(); 229 } 230 231 232 235 synchronized public void println(float fval) 236 throws IOException { 237 print(fval); 238 println(); 239 } 240 241 242 245 synchronized public void println(int i) 246 throws IOException { 247 print(i); 248 println(); 249 } 250 251 252 255 synchronized public void println(long lval) 256 throws IOException { 257 print(lval); 258 println(); 259 } 260 261 262 265 synchronized public void println(Object obj) 266 throws IOException { 267 print(obj); 268 println(); 269 } 270 271 272 275 synchronized public void println(String str) 276 throws IOException { 277 System.out.println("S: " + str); 278 print(str); 279 println(); 280 } 281 282 283 286 public void setLinemode(boolean flag) { 287 linemode = flag; 288 } 289 290 293 public void write(int i) 294 throws IOException { 295 out.write(i); 296 297 if (linemode && (i == '\n')) { 298 out.flush(); 299 } 300 } 301 302 303 } 304 305 | Popular Tags |