samples/delegatingwriterfinal/src-api2.0/api/SimpleBuffer.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 10:04:51 +0200
changeset 209 1c999569643b
parent 196 79eff053c4ec
child 210 acf2c31e22d4
permissions -rw-r--r--
to the end of daily_life
     1 package api;
     2 
     3 import java.io.IOException;
     4 
     5 /**
     6  *
     7  * @author Jaroslav Tulach
     8  */
     9 final class SimpleBuffer implements Writer.ImplSeq {
    10     private final Writer out;
    11     private final StringBuffer sb = new StringBuffer();
    12     
    13     public SimpleBuffer(Writer out) {
    14         this.out = out;
    15     }
    16 
    17     public void close() throws IOException {
    18         flush();
    19         out.close();
    20     }
    21 
    22     public void flush() throws IOException {
    23         if (sb.length() > 0) {
    24             out.write(sb.toString());
    25             sb.setLength(0);
    26             out.flush();
    27         }
    28     }
    29 
    30     public void write(CharSequence seq) throws IOException {
    31         if (seq.length() < 1024) {
    32             sb.append(seq);
    33         } else {
    34             flush();
    35             out.append(seq);
    36         }
    37     }
    38 
    39 }