author | Jaroslav Tulach <jtulach@netbeans.org> |
Sat, 14 Jun 2008 10:04:53 +0200 | |
changeset 210 | acf2c31e22d4 |
parent 209 | 1c999569643b |
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 |
public class CountingWriter implements Writer.ImplSeq { |
jtulach@66 | 11 |
private final AtomicInteger counter; |
jtulach@66 | 12 |
|
jtulach@66 | 13 |
private CountingWriter(AtomicInteger counter) { |
jtulach@66 | 14 |
this.counter = counter; |
jtulach@66 | 15 |
} |
jtulach@66 | 16 |
|
jtulach@66 | 17 |
public static Writer create(AtomicInteger result) { |
jtulach@66 | 18 |
return Writer.create(new CountingWriter(result)); |
jtulach@66 | 19 |
} |
jtulach@66 | 20 |
|
jtulach@66 | 21 |
@Override |
jtulach@66 | 22 |
public void write(CharSequence csq) throws IOException { |
jtulach@66 | 23 |
counter.addAndGet(csq.length()); |
jtulach@66 | 24 |
} |
jtulach@66 | 25 |
|
jtulach@66 | 26 |
@Override |
jtulach@66 | 27 |
public void flush() throws IOException { |
jtulach@66 | 28 |
} |
jtulach@66 | 29 |
|
jtulach@66 | 30 |
@Override |
jtulach@66 | 31 |
public void close() throws IOException { |
jtulach@66 | 32 |
} |
jtulach@66 | 33 |
|
jtulach@66 | 34 |
} |