int c;
ByteBuffer hashset;
MD4 msgDigest = new MD4();
ByteBuffer bb = ByteBuffer.allocateDirect(8192).order(ByteOrder.LITTLE_ENDIAN);
ByteBuffer di = ByteBuffer.allocate(16).order(ByteOrder.LITTLE_ENDIAN);
c = (int) ((fileChannel.size() + PARTSIZE - 1) / PARTSIZE);
// we will need space for c Parts
hashset = ByteBuffer.allocate(16 * (c>0?c:1)).order(ByteOrder.LITTLE_ENDIAN);
for (i = 1; i < c; i++) {
while (position <= (i * PARTSIZE - bb.capacity())) {
if( stop ) return;
position+=fileChannel.read(bb, position);
bb.flip();
msgDigest.update(bb);
bb.rewind();
}
if (position < (i * PARTSIZE)) {
bb.limit((int) ((i * PARTSIZE) - position));
position+=fileChannel.read(bb, position);
bb.flip();
msgDigest.update(bb);
bb.rewind();
}
hashset.limit(16 * i);
//update hashset - add a hash
msgDigest.finalDigest(hashset);
}
if (c > 0) {
while (position < (fileChannel.size())) {
if(stop) return;
position+=fileChannel.read(bb, position);
bb.flip();
msgDigest.update(bb);
bb.rewind();
}
hashset.limit(16 * i);
}
msgDigest.finalDigest(hashset);
hashset.flip();
if (c > 1) {
msgDigest.update(hashset);
msgDigest.finalDigest(di);
} else {
di.put(hashset);