Results 1 to 4 of 4
Thread: Extract A tar.gz file
- 07-10-2008, 02:55 PM #1
Member
- Join Date
- May 2008
- Posts
- 4
- Rep Power
- 0
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:
The class that extracts the files: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
com.ice.tar package can be found at: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(); } }
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.
- 07-10-2008, 04:38 PM #2
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.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
Who wrote the program that is giving the error? Can you ask them the question?
- 07-11-2008, 07:37 AM #3
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
- 03-03-2009, 09:29 AM #4
Member
- Join Date
- Mar 2009
- Posts
- 1
- Rep Power
- 0
Similar Threads
-
Extract xml to store into db
By palanikumark in forum Advanced JavaReplies: 3Last Post: 06-06-2008, 03:09 PM -
[SOLVED] How to Extract Data From this text file?
By jazz2k8 in forum New To JavaReplies: 31Last Post: 04-18-2008, 10:45 AM -
Extract Text from PDF File using java
By TSW1016 in forum Advanced JavaReplies: 5Last Post: 01-06-2008, 11:03 PM


LinkBack URL
About LinkBacks

Bookmarks