1 22 package org.jboss.util.stream; 23 24 import java.io.IOException ; 25 import java.io.PrintWriter ; 26 import java.io.OutputStream ; 27 import java.io.InterruptedIOException ; 28 import java.io.Writer ; 29 30 40 public class CRLFPrintWriter 41 extends PrintWriter 42 { 43 protected boolean autoFlush = false; 44 45 public CRLFPrintWriter(final Writer out) { 46 super(out); 47 } 48 49 public CRLFPrintWriter(final Writer out, final boolean autoFlush) { 50 super(out, autoFlush); 51 this.autoFlush = autoFlush; 52 } 53 54 public CRLFPrintWriter(final OutputStream out) { 55 super(out); 56 } 57 58 public CRLFPrintWriter(final OutputStream out, final boolean autoFlush) { 59 super(out, autoFlush); 60 this.autoFlush = autoFlush; 61 } 62 63 protected void ensureOpen() throws IOException { 64 if (out == null) 65 throw new IOException ("Stream closed"); 66 } 67 68 public void println() { 69 try { 70 synchronized (lock) { 71 ensureOpen(); 72 73 out.write("\r\n"); 74 75 if (autoFlush) { 76 out.flush(); 77 } 78 } 79 } 80 catch (InterruptedIOException e) { 81 Thread.currentThread().interrupt(); 82 } 83 catch (IOException e) { 84 setError(); 85 } 86 } 87 } 88 | Popular Tags |