1 16 package org.directwebremoting.util; 17 18 import java.io.BufferedWriter ; 19 import java.io.OutputStream ; 20 import java.io.OutputStreamWriter ; 21 import java.io.PrintWriter ; 22 import java.io.Writer ; 23 24 28 public class DebuggingPrintWriter extends PrintWriter 29 { 30 35 public DebuggingPrintWriter(String prefix, Writer out) 36 { 37 super(out, false); 38 this.prefix = prefix; 39 } 40 41 47 public DebuggingPrintWriter(String prefix, Writer out, boolean autoFlush) 48 { 49 super(out, autoFlush); 50 this.prefix = prefix; 51 } 52 53 62 public DebuggingPrintWriter(String prefix, OutputStream out) 63 { 64 super(out, false); 65 this.prefix = prefix; 66 } 67 68 77 public DebuggingPrintWriter(String prefix, OutputStream out, boolean autoFlush) 78 { 79 super(new BufferedWriter (new OutputStreamWriter (out)), autoFlush); 80 this.prefix = prefix; 81 } 82 83 86 public void print(boolean x) 87 { 88 super.print(x); 89 buffer.append(x); 90 } 91 92 95 public void print(char x) 96 { 97 super.print(x); 98 buffer.append(x); 99 } 100 101 104 public void print(int x) 105 { 106 super.print(x); 107 buffer.append(x); 108 } 109 110 113 public void print(long x) 114 { 115 super.print(x); 116 buffer.append(x); 117 } 118 119 122 public void print(float x) 123 { 124 super.print(x); 125 buffer.append(x); 126 } 127 128 131 public void print(double x) 132 { 133 super.print(x); 134 buffer.append(x); 135 } 136 137 140 public void print(char x[]) 141 { 142 super.print(x); 143 buffer.append(x); 144 } 145 146 149 public void print(String x) 150 { 151 super.print(x); 152 buffer.append(x); 153 } 154 155 158 public void print(Object x) 159 { 160 super.print(x); 161 buffer.append(x); 162 } 163 164 167 public void println() 168 { 169 synchronized (lock) 170 { 171 printBuffer(); 172 super.println(); 173 } 174 } 175 176 179 public void println(boolean x) 180 { 181 synchronized (lock) 182 { 183 printBuffer(); 184 super.println(x); 185 } 186 } 187 188 191 public void println(char x) 192 { 193 synchronized (lock) 194 { 195 printBuffer(); 196 super.println(x); 197 } 198 } 199 200 203 public void println(int x) 204 { 205 synchronized (lock) 206 { 207 printBuffer(); 208 super.println(x); 209 } 210 } 211 212 215 public void println(long x) 216 { 217 synchronized (lock) 218 { 219 printBuffer(); 220 super.println(x); 221 } 222 } 223 224 227 public void println(float x) 228 { 229 synchronized (lock) 230 { 231 printBuffer(); 232 super.println(x); 233 } 234 } 235 236 239 public void println(double x) 240 { 241 synchronized (lock) 242 { 243 printBuffer(); 244 super.println(x); 245 } 246 } 247 248 251 public void println(char x[]) 252 { 253 synchronized (lock) 254 { 255 printBuffer(); 256 super.println(x); 257 } 258 } 259 260 263 public void println(String x) 264 { 265 synchronized (lock) 266 { 267 printBuffer(); 268 super.println(x); 269 } 270 } 271 272 275 public void println(Object x) 276 { 277 synchronized (lock) 278 { 279 printBuffer(); 280 super.println(x); 281 } 282 } 283 284 287 private void printBuffer() 288 { 289 if (buffer.length() > 0) 290 { 291 log.debug(prefix + buffer.toString()); 292 buffer.setLength(0); 293 } 294 } 295 296 300 public String getPrefix() 301 { 302 return prefix; 303 } 304 305 309 public void setPrefix(String prefix) 310 { 311 this.prefix = prefix; 312 } 313 314 317 private String prefix; 318 319 322 protected final StringBuffer buffer = new StringBuffer (); 323 324 327 private static final Logger log = Logger.getLogger(DebuggingPrintWriter.class); 328 } 329 | Popular Tags |