validation - Java: Validate a TAR file -


is possible validate tar file in java can sure other tar utilities (i.e unix tar command) can extract tar? in code , not resort executing tar -tf application , report based on return code.

i have been using apache commons compress read through tars entries (not extract them). have manually modified of tar using text editor represent "corrupt" tar file. commons compress doesn't fail read entries unix tar command or 7zip have failed consistently no matter modify. more needs done ensure tar file not corrupt, it?

note: haven't tried extract tar via commons compress means of validation. don't think option; tar file sizes have work large (3 4 gigs) , rather not see process take longer does.

since don't want execute tar command, use org.apache.tools.tar.tarinputstream implementation of apache ant.

personaly, have not tried , i'm not expert in tar file format, try iterating on tar file using getnextentry method. assuming once you're done without error/exception, have (somewhat) proven tar file "valid".

update: above wikipedia page lists java implementations:

jtar includes example untaring tar file, guess, modified "test" archive.

   string tarfile = "c:/test/test.tar";     // create tarinputstream    tarinputstream tis = new tarinputstream(new bufferedinputstream(new fileinputstream(tarfile)));    tarentry entry;    while((entry = tis.getnextentry()) != null) {        system.out.println(entry.getname());        // following might not required, arguably        // additionally check content of archive.       int count;       byte data[] = new byte[2048];        while((count = tis.read(data)) != -1) {       }    }     tis.close(); 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -