Results 1 to 4 of 4
  1. #1
    sajdutt is offline Member
    Join Date
    May 2008
    Rep Power

    Default 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:

    Java Code: 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 Source)
            at Extract_TAR_GZ_FILE.untar(
            at Extract_TAR_GZ_FILE.main(
    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:

    Java Code:
    import javax.activation.*;
    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)));
             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());
    	            FileOutputStream fout = new FileOutputStream(destPath);
    	         tarEntry = tin.getNextEntry();
             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) {
    	public static void main(String[] strArgs) throws IOException{
    		new Extract_TAR_GZ_FILE().run();
    } package can be found at:

    The file I tested with can be found here: 039.TAR.GZ

    Any help? Thanks a bunch.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default 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 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?

  3. #3
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Rep Power


    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

  4. #4
    jackmsn001 is offline Member
    Join Date
    Mar 2009
    Rep Power

    Smile pls use gzip extract .tar.gz first

    pls use gzip( extract .tar.gz first first, and then extract tar file by

Similar Threads

  1. Extract xml to store into db
    By palanikumark in forum Advanced Java
    Replies: 3
    Last Post: 06-06-2008, 03:09 PM
  2. [SOLVED] How to Extract Data From this text file?
    By jazz2k8 in forum New To Java
    Replies: 31
    Last Post: 04-18-2008, 10:45 AM
  3. Extract Text from PDF File using java
    By TSW1016 in forum Advanced Java
    Replies: 5
    Last Post: 01-06-2008, 11:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts