In this tutorial you will see how to use update and reset method of CRC32.
In this tutorial you will see how to use update and reset method of CRC32.In this example, you will see how to update the CRC32 checksum. The FileInputStream class create
input
stream for reading bytes from file. The read() method of FileInputStream
class read bytes from
this input stream and store it into a array of bytes. ThegetValue() method
of the CRC32 class returns
the value of checksum. The update(byte[]
buffer, int offset, int length) method
of the CRC32 class
update the value of checksum with array of bytes, and
the reset() method
of the CRC32 class reset
the checksum value with initial value.
About Adler32 API:
The java.util.zip.Adler32 class extends java.lang.Object class. It provide following methods:
Return Type | Method | Description |
checksum | getValue() | The getValue() method returns value of checksum. |
void | update(byte[] buff, int offset, int length) | The update() method update checksum with array of bytes. |
void | reset() | The reset() method reset the checksum value at initial value. |
import java.util.zip.CRC32;
|
C:\>java CrcCheckSum Initial value of CRC32 checkSum :0 After updating the value of CRC32 checksum : 2141301436 Value of CRC32 CheckSum after reset :0 |
Download this code