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:
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:
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... (using classes from http://www.trustice.com/java/tar/)");
      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();
}The file I tested with can be found here:
http://www.yourfilehost.com/media.php?cat=other&file=BROKERH_20080303_A2008_S0039.TAR.GZ
Any help? Thanks a bunch.

I fixed the problem. It was the ftp transfer of files program which wasn't set to BINARY mode. I edited that program and then rerun the above class and boom.. It worked.
Thank you guys for responses.Great! Glad you got it working.
~

Similar Messages

  • Extract multiple tar.gz files

    hey people
    I.ve got a problem here. I.ve got a folder with about 100 .tar.gz files, and I want to extract them all with 1 command. How do I do this? "tar zxvf *.tar.gz" doesn.t work...
    cheers

    find . -name "*.tar.gz" -exec tar xvzf {} ;

  • How to extract a .tar.gz file in IBM AIX 6.1

    we are in R12.1.3 on IBM AIX 6.1,we took the cold backup of prod Instance using the below command
    nohup tar cvf - /u01/oracle/prod/db | gzip > /u01/backup/backup_prod/prod_db.tar.gz &
    nohup tar cvf - /u01/oracle/prod/apps | gzip > /u01/backup/backup_prod_8035/prod_apps.tar.gz &
    we tried to extrac the above 2 .tar.gz files on the same server using below commands, they are extracting on source location i.e /u01/oracle/prod/db.so original files getting updated with old one
    cd /u01/backup/backup_prod_8035
    $gunzip < prod_apps.tar.gz | tar xvf -
    $gunzip < prod_db.tar.gz | tar xvf -
    Please let me know how to extract this files in the same folder with out affecting the original files
    Thanks in advance

    Helios,
    Thank you very much for your reply
    Is it possible to do both gzip and tar -xvf in single commnd because we don't have that much space on the server
    when we execute gzip -d /u01/backup/backup_prod/prod_db.tar.gz it will create file as prod_db.tar again we need to execute
    tar -xvf /u01/backup/backup_prod/prod_db.tar
    In the above command either we need to give . to untar the files in the same directory same like Linux.
    With out . in aix the untar files are over riding on source location i.e /u01/erp/prod
    Please advice

  • Extracting tar.bz2 files.

    How can i extract tar.bz2 files?. zip, jar, tar can be extracted within java. But how tar.bz2?.

    Some tars have built-in knowledge of the bz2 (bunzip) compression format.
    Tar ("tape archive") is to package several files in one archive or to extract them. The archive files can be called "*.tar".

  • Jar File for uncompress *.tar.Z-File

    hello,
    i'm locking for a jar -file to uncompress *.tar.Z files but i cant't found souch a jar file.
    do you know where i can download a jar-file wich suppose to extract a *.Z-Archiv? You do you know how i can extract a *.tar.Z-Archiv?
    Torsten

    hello,
    i'm locking for a jar -file to uncompress *.tar.Z files but i cant't found souch a jar file.
    do you know where i can download a jar-file wich suppose to extract a *.Z-Archiv? You do you know how i can extract a *.tar.Z-Archiv?
    Torsten

  • Handling tar.gz files

    Hi all,
    I am looking to get PHP up and running on my Mac I found the PHP modules on http://www.entropy.ch/software/macosx/php/ which was linked directly from php.net.
    The tutorial for installation says NOT to use Stuffit but to use BOMArchiveHelper instead to unpack the installation files.
    I have clicked "get info" on my php-5.2.1.tar.gz file and chose BOMArchiveHelper to open the file.
    Problem is when I double click the file a second archive is created, it is compressing again instead of unpacking!
    Any help with this will be greatly appreciated. A second option could be if you can point out a tutorial for correctly handling any compressed file from the command line.
    Thanks in advance.
    Juan

    Juan:
    Try this. Create a new folder in your desktop (let's say you called it PHP) and put your archive in there. Then open the terminal (in Utilities) and change directories to the new folder:
    cd ~/Desktop/PHP
    Then, extract the archive with
    tar -xzvf php-5.2.1.tar.gz
    That should decompress and unarchive the contents of the "tarball" into the PHP directory. We created the PHP directory only to prevent a potential large number of files loose in your desktop.
    Good luck,
    Juan-Pablo

  • Reading contents of tar.gz file programatically

    Hi,
    I have a file explorer type application, where I want the user to be able to double click on the tar.gz file and see the contents of the tar archive inside the .gz file.
    Of course, we dont want to have to extract the entire .gz file first. But it seems that the only way to read a .gz file is to use GZIPInputStream and if we through that, we will end up extracting the entire file.
    So can anyone tell me how to go about doing this?

    Hi,
    yes you're right. It's quite tricky sometimes to get what you need from a GZip file.
    What I found out today worked greatly.
    First of all, you need to get Apache Ant and inside the ant.jar file you'll locate the TAR package under tools (org.apache.tools.tar)
    So:
    1) Create a GZIPInputStream from the file (java.util.zip.GZIPInputStream)
    2) read the file entirely, coping it using a FileOutputStream
    3) In point 2, you created a tar file, you can read it with TarInputStream in org.apache.tools.tar TarInputStream.
    4) Get the entry you look for with TarEntry using
    - TarInputStream ts = new TarInputStream(file);
    - while (true){
    TarEntry t = ts.getNextEntry();
    if (tgetName().equals("myEntry")){
    //use ts to read this entry
    ts.read (buffer, 0, buffer.length)
    5) You have the unpacked Gzip entry where you want. Enjoy!
    ZazzaZ

  • Creating/Extracting password protected zip files in AIR

    Hello,
    Does any one have any idea about creating/extracting password protected zip files in AIR. I am aware of FZip but it does not has the feature to password protect.
    Any help would be appreciated.
    Thank you
    VinSat

    Here's some you could try. The first two links are to zip utilities for OS X. I can't tell you if they'll do what you need, I just looked for zip programs that work in OS X.
    The third link is for the free Stuffit Expander. The last link is the results for "zip" at VersionTracker. You'll just have to try a bunch of them to find one that hopefully works.
    http://mac.softpedia.com/get/Utilities/MacZi.shtml
    http://www.maczipit.com/download.html
    http://my.smithmicro.com/mac/stuffit/expander.html
    http://www.versiontracker.com/php/qs.php?mode=basic&action=search&str=zip&srchAr ea=macosx&submit=Go

  • Where is the xsqlservlet_v9****.tar.gz file?

    I'm looking to install XSQL Servlet support on Oracle 8.1.7.
    I've just downloaded the latest XDK for Java, since technet
    states the XSQL Servlet components are included in it. After
    uncompressing the download and reviewing the included
    documentation, I expected to find a xsqlserlvet_v9_0_1_0.tar.gz
    file included somewhere in the directory structure. Nope, not
    there...so either:
    (1). The included docs are wrong/outdated - I'm looking
    at "Downloading and Installing the XSQL Servlet".
    (2). My expectation is wrong OR missing an important step.
    (3). I've downloaded the wrong file.
    Any ideas? Thanks.

    Another observation on the release notes included with the
    download...
    In reviewing the section "Software Included in the XSQL Servlet
    Distribution" of the "Oracle XSQL Pages and the XSQL Servlet"
    Release Notes, it mentions the following files:
    .\xsql\lib\xmlparserv2.jar
    .\xsql\lib\xsu12.jar
    .\xsql\lib\classes12.jar
    .\xsql\lib\sax2.jar
    I don't see the .\xsql\lib directory structure in what I
    downloaded??? I see xmlparserv2 and xsu12 in the ./lib
    directory, but classes12 and sax2 are no where to be found.
    I realize I can download classes12 and sax2 from elsewhere, but
    I still have this strange feeling that I'm missing something
    here...

  • How to extract data from dmp file to oracle express edition database

    Hi,
    I wanted to extract a oracle dump file in oracle express edition database. Is it possible? If yes, then can anyone please guide me how to do it?
    Thanks

    Hi,
    This might help
    Backup/Export Question!
    Br,Jari

  • How to extract data from XML file with JavaScript

    HI All
    I am new to this group.
    Can anybody help me regarding XML.
    I want to know How to extract data from XML file with JavaScript.
    And also how to use API for XML
    regards
    Nagaraju

    This is a Java forum.
    JavaScript is something entirely different than Java, even though the names are similar.
    Try another website with forums about JavaScript.
    For example here: http://www.webdeveloper.com/forum/forumdisplay.php?s=&forumid=3

  • Custom batch rename files with Aperture 3 in the following format: IMG_0023.cr2 to Smith_YYMMDD_0023.cr2?  I cannot find a way to structure the date in Aperture as such, as well as extract only the camera file

    Please advise how to custom batch rename files with Aperture 3 in the following format: IMG_0023.cr2 to Smith_120816_0023.cr2?  I cannot find a way to structure the date in Aperture as such (YYMMDD), as well as extract only the camera file (0023, for example).  Adobe Bridge CS5 can do this, but NONE of the Adobe software is retina optimized, and is terrible to look at.

    In Aperture you are limited to renaming files by the entries in the File Naming preset window.
    At what point are you looking to rename, import or export? It might be possible to do what you are looking to do external to Aperture either via a script or other software.
    regards

  • Problem parsing XML with schema when extracted from a jar file

    I am having a problem parsing XML with a schema, both of which are extracted from a jar file. I am using using ZipFile to get InputStream objects for the appropriate ZipEntry objects in the jar file. My XML is encrypted so I decrypt it to a temporary file. I am then attempting to parse the temporary file with the schema using DocumentBuilder.parse.
    I get the following exception:
    org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element '<root element name>'
    This was all working OK before I jarred everything (i.e. when I was using standalone files, rather than InputStreams retrieved from a jar).
    I have output the retrieved XML to a file and compared it with my original source and they are identical.
    I am baffled because the nature of the exception suggests that the schema has been read and parsed correctly but the XML file is not parsing against the schema.
    Any suggestions?
    The code is as follows:
      public void open(File input) throws IOException, CSLXMLException {
        InputStream schema = ZipFileHandler.getResourceAsStream("<jar file name>", "<schema resource name>");
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = null;
        try {
          factory.setNamespaceAware(true);
          factory.setValidating(true);
          factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
          factory.setAttribute(JAXP_SCHEMA_SOURCE, schema);
          builder = factory.newDocumentBuilder();
          builder.setErrorHandler(new CSLXMLParseHandler());
        } catch (Exception builderException) {
          throw new CSLXMLException("Error setting up SAX: " + builderException.toString());
        Document document = null;
        try {
          document = builder.parse(input);
        } catch (SAXException parseException) {
          throw new CSLXMLException(parseException.toString());
        }

    I was originally using getSystemResource, which worked fine until I jarred the application. The problem appears to be that resources returned from a jar file cannot be used in the same way as resources returned directly from the file system. You have to use the ZipFile class (or its JarFile subclass) to locate the ZipEntry in the jar file and then use ZipFile.getInputStream(ZipEntry) to convert this to an InputStream. I have seen example code where an InputStream is used for the JAXP_SCHEMA_SOURCE attribute but, for some reason, this did not work with the InputStream returned by ZipFile.getInputStream. Like you, I have also seen examples that use a URL but they appear to be URL's that point to a file not URL's that point to an entry in a jar file.
    Maybe there is another way around this but writing to a file works and I set use File.deleteOnExit() to ensure things are tidied afterwards.

  • How to un tar required file?

    Hello All,
    I used TAR backup as below.
    tar -cvf test01.tar /uo1/oracle/bin/java
    its created testo1.tar file.
    Now i wanted to untar or recovery only one file instaed of whole tar file.
    for e.g: i wanted to recovery only file under bin folder callled config.
    how to un tar file?
    Any help will be appreciated. Thanks
    D

    You can look inside the tar using the 't' command:
    tar tvf file.tar And you can untar only one file with:
    frits@gateway:~/download$ mkdir t
    frits@gateway:~/download$ cd t
    frits@gateway:~/download/t$ touch a
    frits@gateway:~/download/t$ touch b
    frits@gateway:~/download/t$ tar czf ab.tgz *
    frits@gateway:~/download/t$ ls
    a  ab.tgz  b
    frits@gateway:~/download/t$ tar tzf ab.tgz
    a
    b
    frits@gateway:~/download/t$ rm a
    frits@gateway:~/download/t$ ls
    ab.tgz  b
    frits@gateway:~/download/t$ tar xzf ab.tgz a
    frits@gateway:~/download/t$ ls
    a  ab.tgz  b
    frits@gateway:~/download/t$

  • API extracting keywods from text files

    hi all,
    i will be grateful if any of you can suggest some free java api which can be used to extract keywords from text files.
    thanx in advance
    malls

    java.util.regex - regular expressions API in JDK 1.4

Maybe you are looking for

  • Windows Deployment Services and Windows 8.1 Tablet Autorotation Issue

    Hi, I have been trying to deploy a vanilla Windows 8.1 image to Fujitsu Stylistic Q702 Hybrid Tablet using WDS, however this appears to prevent the automatic screen rotation functionality. When installed from the Windows DVD, automatic rotation is av

  • One of our user accounts no longer loads thru Mail

    For no reason I can ascertain, the Inbox is greyed out in Mail, and only one user (myself, the main user) is black and will load mail. This account works normally. However my husband's "mail only" sub-user account is greyed out, displays the "~" and

  • Missing tools in Illustrator cs4

    hey, This problem is driving me crazy. I have Adobe Illustrator cs4 installed (win.Vista), it runs o.k but I'm missing a lot of tools- I get all the main tool groups but the groups wont open` so I have the line tool but not arc or spiral, I have warp

  • How we make time table in SAP?

    Hi Experts If i am going to implement SAP HCM in any college or University and I want to make a format of daily time table, examination detail, mark sheets and degree. So how we can do this?  And also how Payroll is different from the other organizat

  • Inter company purchase order

    Hi guru's I am a PP guy and new to MM. I am not getting the shipping details( shipping tab) in the purchase order. I am creating a inter company purchase order and i am not getting the shipping view for only one plant. I have copied that plant from a