001    package org.shiftone.jrat.util.io;
002    
003    
004    import org.shiftone.jrat.util.log.Logger;
005    
006    import java.io.IOException;
007    import java.io.PrintStream;
008    import java.io.Writer;
009    
010    
011    /**
012     * @author jeff@shiftone.org (Jeff Drost)
013     */
014    public class PrintStreamWriter extends Writer {
015    
016        private static final Logger LOG = Logger.getLogger(PrintStreamWriter.class);
017        private final PrintStream printStream;
018    
019        public PrintStreamWriter(PrintStream printStream) {
020    
021            super(printStream);
022    
023            this.printStream = printStream;
024        }
025    
026    
027        public void write(int c) throws IOException {
028            printStream.print(c);
029        }
030    
031    
032        public void write(char cbuf[]) throws IOException {
033            printStream.print(cbuf);
034        }
035    
036    
037        public void write(String str) throws IOException {
038            printStream.print(str);
039        }
040    
041    
042        public void write(String str, int off, int len) throws IOException {
043            printStream.print(str.substring(off, off + len));
044        }
045    
046    
047        public void close() throws IOException {
048            printStream.close();
049        }
050    
051    
052        public void flush() throws IOException {
053            printStream.flush();
054        }
055    
056    
057        public void write(char cbuf[], int off, int len) throws IOException {
058    
059            char[] target = new char[len];
060    
061            System.arraycopy(cbuf, off, target, 0, len);
062            printStream.print(target);
063        }
064    }