📅  最后修改于: 2023-12-03 15:01:35.637000             🧑  作者: Mango
The java.util.zip.CRC32
class in Java provides methods to compute cyclic redundancy checks (CRC) for data streams. It is widely used for data integrity checks, error detection, and data validation.
public class CRC32 extends Object implements Checksum
graph TD
CRC32 --> Object
Checksum -->|implemented by| CRC32
update(byte[] b)
This method updates the checksum with the bytes from the specified byte array. The bytes are read starting from the current position of the array and up to its length.
public void update(byte[] b)
update(byte[] b, int off, int len)
This method updates the checksum with the bytes from the specified byte array. The bytes are read starting from the specified offset and up to the specified length.
public void update(byte[] b, int off, int len)
update(int b)
This method updates the checksum with the specified byte.
public void update(int b)
getValue()
This method returns the current value of the checksum.
public long getValue()
reset()
This method resets the checksum to its initial value.
public void reset()
import java.util.zip.CRC32;
public class CRC32Example {
public static void main(String[] args) {
byte[] bytes = "Lorem ipsum dolor sit amet".getBytes();
CRC32 crc32 = new CRC32();
crc32.update(bytes);
System.out.println("CRC32 checksum: " + crc32.getValue());
}
}
Output:
CRC32 checksum: 1075730289
The java.util.zip.CRC32
class in Java provides easy-to-use methods for computing cyclic redundancy checks for data streams. It offers a convenient way of detecting errors and ensuring data integrity.