Package org.apache.commons.compress.archivers.tar

Examples of org.apache.commons.compress.archivers.tar.TarArchiveInputStream


        is.close();
    }

    public void testTarBzip2() throws Exception {
        File file = new File("src/test/resources/bla.tar.bz2");
        final TarArchiveInputStream is = new TarArchiveInputStream(new BZip2CompressorInputStream(new FileInputStream(file)));
        final TarArchiveEntry entry = (TarArchiveEntry)is.getNextEntry();
        assertNotNull(entry);
        assertEquals("test1.xml", entry.getName());
        is.close();
    }
View Full Code Here


      ArchiveInputStream input;
   
            /* I am really sad that classes aren't first-class objects in
               Java :'( */
      try {
        input = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(file)));
      } catch (IOException e) {
        try {
          input = new TarArchiveInputStream(new BZip2CompressorInputStream(new FileInputStream(file)));
        } catch (IOException e2) {
          input = new ZipArchiveInputStream(new FileInputStream(file));
        }
      }

View Full Code Here

        }
        if (ZIP.equalsIgnoreCase(archiverName)) {
            return new ZipArchiveInputStream(in);
        }
        if (TAR.equalsIgnoreCase(archiverName)) {
            return new TarArchiveInputStream(in);
        }
        if (JAR.equalsIgnoreCase(archiverName)) {
            return new JarArchiveInputStream(in);
        }
        if (CPIO.equalsIgnoreCase(archiverName)) {
View Full Code Here

            final byte[] tarheader = new byte[512];
            in.mark(tarheader.length);
            signatureLength = in.read(tarheader);
            in.reset();
            if (TarArchiveInputStream.matches(tarheader, signatureLength)) {
                return new TarArchiveInputStream(in);
            }
        } catch (IOException e) {
            throw new ArchiveException("Could not use reset and mark operations.", e);
        }
View Full Code Here

  }
 
  private static void unTarUsingJava(File inFile, File untarDir,
      boolean gzipped) throws IOException {
    InputStream inputStream = null;
    TarArchiveInputStream tis = null;
    try {
      if (gzipped) {
        inputStream = new BufferedInputStream(new GZIPInputStream(
            new FileInputStream(inFile)));
      } else {
        inputStream = new BufferedInputStream(new FileInputStream(inFile));
      }

      tis = new TarArchiveInputStream(inputStream);

      for (TarArchiveEntry entry = tis.getNextTarEntry(); entry != null;) {
        unpackEntries(tis, entry, untarDir);
        entry = tis.getNextTarEntry();
      }
    } finally {
      IOUtils.cleanup(LOG, tis, inputStream);
    }
  }
View Full Code Here

        }
        if (ZIP.equalsIgnoreCase(archiverName)) {
            return new ZipArchiveInputStream(in);
        }
        if (TAR.equalsIgnoreCase(archiverName)) {
            return new TarArchiveInputStream(in);
        }
        if (JAR.equalsIgnoreCase(archiverName)) {
            return new JarArchiveInputStream(in);
        }
        if (CPIO.equalsIgnoreCase(archiverName)) {
View Full Code Here

            final byte[] tarheader = new byte[512];
            in.mark(tarheader.length);
            signatureLength = in.read(tarheader);
            in.reset();
            if (TarArchiveInputStream.matches(tarheader, signatureLength)) {
                return new TarArchiveInputStream(in);
            }
            // COMPRESS-117 - improve auto-recognition
            if (signatureLength >= 512) {
                try {
                    TarArchiveInputStream tais = new TarArchiveInputStream(new ByteArrayInputStream(tarheader));
                    tais.getNextEntry();
                    return new TarArchiveInputStream(in);
                } catch (Exception e) { // NOPMD
                    // can generate IllegalArgumentException as well
                    // as IOException
                    // autodetection, simply not a TAR
                    // ignored
View Full Code Here

      org.apache.commons.compress.utils.IOUtils.copy(input, fos);
     
      IOUtils.closeQuietly(input);
      IOUtils.closeQuietly(fos);
     
      TarArchiveInputStream tis = new TarArchiveInputStream(new FileInputStream(s));

      for(TarArchiveEntry entry=tis.getNextTarEntry(); entry!=null;)
      {
        if(entry.isDirectory())
        {
          // works here, but is generally speaking a hack; we are assuming here that this is not a TAR bomb (no single root directory)
          String d = outputDir + File.separator + entry.getName();
         
          if(new File(d).getParentFile().equals(outputDir))
          {
            root = d;
          }
        }

        unpackEntries(tis, entry, outputDir);
       
        entry = tis.getNextTarEntry();
      }
    }
    catch (Exception e)
    {
      e.printStackTrace();
View Full Code Here

            else if (MT_AR.equals(type)) {
                final ArchiveInputStream archiveStream = new ArArchiveInputStream(bufferedResourceStream);
                importDataArchive(archive, archiveStream, options);
            }
            else if (MT_TAR.equals(type)) {
                final ArchiveInputStream archiveStream = new TarArchiveInputStream(bufferedResourceStream);
                importDataArchive(archive, archiveStream, options);
            }
            else if (MT_BZIP2.equals(type)) {
                final CompressorInputStream compressedStream = new BZip2CompressorInputStream(bufferedResourceStream);
                importDataArchive(archive, compressedStream, options);
View Full Code Here

            ArchiveInputStream input;

            /* I am really sad that classes aren't first-class objects in
               Java :'( */
            try {
                input = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(file)));
            } catch (IOException e) {
                try {
                    input = new TarArchiveInputStream(new BZip2CompressorInputStream(new FileInputStream(file)));
                } catch (IOException e2) {
                    input = new ZipArchiveInputStream(new FileInputStream(file));
                }
            }

View Full Code Here

TOP

Related Classes of org.apache.commons.compress.archivers.tar.TarArchiveInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.