Tag Archives: CRC

java.util.zip.CRC32 and java.util.zip.Adler32 performance

by Mikhail Vorontsov

Checksum is a function from an arbitrary size input byte array to a small number of bytes (integer in case of CRC32 and Adler32). Its most important property is that a small change in the input data (even one byte is increased by one) means a large change in the checksum. Checksums are usually calculated in one of two following scenarios:

  • A file was received with a separately received checksum. We need to calculate a checksum on the file contents and compare it with the received checksum to ensure that the file was not changed during transmission.
  • A file is being read from an input device and a checksum is being calculated on its contents. Partial file contents are being somehow processed. In some occasions connection with the input device may be broken and retransmission is required. We may use the last calculated checksum and its file position in order to check that the same data is being received during retransmission until the last known file position in order not to reprocess the retransmitted file and continue processing after that position.

The most well-known checksum implementation from standard JDK is java.util.zip.CRC32. A lot of developers think that it is the only standard checksum implementation (a lot of them would tell ‘standard CRC implementation’). Actually, there is one more checksum implementation called java.util.zip.Adler32. Both CRC32 and Adler32 implement the same interface – java.util.zip.Checksum.

Continue reading