Java compatible cksum function

Is there any library / code in Java to compute a 32-bit CRC byte stream in a way that is consistent with the cksum command on unix?

+7
source share
3 answers

Jacksum: http://www.jonelo.de/java/jacksum/index.html

cksum algorithm: POSIX 1003.2 CRC algorithm length: 32 bits type: crc since: Jacksum 1.0.0 comment: - under BeOS it is /bin/cksum - under FreeBSD it is /usr/bin/cksum - under HP-UX it is /usr/bin/cksum and /usr/bin/sum -p - under IBM AIX it is /usr/bin/cksum - under Linux it is /usr/bin/cksum 

Open source.

+5
source

Have you tried the CRC32 class?

http://download.oracle.com/javase/7/docs/api/java/util/zip/CRC32.html

This is crc 32 that uses gzip.

+2
source

Carlos Randonโ€™s statement: โ€œI can verify that Java CRC32 does not match / usr / bin / cksumโ€ is incorrect.

As Peter Laurie noted, you can use Java CRC32 directly to get the same checksum as Unix / Linux cksum .

The correct way to do this is:

 java.util.zip.CRC32 x = new java.util.zip.CRC32(); x.update(bytes); StdOut.println("CRC32 (via Java library) = " + Long.toHexString(x.getValue())); 

Source: http://introcs.cs.princeton.edu/java/61data/CRC32.java.html

The default CRC used is based on the polynomial used for checking CRC errors in the network standard ISO / IEC 8802-3: 1989.

0
source

All Articles