+++ /dev/null
-/**\r
- * \r
- */\r
-package uk.ac.vamsas.client.utils;\r
-\r
-import java.io.IOException;\r
-import java.io.Reader;\r
-\r
-/**\r
- * @author JimP\r
- * Simple wrapper for reader to keep track of position in stream.\r
- * This is used in the document unmarshalling mechanism to compute\r
- * a simple hash based on the distance between the read blocks containing\r
- * the start and end tags of the XML.\r
- */\r
-public class ChecksummedReader extends Reader {\r
- private Reader myReader=null;\r
- private long count=0;\r
- public ChecksummedReader(Reader myReader) {\r
- super();\r
- this.myReader = myReader;\r
- count=0;\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see java.io.Reader#close()\r
- */\r
- public void close() throws IOException {\r
- if (myReader!=null)\r
- myReader.close();\r
- else\r
- throw new IOException("Close called on un-inited ChecksummedReader");\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see java.io.Reader#read(char[], int, int)\r
- */\r
- public int read(char[] cbuf, int off, int len) throws IOException {\r
- int rlen = myReader.read(cbuf, off, len);\r
- if (rlen>0)\r
- count+=cbuf.hashCode();\r
- return rlen;\r
- }\r
- /**\r
- * Return current checksum of read bytes.\r
- * @return stream checksum\r
- */\r
- public long getChecksum() {\r
- return count;\r
- }\r
- /**\r
- * Return existing checksum value and reset\r
- * @return old count\r
- */\r
- public long getAndResetChecksum() {\r
- long cnt=count;\r
- count=0;\r
- return cnt;\r
- }\r
-}\r