View Javadoc

1   /*
2   	Copyright (c) 2009 Olivier Chafik, All Rights Reserved
3   	
4   	This file is part of JNAerator (http://jnaerator.googlecode.com/).
5   	
6   	JNAerator is free software: you can redistribute it and/or modify
7   	it under the terms of the GNU General Public License as published by
8   	the Free Software Foundation, either version 3 of the License, or
9   	(at your option) any later version.
10  	
11  	JNAerator is distributed in the hope that it will be useful,
12  	but WITHOUT ANY WARRANTY; without even the implied warranty of
13  	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  	GNU General Public License for more details.
15  	
16  	You should have received a copy of the GNU General Public License
17  	along with JNAerator.  If not, see <http://www.gnu.org/licenses/>.
18  */
19  package com.ochafik.io;
20  import java.io.IOException;
21  import java.io.OutputStream;
22  public class StringBufferOutputStream extends OutputStream {
23  	StringBuffer buffer;
24  	public StringBufferOutputStream() {
25  		buffer=new StringBuffer();
26  	}
27  	public String toString() { return buffer.toString(); }
28  	public StringBufferOutputStream(StringBuffer b) {
29  		buffer=b;
30  	}
31  	public StringBufferOutputStream(String s) {
32  		buffer=new StringBuffer(s);
33  	}	
34  	public void close() throws IOException {
35  		buffer=null;
36  	}
37  	public void flush() throws IOException {}
38  	public void write(int i) throws IOException {
39  		buffer.append((char)i);
40  	}
41  	public void write(byte[] b,int off,int l) throws IOException {
42  		buffer.append(new String(b,off,l));
43  	}
44  	public void write(byte[] b) throws IOException {
45  		buffer.append(new String(b));
46  	}
47  }
48