1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/samples/delegatingwriterfinal/src-api2.0/api/SimpleBuffer.java Sat Jun 14 09:53:07 2008 +0200
1.3 @@ -0,0 +1,39 @@
1.4 +package api;
1.5 +
1.6 +import java.io.IOException;
1.7 +
1.8 +/**
1.9 + *
1.10 + * @author Jaroslav Tulach
1.11 + */
1.12 +final class SimpleBuffer implements Writer.ImplSeq {
1.13 + private final Writer out;
1.14 + private final StringBuffer sb = new StringBuffer();
1.15 +
1.16 + public SimpleBuffer(Writer out) {
1.17 + this.out = out;
1.18 + }
1.19 +
1.20 + public void close() throws IOException {
1.21 + flush();
1.22 + out.close();
1.23 + }
1.24 +
1.25 + public void flush() throws IOException {
1.26 + if (sb.length() > 0) {
1.27 + out.write(sb.toString());
1.28 + sb.setLength(0);
1.29 + out.flush();
1.30 + }
1.31 + }
1.32 +
1.33 + public void write(CharSequence seq) throws IOException {
1.34 + if (seq.length() < 1024) {
1.35 + sb.append(seq);
1.36 + } else {
1.37 + flush();
1.38 + out.append(seq);
1.39 + }
1.40 + }
1.41 +
1.42 +}