View Javadoc
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  	 * (non-Javadoc)
18  	 * 
19  	 * @see java.io.Reader#close()
20  	 */
21  	@Override
22  	public void close() throws IOException {
23  		myWrap.close();
24  	}
25  
26  	/**
27  	 * @return the count
28  	 */
29  	public long getCount() {
30  		return myCount;
31  	}
32  
33  	/*
34  	 * (non-Javadoc)
35  	 * 
36  	 * @see java.io.Reader#mark(int)
37  	 */
38  	@Override
39  	public void mark(int theReadAheadLimit) throws IOException {
40  		myWrap.mark(theReadAheadLimit);
41  	}
42  
43  	/*
44  	 * (non-Javadoc)
45  	 * 
46  	 * @see java.io.Reader#markSupported()
47  	 */
48  	@Override
49  	public boolean markSupported() {
50  		return myWrap.markSupported();
51  	}
52  
53  	/*
54  	 * (non-Javadoc)
55  	 * 
56  	 * @see java.io.Reader#read()
57  	 */
58  	@Override
59  	public int read() throws IOException {
60  		int read = myWrap.read();
61  		myCount++;
62  		return read;
63  	}
64  
65  	/*
66  	 * (non-Javadoc)
67  	 * 
68  	 * @see java.io.Reader#read(char[])
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  	 * (non-Javadoc)
79  	 * 
80  	 * @see java.io.Reader#read(char[], int, int)
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  	 * (non-Javadoc)
91  	 * 
92  	 * @see java.io.Reader#read(java.nio.CharBuffer)
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 	 * (non-Javadoc)
103 	 * 
104 	 * @see java.io.Reader#ready()
105 	 */
106 	@Override
107 	public boolean ready() throws IOException {
108 		return myWrap.ready();
109 	}
110 
111 	/*
112 	 * (non-Javadoc)
113 	 * 
114 	 * @see java.io.Reader#reset()
115 	 */
116 	@Override
117 	public void reset() throws IOException {
118 		myCount = 0;
119 		myWrap.reset();
120 	}
121 
122 	/*
123 	 * (non-Javadoc)
124 	 * 
125 	 * @see java.io.Reader#skip(long)
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 }