PureJavaCrc32 implements Checksum { @Override public void update(final byte[] b, final int offset, final int len) { int localCrc = crc; final int remainder = len & 0x7; int i = offset; for(final int end = offset + len - remainder; i < end; i += 8) { final int x = localCrc ^ ((((b[i ] << 24) >>> 24) + ((b[i+1] << 24) >>> 16)) + (((b[i+2] << 24) >>> 8 ) + (b[i+3] << 24))); localCrc = ((T[((x << 24) >>> 24) + 0x700] ^ T[((x << 16) >>> 24) + 0x600]) ^ (T[((x << 8) >>> 24) + 0x500] ^ T[ (x >>> 24) + 0x400])) ^ ((T[((b[i+4] << 24) >>> 24) + 0x300] ^ T[((b[i+5] << 24) >>> 24) + 0x200]) ^ (T[((b[i+6] << 24) >>> 24) + 0x100] ^ T[((b[i+7] << 24) >>> 24)])); } switch(remainder) { case 7: localCrc = (localCrc >>> 8) ^ T[((localCrc ^ b[i++]) << 24) >>> 24]; case 6: localCrc = (localCrc >>> 8) ^ T[((localCrc ^ b[i++]) << 24) >>> 24]; case 5: localCrc = (localCrc >>> 8) ^ T[((localCrc ^ b[i++]) << 24) >>> 24]; case 4: localCrc = (localCrc >>> 8) ^ T[((localCrc ^ b[i++]) << 24) >>> 24]; case 3: localCrc = (localCrc >>> 8) ^ T[((localCrc ^ b[i++]) << 24) >>> 24]; case 2: localCrc = (localCrc >>> 8) ^ T[((localCrc ^ b[i++]) << 24) >>> 24]; case 1: localCrc = (localCrc >>> 8) ^ T[((localCrc ^ b[i++]) << 24) >>> 24]; default: } crc = localCrc; } PureJavaCrc32(); @Override long getValue(); @Override void reset(); @Override void update(final byte[] b, final int offset, final int len); @Override final void update(int b);  }
@Test public void testCorrectness() throws Exception { checkSame(); theirs.update(104); ours.update(104); checkSame(); checkOnBytes(new byte[] {40, 60, 97, -70}, false); checkOnBytes("hello world!".getBytes("UTF-8"), false); for (int i = 0; i < 10000; i++) { byte randomBytes[] = new byte[new Random().nextInt(2048)]; new Random().nextBytes(randomBytes); checkOnBytes(randomBytes, false); } }