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