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

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

    Java 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.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,619
    Rep Power
    23

    Default

    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?

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

    Default

    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
    Posts
    1
    Rep Power
    0

    Smile pls use gzip extract .tar.gz first

    pls use gzip(java.util.zip) extract .tar.gz first first, and then extract tar file by com.ice.tar

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
  •