1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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