samples/delegatingwriterfinal/src-test2.0/api/usage/twodotzero/CountingWriter.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:53:06 +0200
changeset 66 8379bb7c0dff
child 194 2c53209c30e4
permissions -rw-r--r--
Tests rewritten to new version, just the Writer version 2.0 does not yet implement Appendable
     1 
     2 package api.usage.twodotzero;
     3 
     4 import api.Writer;
     5 import java.io.IOException;
     6 import java.util.concurrent.atomic.AtomicInteger;
     7 
     8 /** Writer that counts the number of written in characters.
     9  *
    10  * @author Jaroslav Tulach
    11  */
    12 public class CountingWriter implements Writer.ImplSeq {
    13     private final AtomicInteger counter;
    14     
    15     private CountingWriter(AtomicInteger counter) {
    16         this.counter = counter;
    17     }
    18     
    19     public static Writer create(AtomicInteger result) {
    20         return Writer.create(new CountingWriter(result));
    21     }
    22 
    23     @Override
    24     public void write(CharSequence csq) throws IOException {
    25         counter.addAndGet(csq.length());
    26     }
    27 
    28     @Override
    29     public void flush() throws IOException {
    30     }
    31 
    32     @Override
    33     public void close() throws IOException {
    34     }
    35 
    36 }