java.util.zip.CRC32.update() Method Example



Description

The java.util.zip.CRC32.update(byte[] b) method updates the checksum with the specified array of bytes.

Declaration

Following is the declaration for java.util.zip.CRC32.update(byte[] b) method.

public void update(byte[] b)

Parameters

  • b − the byte array to update the checksum with.

Example

The following example shows the usage of java.util.zip.CRC32.update(byte[] b) method.

package com.tutorialspoint;

import java.util.zip.CRC32;

public class CRC32Demo {

   public static void main(String[] args) {
      String message = "Welcome to Tutorialspoint.com";
      byte bytes[] = message.getBytes();

      CRC32 checksum = new CRC32();
      checksum.reset();       

      checksum.update(bytes);
      long checksumValue = checksum.getValue();

      System.out.println("CRC32 checksum :" + checksumValue);
   }
}

Let us compile and run the above program, this will produce the following result −

CRC32 checksum :1734172551
javazip_crc32.htm
Advertisements