1 package ca.uhn.hl7v2.testpanel.util;
2
3 import java.io.IOException;
4 import java.io.Reader;
5 import java.nio.CharBuffer;
6
7 public class CharCountingReaderWrapper extends Reader {
8
9 private long myCount = 0;
10 private Reader myWrap;
11
12 public CharCountingReaderWrapper(Reader theWrap) {
13 myWrap = theWrap;
14 }
15
16
17
18
19
20
21 @Override
22 public void close() throws IOException {
23 myWrap.close();
24 }
25
26
27
28
29 public long getCount() {
30 return myCount;
31 }
32
33
34
35
36
37
38 @Override
39 public void mark(int theReadAheadLimit) throws IOException {
40 myWrap.mark(theReadAheadLimit);
41 }
42
43
44
45
46
47
48 @Override
49 public boolean markSupported() {
50 return myWrap.markSupported();
51 }
52
53
54
55
56
57
58 @Override
59 public int read() throws IOException {
60 int read = myWrap.read();
61 myCount++;
62 return read;
63 }
64
65
66
67
68
69
70 @Override
71 public int read(char[] theCbuf) throws IOException {
72 int read = myWrap.read(theCbuf);
73 myCount += read;
74 return read;
75 }
76
77
78
79
80
81
82 @Override
83 public int read(char[] theCbuf, int theOff, int theLen) throws IOException {
84 int read = myWrap.read(theCbuf, theOff, theLen);
85 myCount += read;
86 return read;
87 }
88
89
90
91
92
93
94 @Override
95 public int read(CharBuffer theTarget) throws IOException {
96 int read = myWrap.read(theTarget);
97 myCount += read;
98 return read;
99 }
100
101
102
103
104
105
106 @Override
107 public boolean ready() throws IOException {
108 return myWrap.ready();
109 }
110
111
112
113
114
115
116 @Override
117 public void reset() throws IOException {
118 myCount = 0;
119 myWrap.reset();
120 }
121
122
123
124
125
126
127 @Override
128 public long skip(long theN) throws IOException {
129 long skip = myWrap.skip(theN);
130 myCount += skip;
131 return skip;
132 }
133
134 }