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