samples/delegatingwriterfinal/src-api1.0/api/SimpleBuffer.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 30 Oct 2014 20:46:27 +0100
changeset 408 9a439a79c6d0
permissions -rw-r--r--
Use scala 2.10.4 to compile on JDK8
     1 package api;
     2 
     3 import java.io.IOException;
     4 
     5 /**
     6  *
     7  * @author Jaroslav Tulach
     8  */
     9 final class SimpleBuffer implements Writer.Impl {
    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         out.write(sb.toString());
    24         sb.setLength(0);
    25         out.flush();
    26     }
    27 
    28     public void write(String str, int off, int len) throws IOException {
    29         sb.append(str, len, len);
    30     }
    31 
    32     public void write(char[] arr, int off, int len) throws IOException {
    33         sb.append(arr, len, len);
    34     }
    35 
    36 }