samples/delegatingwriter/test/org/apidesign/delegatingwriter/CountingWriter.java
changeset 61 59df94cee246
child 152 eb6f29070331
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/samples/delegatingwriter/test/org/apidesign/delegatingwriter/CountingWriter.java	Sat Jun 14 09:53:03 2008 +0200
     1.3 @@ -0,0 +1,72 @@
     1.4 +
     1.5 +package org.apidesign.delegatingwriter;
     1.6 +
     1.7 +import java.io.IOException;
     1.8 +import java.io.Writer;
     1.9 +
    1.10 +// BEGIN: writer.CountingWriter
    1.11 +/** Writer that counts the number of written in characters.
    1.12 + *
    1.13 + * @author Jaroslav Tulach
    1.14 + */
    1.15 +public class CountingWriter extends Writer {
    1.16 +    private int counter;
    1.17 +    
    1.18 +    
    1.19 +    public int getCharacterCount() {
    1.20 +        return counter;
    1.21 +    }
    1.22 +
    1.23 +    @Override
    1.24 +    public void write(char[] cbuf, int off, int len) throws IOException {
    1.25 +        counter += len;
    1.26 +    }
    1.27 +
    1.28 +    @Override
    1.29 +    public Writer append(CharSequence csq) throws IOException {
    1.30 +        counter += csq.length();
    1.31 +        return this;
    1.32 +    }
    1.33 +// END: writer.CountingWriter
    1.34 +
    1.35 +    @Override
    1.36 +    public Writer append(CharSequence csq, int start, int end) throws IOException {
    1.37 +        counter += (end - start);
    1.38 +        return this;
    1.39 +    }
    1.40 +
    1.41 +    @Override
    1.42 +    public Writer append(char c) throws IOException {
    1.43 +        counter++;
    1.44 +        return this;
    1.45 +    }
    1.46 +
    1.47 +    @Override
    1.48 +    public void write(int c) throws IOException {
    1.49 +        counter++;
    1.50 +    }
    1.51 +
    1.52 +    @Override
    1.53 +    public void write(char[] cbuf) throws IOException {
    1.54 +        counter += cbuf.length;
    1.55 +    }
    1.56 +
    1.57 +    @Override
    1.58 +    public void write(String str) throws IOException {
    1.59 +        counter += str.length();
    1.60 +    }
    1.61 +
    1.62 +    @Override
    1.63 +    public void write(String str, int off, int len) throws IOException {
    1.64 +        counter += len;
    1.65 +    }
    1.66 +
    1.67 +    @Override
    1.68 +    public void flush() throws IOException {
    1.69 +    }
    1.70 +
    1.71 +    @Override
    1.72 +    public void close() throws IOException {
    1.73 +    }
    1.74 +
    1.75 +}