4 package uk.ac.vamsas.client.utils;
\r
6 import java.io.IOException;
\r
7 import java.io.Reader;
\r
11 * Simple wrapper for reader to keep track of position in stream.
\r
12 * This is used in the document unmarshalling mechanism to compute
\r
13 * a simple hash based on the distance between the read blocks containing
\r
14 * the start and end tags of the XML.
\r
16 public class ChecksummedReader extends Reader {
\r
17 private Reader myReader=null;
\r
18 private long count=0;
\r
19 public ChecksummedReader(Reader myReader) {
\r
21 this.myReader = myReader;
\r
26 * @see java.io.Reader#close()
\r
28 public void close() throws IOException {
\r
32 throw new IOException("Close called on un-inited ChecksummedReader");
\r
36 * @see java.io.Reader#read(char[], int, int)
\r
38 public int read(char[] cbuf, int off, int len) throws IOException {
\r
39 int rlen = myReader.read(cbuf, off, len);
\r
41 count+=cbuf.hashCode();
\r
45 * Return current checksum of read bytes.
\r
46 * @return stream checksum
\r
48 public long getChecksum() {
\r
52 * Return existing checksum value and reset
\r
55 public long getAndResetChecksum() {
\r