samples/delegatingwriter/test/org/apidesign/delegatingwriter/CountingWriter.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:58:05 +0200
changeset 152 eb6f29070331
parent 61 59df94cee246
child 153 b5cbb797ec0a
permissions -rw-r--r--
Checking that all examples pair the opening and closing brackets
     1 
     2 package org.apidesign.delegatingwriter;
     3 
     4 import java.io.IOException;
     5 import java.io.Writer;
     6 
     7 // BEGIN: writer.CountingWriter
     8 /** Writer that counts the number of written in characters.
     9  *
    10  * @author Jaroslav Tulach
    11  */
    12 public class CountingWriter extends Writer {
    13     private int counter;
    14     
    15     
    16     public int getCharacterCount() {
    17         return counter;
    18     }
    19 
    20     @Override
    21     public void write(char[] cbuf, int off, int len) throws IOException {
    22         counter += len;
    23     }
    24 
    25     @Override
    26     public Writer append(CharSequence csq) throws IOException {
    27         counter += csq.length();
    28         return this;
    29     }
    30 // FINISH: writer.CountingWriter
    31 
    32     @Override
    33     public Writer append(CharSequence csq, int start, int end) throws IOException {
    34         counter += (end - start);
    35         return this;
    36     }
    37 
    38     @Override
    39     public Writer append(char c) throws IOException {
    40         counter++;
    41         return this;
    42     }
    43 
    44     @Override
    45     public void write(int c) throws IOException {
    46         counter++;
    47     }
    48 
    49     @Override
    50     public void write(char[] cbuf) throws IOException {
    51         counter += cbuf.length;
    52     }
    53 
    54     @Override
    55     public void write(String str) throws IOException {
    56         counter += str.length();
    57     }
    58 
    59     @Override
    60     public void write(String str, int off, int len) throws IOException {
    61         counter += len;
    62     }
    63 
    64     @Override
    65     public void flush() throws IOException {
    66     }
    67 
    68     @Override
    69     public void close() throws IOException {
    70     }
    71 
    72 }