Hello,
Iam looking for how to validate a zip file in java, I tried for that, to use
java.sun.com / j2se / 1.4.2 / docs / ap i/ java / util / zip / CheckedInputStream.html , and in the definition of this class, it is said in the documentation :
|
Quote:
|
|
An input stream that also maintains a checksum of the data being read. The checksum can then be used to verify the integrity of the input data.
|
.
I tried this code
|
Code:
|
public class Checksumoffile
{
public static void Checkyourfiles(String strfilename)
{
long checksum=0;
try {
// Compute Adler-32 checksum
CheckedInputStream cis = new CheckedInputStream(
new FileInputStream(strfilename), new Adler32());
byte[] tempBuf = new byte[128];
while (cis.read(tempBuf) >= 0) {
}
checksum = cis.getChecksum().getValue();
} catch (IOException e) {
}
System.out.println("The checksum of file is : " + checksum);
} |
Called by this code
|
Quote:
|
public static void main(String[] args) {
// TODO Auto-generated method stub
try
{
Checksumoffile.Checkyourfiles(TestStringTokenizing .strchemin2+"/TestHeadFirsts2.zip");
}
catch(Exception exop)
{
System.out.println("Problem using your zip "+ exop.getMessage());
}
|
I obtained a checksum = 0 in all cases, even when I have tried with a validate file, and a corrupt file.
I think there is a problem for me, either my code is wrong, or I did not understand what
checksum and
Integrity mean. Do Checksum and Integrity mean the same think ? Are they different ?
I use the almanac java developers 'example availlable here = exampledepot. com / egs / java.util.zip / ChecksumFile.html
Thx for any help.
PS: Despite the fact that I posted two links for the first post, I am not a spammer, Iam a java developper, if I put these two links, this is for a purpose to illustrate, and documented my message. I used to post in several java forum as developpez. com, and java.net forum, Glassfish topic