1 22 package org.jboss.logging.util; 23 24 import java.io.IOException ; 25 import java.io.PrintWriter ; 26 import java.io.Writer ; 27 28 import org.jboss.logging.LoggerPlugin; 29 30 38 public class LoggerPluginWriter 39 extends PrintWriter 40 { 41 45 public LoggerPluginWriter(final LoggerPlugin logger) 46 { 47 super(new PluginWriter(logger), true); 48 } 49 50 static class PluginWriter extends Writer 51 { 52 private LoggerPlugin logger; 53 private boolean closed; 54 55 public PluginWriter(final LoggerPlugin logger) 56 { 57 lock = logger; 58 this.logger = logger; 59 } 60 61 public void write(char[] cbuf, int off, int len) 62 throws IOException 63 { 64 if (closed) 65 { 66 throw new IOException ("Called write on closed Writer"); 67 } 68 while (len > 0 && (cbuf[len - 1] == '\n' || cbuf[len - 1] == '\r')) 70 { 71 len--; 72 } 73 if (len > 0) 74 { 75 logger.info(String.copyValueOf(cbuf, off, len)); 76 } 77 } 78 79 public void flush() 80 throws IOException 81 { 82 if (closed) 83 { 84 throw new IOException ("Called flush on closed Writer"); 85 } 86 } 87 88 public void close() 89 { 90 closed = true; 91 } 92 } 93 94 } 95 | Popular Tags |