Uploaded image for project: 'Commons Compress'
  1. Commons Compress
  2. COMPRESS-511

Decompress tar failed. java.io.IOException: Error detected parsing the header

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Not A Bug
    • 1.20
    • None
    • Archivers
    • None

    Description

      public static void main(String args[]) throws Exception {

      //Send the TAR file as an argument
      String tarFileName = args[0];

      /* Read TAR File into TarArchiveInputStream */
      TarArchiveInputStream myTarFile=new TarArchiveInputStream(new FileInputStream(new File(tarFileName)));
      /* To read individual TAR file */
      TarArchiveEntry entry = null;
      String individualFiles;
      int offset;
      FileOutputStream outputFile=null;
      /* Create a loop to read every single entry in TAR file */
      while ((entry = myTarFile.getNextTarEntry()) != null)

      { /* Get the name of the file */ individualFiles = entry.getName(); /* Get Size of the file and create a byte array for the size */ byte[] content = new byte[(int) entry.getSize()]; offset=0; /* Some SOP statements to check progress */ System.out.println("File Name in TAR File is: " + individualFiles); System.out.println("Size of the File is: " + entry.getSize()); System.out.println("Byte Array length: " + content.length); /* Read file from the archive into byte array */ myTarFile.read(content, offset, content.length - offset); /* Define OutputStream for writing the file */ outputFile=new FileOutputStream(new File(individualFiles)); }

       

      I was able to decompress the tar file in the Linux environment using the tar command. Following is the error when I run the code:

       

      [ec2-user@ip-172-31-16-85 src]$ java TarToByteArray.java layer1.tar
      Error: Could not find or load main class TarToByteArray.java
      [ec2-user@ip-172-31-16-85 src]$ java TarToByteArray layer1.tar
      Exception in thread "main" java.io.IOException: Error detected parsing the header
      at org.apache.commons.compress.archivers.tar.TarArchiveInputStream.getNextTarEntry(TarArchiveInputStream.java:371)
      at TarToByteArray.main(TarToByteArray.java:19)
      Caused by: java.lang.IllegalArgumentException: At offset 124, 12 byte binary number exceeds maximum signed long value
      at org.apache.commons.compress.archivers.tar.TarUtils.parseBinaryBigInteger(TarUtils.java:215)
      at org.apache.commons.compress.archivers.tar.TarUtils.parseOctalOrBinary(TarUtils.java:179)
      at org.apache.commons.compress.archivers.tar.TarArchiveEntry.parseTarHeader(TarArchiveEntry.java:1350)
      at org.apache.commons.compress.archivers.tar.TarArchiveEntry.<init>(TarArchiveEntry.java:438)
      at org.apache.commons.compress.archivers.tar.TarArchiveInputStream.getNextTarEntry(TarArchiveInputStream.java:369)
      ... 1 more

       

       

      Also attaching the tar file that I am using!

      Attachments

        1. layer1.tar
          19.24 MB
          Akhila Mangipudi

        Activity

          People

            peterlee Peter Lee
            akhila1012 Akhila Mangipudi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: