001    /*
002            Copyright (c) 2009 Olivier Chafik, All Rights Reserved
003            
004            This file is part of JNAerator (http://jnaerator.googlecode.com/).
005            
006            JNAerator is free software: you can redistribute it and/or modify
007            it under the terms of the GNU General Public License as published by
008            the Free Software Foundation, either version 3 of the License, or
009            (at your option) any later version.
010            
011            JNAerator is distributed in the hope that it will be useful,
012            but WITHOUT ANY WARRANTY; without even the implied warranty of
013            MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014            GNU General Public License for more details.
015            
016            You should have received a copy of the GNU General Public License
017            along with JNAerator.  If not, see <http://www.gnu.org/licenses/>.
018    */
019    package com.ochafik.io;
020    import java.io.IOException;
021    import java.io.OutputStream;
022    public class StringBufferOutputStream extends OutputStream {
023            StringBuffer buffer;
024            public StringBufferOutputStream() {
025                    buffer=new StringBuffer();
026            }
027            public String toString() { return buffer.toString(); }
028            public StringBufferOutputStream(StringBuffer b) {
029                    buffer=b;
030            }
031            public StringBufferOutputStream(String s) {
032                    buffer=new StringBuffer(s);
033            }       
034            public void close() throws IOException {
035                    buffer=null;
036            }
037            public void flush() throws IOException {}
038            public void write(int i) throws IOException {
039                    buffer.append((char)i);
040            }
041            public void write(byte[] b,int off,int l) throws IOException {
042                    buffer.append(new String(b,off,l));
043            }
044            public void write(byte[] b) throws IOException {
045                    buffer.append(new String(b));
046            }
047    }
048