|
Java™ by example!
|
|
|
How do I calculate the checksum of a byte array using CRC32?
Use the CRC32 class in the java.util.zip package. It contains an implementation of an algorithm to calculate the checksum of a set of bytes. It is slighly slower than Adler32, a class with the same purpose, but it generates a better result. The procedure is simple: create an instance of the CRC32 class, call its method update and provide it with a set of bytes in the order as they appear in the stream. If all bytes have been processed, call getValue to get the checksum as a String. If you need to calculate checksums of several bytestreams, you can reuse the CRC32 instance but you need to call reset in order to reset it to its original state. Following example displays a checksum of a file provided at command line. Main.java:
Further Information
Author of answer: Joris Van den Bogaert
Comments to this answer are only viewable by members. Login or become a member!
|
|
|
|
|