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

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


        } 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


    }
    StringBuilder classpath = new StringBuilder();
    // put the jar files under the archive in the classpath
    try {
      final InputStream is = new FileInputStream(archiveFile);
      final TarArchiveInputStream debInputStream =
          (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream("tar", is);
      TarArchiveEntry entry = null;
      while ((entry = (TarArchiveEntry) debInputStream.getNextEntry()) != null) {
        if (entry.isFile()) {
          classpath.append(File.pathSeparatorChar);
          classpath.append("./" + serviceName + "/" + entry.getName());
        }
      }
      debInputStream.close();

    } catch (Exception e) {
      LOG.error("Unable to read archive file:" + archiveFile, e);
    }
    return classpath.toString();
View Full Code Here

    Runtime.getRuntime().exec(args);
    LOGGER.info("Set execute permissions on " + file);
  }

  private void untarTarFile(File tarFile, File destDir) throws Exception {
    TarArchiveInputStream tarInputStream = null;
    try {
      tarInputStream = new TarArchiveInputStream(new FileInputStream(tarFile));
      TarArchiveEntry entry = null;
      while ((entry = tarInputStream.getNextTarEntry()) != null) {
        String name = entry.getName();
        LOGGER.debug("Next file: " + name);
        File destFile = new File(destDir, entry.getName());
        if (entry.isDirectory()) {
          destFile.mkdirs();
          continue;
        }
        File destParent = destFile.getParentFile();
        destParent.mkdirs();
        OutputStream entryOutputStream = null;
        try {
          entryOutputStream = new FileOutputStream(destFile);
          byte[] buffer = new byte[2048];
          int length = 0;
          while ((length = tarInputStream.read(buffer, 0, 2048)) != -1) {
            entryOutputStream.write(buffer, 0, length);
          }
        } catch (Exception ex) {
          LOGGER.error("Exception while expanding tar file", ex);
          throw ex;
        } finally {
          if (entryOutputStream != null) {
            try {
              entryOutputStream.close();
            } catch (Exception ex) {
              LOGGER.warn("Failed to close entry output stream", ex);
            }
          }
        }
      }
    } catch (Exception ex) {
      LOGGER.error("Exception caught while untarring tar file: "
            + tarFile.getAbsolutePath(), ex);
      throw ex;
    } finally {
      if (tarInputStream != null) {
        try {
          tarInputStream.close();
        } catch (Exception ex) {
          LOGGER.warn("Unable to close tar input stream: "
                + tarFile.getCanonicalPath(), ex);
        }
      }
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

                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
                    // ignored
                } finally {
                    if (tais != null) {
                        try {
                            tais.close();
                        } catch (IOException ignored) { // NOPMD
                            // ignored
                        }
                    }
                }
View Full Code Here

     * @param encoding the encoding of the entry names, ignored
     */
    public ArchiveInputStream getArchiveStream(InputStream stream,
                                               String encoding)
        throws IOException {
        return new TarArchiveInputStream(stream);
    }
View Full Code Here

                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

                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

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.