Java : CRC32 con ejemplos
CRC32 (Java SE 23 & JDK 23) en Java con ejemplos.
Encontrará muestras de código para la mayoría de los métodos CRC32.
Nota :
- Este artículo puede utilizar software de traducción para su comodidad. Consulte también la versión original en inglés.
Summary
Una clase que se puede utilizar para calcular el CRC-32 de un flujo de datos. (Traducción automática)
final byte[] b = "abcd".getBytes();
System.out.println(Arrays.toString(b)); // [97, 98, 99, 100]
final var checksum = new CRC32();
checksum.update(b);
System.out.printf("%x%n", checksum.getValue()); // ed82cd11
Constructors
CRC32 ()
Crea un nuevo objeto CRC32. (Traducción automática)
final var checksum = new CRC32();
System.out.printf("%x%n", checksum.getValue()); // 0
checksum.update(123);
System.out.printf("%x%n", checksum.getValue()); // 15d54739
Methods
long getValue ()
Devuelve el valor CRC-32. (Traducción automática)
final var b = "abcd".getBytes();
System.out.println(Arrays.toString(b)); // [97, 98, 99, 100]
final var checksum = new CRC32();
checksum.update(b);
System.out.printf("%x%n", checksum.getValue()); // ed82cd11
final var checksum = new CRC32();
checksum.update(97);
System.out.printf("%x%n", checksum.getValue()); // e8b7be43
checksum.update(98);
System.out.printf("%x%n", checksum.getValue()); // 9e83486d
checksum.update(99);
System.out.printf("%x%n", checksum.getValue()); // 352441c2
checksum.update(100);
System.out.printf("%x%n", checksum.getValue()); // ed82cd11
void reset ()
Restablece CRC-32 al valor inicial. (Traducción automática)
final var checksum = new CRC32();
System.out.printf("%x%n", checksum.getValue()); // 0
checksum.update("abcd".getBytes());
System.out.printf("%x%n", checksum.getValue()); // ed82cd11
checksum.reset();
System.out.printf("%x%n", checksum.getValue()); // 0
void update (byte[] b, int off, int len)
Actualiza la suma de comprobación CRC-32 con la matriz de bytes especificada. (Traducción automática)
final var b = "abcdXYZ".getBytes();
System.out.println(Arrays.toString(b)); // [97, 98, 99, 100, 88, 89, 90]
final var checksum = new CRC32();
checksum.update(b, 0, 4);
System.out.printf("%x%n", checksum.getValue()); // ed82cd11
checksum.reset();
checksum.update(b, 4, 3);
System.out.printf("%x%n", checksum.getValue()); // 7d29f8ed
final var checksum = new CRC32();
checksum.update("abcd".getBytes());
System.out.printf("%x%n", checksum.getValue()); // ed82cd11
checksum.reset();
checksum.update("XYZ".getBytes());
System.out.printf("%x%n", checksum.getValue()); // 7d29f8ed
void update (int b)
Actualiza la suma de comprobación CRC-32 con el byte especificado (los ocho bits inferiores del argumento b). (Traducción automática)
final var b = "abcd".getBytes();
System.out.println(Arrays.toString(b)); // [97, 98, 99, 100]
final var checksum = new CRC32();
checksum.update(b);
System.out.printf("%x%n", checksum.getValue()); // ed82cd11
final var checksum = new CRC32();
checksum.update(97);
System.out.printf("%x%n", checksum.getValue()); // e8b7be43
checksum.update(98);
System.out.printf("%x%n", checksum.getValue()); // 9e83486d
checksum.update(99);
System.out.printf("%x%n", checksum.getValue()); // 352441c2
checksum.update(100);
System.out.printf("%x%n", checksum.getValue()); // ed82cd11
void update (ByteBuffer buffer)
Actualiza la suma de comprobación CRC-32 con los bytes del búfer especificado. (Traducción automática)
final var buffer = ByteBuffer.wrap("abcd".getBytes());
System.out.println(buffer); // java.nio.HeapByteBuffer[pos=0 lim=4 cap=4]
final var checksum = new CRC32();
checksum.update(buffer);
System.out.printf("%x%n", checksum.getValue()); // ed82cd11
System.out.println(buffer); // java.nio.HeapByteBuffer[pos=4 lim=4 cap=4]