Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-10-2009, 11:19 AM
Member
 
Join Date: Jul 2009
Posts: 2
Rep Power: 0
peuplier is on a distinguished road
Default Validate a Zip file with java
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

Last edited by peuplier; 07-10-2009 at 11:21 AM.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 07-10-2009, 11:07 PM
angryboy's Avatar
Senior Member
 
Join Date: Jan 2009
Location: Javaland
Posts: 743
Rep Power: 2
angryboy is on a distinguished road
Default
seems to work unless file is not found. then checksum = 0.

what's this?
Checksumoffile.Checkyourfiles(TestStringTokenizing .strchemin2+"/TestHeadFirsts2.zip");
__________________
USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to parse the CSV(Comma separation values)file and validate the file using java padmajap13 Advanced Java 7 05-23-2008 04:46 AM
How to validate date using SampleDateFormat Java Tip java.text 0 04-04-2008 03:38 PM
repaint validate doLayout Gajesh Tripathi AWT / Swing 1 10-27-2007 07:53 PM
how to validate a xml file with schemas via SAX oregon XML 3 08-01-2007 06:15 PM
validate hex character paul New To Java 1 07-25-2007 10:08 PM


All times are GMT +2. The time now is 12:28 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org