private static void validateDataHandler(int expTotal, DataHandler dh)
throws IOException {
// readOnce() doesn't store attachment on the disk in some cases
// for e.g when only one attachment is in the message
StreamingDataHandler sdh = (StreamingDataHandler)dh;
InputStream in = sdh.readOnce();
byte[] buf = new byte[8192];
int total = 0;
int len;
while((len=in.read(buf, 0, buf.length)) != -1) {
for(int i=0; i < len; i++) {
if ((byte)('A'+(total+i)%26) != buf[i]) {
System.out.println("FAIL: DataHandler data is different");
}
}
total += len;
if (total%(8192*250) == 0) {
System.out.println("Total so far="+total);
}
}
System.out.println("Total Received="+total);
if (total != expTotal) {
System.out.println("FAIL: DataHandler data size is different. Expected="+expTotal+" Got="+total);
}
in.close();
sdh.close();
}