The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.util.zip  [9 examples] > Checksums  [2 examples]

e456. Calculating the Checksum of a Byte Array

    byte[] bytes = "some data".getBytes();
    
    // Compute Adler-32 checksum
    Checksum checksumEngine = new Adler32();
    checksumEngine.update(bytes, 0, bytes.length);
    long checksum = checksumEngine.getValue();
    
    // Compute CRC-32 checksum
    checksumEngine = new CRC32();
    checksumEngine.update(bytes, 0, bytes.length);
    checksum = checksumEngine.getValue();
    
    // The checksum engine can be reused again for a different byte array by calling reset()
    checksumEngine.reset();

 Related Examples
e457. Calculating the Checksum of a File

See also: GZIP    ZIP   


© 2002 Addison-Wesley.