I am not sure if I got the concept right, but I know that we can verify that the integrity of the files in a zip by getting the CRC values for each entry. However, my question is if I get a zip file, will there be a CRC for it and if so how can I determine that ?
A CRC error indicates that some data in your Zip file (. zip or . zipx) is damaged. CRC stands for "cyclic redundancy check".
Right-click the file you wish to get the CRC-32 for. A context menu appears. Select the CRC SHA submenu entry. Select any of the available algorithms: CRC-32, CRC-64, SHA-1 or SHA-256 to calculate the respective checksum, or select "*" to calculate all of them and additionally BLAKE2sp.
The CRC-32 of the ZIP is the calculation of all the bytes (0-13) before, no?
You can use java.util.zip.CRC32
to compute CRC-32 checksum for any data stream.
BufferedInputStream bis = new BufferedInputStream(
new FileInputStream(new File("/path/to/file.zip")));
int read = 0;
CRC32 checksum = new CRC32();
byte[] buffer = new byte[1024];
while ((read = bis.read(buffer)) != -1) {
checksum.update(buffer, 0, read);
}
bis.close();
System.out.println ("CRC32 of your zip is: " + checksum.getValue());
You can use the checksumCRC32
method from the FileUtils
class in org.apache.commons.io
package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With