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

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


                return new ZipArchiveInputStream(in);
            }
        }
        if (TAR.equalsIgnoreCase(archiverName)) {
            if (entryEncoding != null) {
                return new TarArchiveInputStream(in, entryEncoding);
            } else {
                return new TarArchiveInputStream(in);
            }
        }
        if (JAR.equalsIgnoreCase(archiverName)) {
            return new JarArchiveInputStream(in);
        }
View Full Code Here


            in.mark(tarheader.length);
            signatureLength = IOUtils.readFully(in, tarheader);
            in.reset();
            if (TarArchiveInputStream.matches(tarheader, signatureLength)) {
                if (entryEncoding != null) {
                    return new TarArchiveInputStream(in, entryEncoding);
                } else {
                    return new TarArchiveInputStream(in);
                }
            }
            // COMPRESS-117 - improve auto-recognition
            if (signatureLength >= 512) {
                TarArchiveInputStream tais = null;
                try {
                    tais = new TarArchiveInputStream(new ByteArrayInputStream(tarheader));
                    // COMPRESS-191 - verify the header checksum
                    if (tais.getNextTarEntry().isCheckSumOK()) {
                        return new TarArchiveInputStream(in);
                    }
                } catch (Exception e) { // NOPMD
                    // can generate IllegalArgumentException as well
                    // as IOException
                    // autodetection, simply not a TAR
View Full Code Here

                is = new BZip2CompressorInputStream(is);
            } else {
                throw new IllegalStateException("Unsupported compression format " + archiveFormat + "!. "
                                                + "Please report this to stanbol-dev mailing list!");
            }
            ais = new TarArchiveInputStream(is);
        }
        return ais;
    }
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

    }
 
    @Override
    protected Sequence processCompressedData(BinaryValue compressedData) throws XPathException, XMLDBException
    {
        TarArchiveInputStream tis = null;
        try
        {
            tis = new TarArchiveInputStream(compressedData.getInputStream());
            TarArchiveEntry entry = null;

            Sequence results = new ValueSequence();

            while((entry = tis.getNextTarEntry()) != null)
            {
                Sequence processCompressedEntryResults = processCompressedEntry(entry.getName(), entry.isDirectory(), tis, filterParam, storeParam);

                results.addAll(processCompressedEntryResults);
            }

            return results;
        }
        catch(IOException ioe)
        {
            LOG.error(ioe.getMessage(), ioe);
            throw new XPathException(this, ioe.getMessage(), ioe);
        }
        finally
        {
            if(tis != null)
            {
                try
                {
                    tis.close();
                }
                catch(IOException ioe)
                {
                    LOG.warn(ioe.getMessage(), ioe);
                }
View Full Code Here

            extractArchive(in, destination);
        }
    }

    public static void extractTarGzip(File file, File destinaton) throws IOException {
        try (final TarArchiveInputStream in = new TarArchiveInputStream(new GZIPInputStream(new FileInputStream(file)))) {
            extractArchive(in, destinaton);
        }
    }
View Full Code Here

        ));

        final File packageDir = temporaryFolder.newFolder();
        ArchiveUtils.extractAr(debFile, packageDir);

        try (final TarArchiveInputStream in = new TarArchiveInputStream(new GZIPInputStream(new FileInputStream(new File(packageDir, "data.tar.gz"))))) {
            final TarArchiveEntry entry = in.getNextTarEntry();
            assertEquals("./test.txt", entry.getName());
            assertEquals(USER, entry.getUserName());
            assertEquals(USER, entry.getGroupName());
            assertEquals(0764, entry.getMode());
        }
View Full Code Here

        if (!input.canRead()) throw new FileNotFoundException("cannot find input "+input);

        System.out.println("unpacking db to "+targetDir);

        TarArchiveEntry entry;
        try (TarArchiveInputStream tis = new TarArchiveInputStream(
                new BZip2CompressorInputStream(
                        new FileInputStream(input))
        )) {
            while ((entry = tis.getNextTarEntry()) != null) {
                File file = new File(targetDir.getParentFile(), entry.getName());
                if (entry.isDirectory()) {
                    if (!file.exists()) assert(file.mkdirs());
                } else if (entry.isFile()) {
                    if (!file.getParentFile().exists()) assert (file.getParentFile().mkdirs());
                    long readBytes = 0;
                    byte[] buffer = new byte[8192];
                    try (FileOutputStream fos = new FileOutputStream(file)) {
                        int n;
                        while (readBytes < entry.getSize()) {
                            n = tis.read(buffer, 0, (int) Math.min(entry.getSize() - readBytes, buffer.length));
                            if (n == -1) {
                                break;
                            }
                            fos.write(buffer, 0, n);
                            readBytes += n;
View Full Code Here

    private void extractTarGzDistribution(URL sourceDistribution, File targetFolder) throws IOException,
            FileNotFoundException {
        File uncompressedFile = File.createTempFile("uncompressedTarGz-", ".tar");
        extractGzArchive(sourceDistribution.openStream(), uncompressedFile);
        extract(new TarArchiveInputStream(new FileInputStream(uncompressedFile)), targetFolder);
        FileUtils.forceDelete(uncompressedFile);
    }
View Full Code Here

        } else if (a == '=' && (b == '<' || b == '!')) {
            metadata.set(Metadata.CONTENT_TYPE, "application/x-archive");
            unpack(new ArArchiveInputStream(stream), xhtml);
        } else {
            metadata.set(Metadata.CONTENT_TYPE, "application/x-tar");
            unpack(new TarArchiveInputStream(stream), xhtml);
        }

        xhtml.endDocument();
    }
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.