Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-10-2008, 04:55 PM
Member
 
Join Date: May 2008
Posts: 4
sajdutt is on a distinguished road
Extract A tar.gz file
Ok guys,

I have a program that extracts the contents of a tar.gz file. Right now it does extract one of the files and then throws an error:

Code:
com.ice.tar.InvalidHeaderException: bad header in block 9 record 10, header magi c is not 'ustar' or unix-style zeros, it is '1141115144674854', or (dec) 114, 11 1, 51, 44, 67, 48, 54 at com.ice.tar.TarInputStream.getNextEntry(Unknown Source) at Extract_TAR_GZ_FILE.untar(Extract_TAR_GZ_FILE.java:37) at Extract_TAR_GZ_FILE.run(Extract_TAR_GZ_FILE.java:55) at Extract_TAR_GZ_FILE.main(Extract_TAR_GZ_FILE.java:67) bad header in block 9 record 10, header magic is not 'ustar' or unix-style zeros , it is '1141115144674854', or (dec) 114, 111, 51, 44, 67, 48, 54
The class that extracts the files:

Code:
import java.io.*; import com.ice.tar.*; import javax.activation.*; import java.util.zip.GZIPInputStream; public class Extract_TAR_GZ_FILE { public static InputStream getInputStream(String tarFileName) throws Exception{ if(tarFileName.substring(tarFileName.lastIndexOf(".") + 1, tarFileName.lastIndexOf(".") + 3).equalsIgnoreCase("gz")){ System.out.println("Creating an GZIPInputStream for the file"); return new GZIPInputStream(new FileInputStream(new File(tarFileName))); }else{ System.out.println("Creating an InputStream for the file"); return new FileInputStream(new File(tarFileName)); } } private static void untar(InputStream in, String untarDir) throws IOException { System.out.println("Reading TarInputStream... "); TarInputStream tin = new TarInputStream(in); TarEntry tarEntry = tin.getNextEntry(); if(new File(untarDir).exists()){ while (tarEntry != null){ File destPath = new File(untarDir + File.separatorChar + tarEntry.getName()); System.out.println("Processing " + destPath.getAbsoluteFile()); if(!tarEntry.isDirectory()){ FileOutputStream fout = new FileOutputStream(destPath); tin.copyEntryContents(fout); fout.close(); }else{ destPath.mkdir(); } tarEntry = tin.getNextEntry(); } tin.close(); }else{ System.out.println("That destination directory doesn't exist! " + untarDir); } } private void run(){ try { String strSourceFile = "G:/source/BROKERH_20080303_A2008_S0039.TAR.GZ"; String strDest = "G:/source/Extracted Files"; InputStream in = getInputStream(strSourceFile); untar(in, strDest); }catch(Exception e) { e.printStackTrace(); System.out.println(e.getMessage()); } } public static void main(String[] strArgs) throws IOException{ new Extract_TAR_GZ_FILE().run(); } }
com.ice.tar package can be found at:
trustice.com/java/tar/

The file I tested with can be found here:
yourfilehost.com/media.php?cat=other&file=BROKERH_20080303_A2008_S0 039.TAR.GZ

Any help? Thanks a bunch.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-10-2008, 06:38 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Gone to Costa Rica
Posts: 2,223
Norm is on a distinguished road
Quote:
com.ice.tar.InvalidHeaderException: bad header in block 9 record 10, header magic is not 'ustar' or unix-style zeros, it is '1141115144674854', or (dec) 114, 11
1, 51, 44, 67, 48, 54
It seems that the com.ice.tar program doesn't like the file for the stated reasons. Can other programs read the file OK? Can your program read other tar.gz files ok? Ie is it just this one file that is a problem.
Who wrote the program that is giving the error? Can you ask them the question?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-11-2008, 09:37 AM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 462
fishtoprecords is on a distinguished road
Debugging hint: separate your problem.
Write one program to convert the tar.gz to a .tar
and then write another program using the TarInputStream to read the file.

Manually verify that your unGZ works by using stand alone tar. Make sure that works.
Then feed the .tar file to your second program.

Problem isolation is the key to all debugging
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


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

vB 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
Extract xml to store into db palanikumark Advanced Java 3 06-06-2008 05:09 PM
[SOLVED] How to Extract Data From this text file? jazz2k8 New To Java 31 04-18-2008 12:45 PM
Extract Interface (I) JavaForums Java Blogs 0 03-12-2008 12:40 AM
Extract superclass(II) JavaForums Java Blogs 0 03-12-2008 12:40 AM
Extract Text from PDF File using java TSW1016 Advanced Java 5 01-07-2008 01:03 AM


All times are GMT +3. The time now is 04:26 PM.


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