Package org.apache.tools.tar

Examples of org.apache.tools.tar.TarEntry


                        "Entry: " + vPath + " longer than " +
                        TarConstants.NAMELEN + "characters.", location);
                }
            }

            TarEntry te = new TarEntry(vPath);
            te.setModTime(file.lastModified());
            if (!file.isDirectory()) {
                te.setSize(file.length());
                te.setMode(tarFileSet.getMode());
            }
            te.setUserName(tarFileSet.getUserName());
            te.setGroupName(tarFileSet.getGroup());

            tOut.putNextEntry(te);

            if (!file.isDirectory()) {
                fIn = new FileInputStream(file);
View Full Code Here


            log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO);
            tis = new TarInputStream(
                compression.decompress(srcF,
                    new BufferedInputStream(
                        new FileInputStream(srcF))));
            TarEntry te = null;

            while ((te = tis.getNextEntry()) != null) {
                extractFile(fileUtils, srcF, dir, tis,
                            te.getName(), te.getModTime(), te.isDirectory());
            }
            log("expand complete", Project.MSG_VERBOSE);

        } catch (IOException ioe) {
            throw new BuildException("Error while expanding " + srcF.getPath(),
View Full Code Here

            log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO);
            tis = new TarInputStream(
                compression.decompress(srcF,
                    new BufferedInputStream(
                        new FileInputStream(srcF))));
            TarEntry te = null;

            while ((te = tis.getNextEntry()) != null) {
                extractFile(fileUtils, srcF, dir, tis,
                            te.getName(), te.getModTime(), te.isDirectory());
            }
            log("expand complete", Project.MSG_VERBOSE);

        } catch (IOException ioe) {
            throw new BuildException("Error while expanding " + srcF.getPath(),
View Full Code Here

                        + " longer than " + TarConstants.NAMELEN
                        + "characters.", getLocation());
                }
            }

            TarEntry te = new TarEntry(vPath);
            te.setModTime(file.lastModified());
            if (!file.isDirectory()) {
                te.setSize(file.length());
                te.setMode(tarFileSet.getMode());
            } else {
                te.setMode(tarFileSet.getDirMode());
            }
            te.setUserName(tarFileSet.getUserName());
            te.setGroupName(tarFileSet.getGroup());

            tOut.putNextEntry(te);

            if (!file.isDirectory()) {
                fIn = new FileInputStream(file);
View Full Code Here

   */
  public static void unTar(final InputStream in, final String untarDir) throws Exception{
    Log.logInfo("UNTAR", "starting");
    if(new File(untarDir).exists()){
      final TarInputStream tin = new TarInputStream(in);
      TarEntry tarEntry = tin.getNextEntry();
      while(tarEntry != null){
        final File destPath = new File(untarDir + File.separator + tarEntry.getName());
        if (!tarEntry.isDirectory()) {
          new File(destPath.getParent()).mkdirs(); // create missing subdirectories
          final FileOutputStream fout = new FileOutputStream(destPath);
          tin.copyEntryContents(fout);
          fout.close();
        } else {
View Full Code Here

                source = new GZIPInputStream(source);
            } catch (final IOException e) {
                throw new Parser.Failure("tar parser: " + e.getMessage(), url);
            }
        }
        TarEntry entry;
        final TarInputStream tis = new TarInputStream(source);
        File tmp = null;

        // loop through the elements in the tar file and parse every single file inside
        while (true) {
            try {
                if (tis.available() <= 0) break;
                entry = tis.getNextEntry();
                if (entry == null) break;
                if (entry.isDirectory() || entry.getSize() <= 0) continue;
                final String name = entry.getName();
                final int idx = name.lastIndexOf('.');
                final String mime = TextParser.mimeOf((idx > -1) ? name.substring(idx+1) : "");
                try {
                    tmp = FileUtils.createTempFile(this.getClass(), name);
                    FileUtils.copy(tis, tmp, entry.getSize());
                    subDocs = TextParser.parseSource(MultiProtocolURI.newURL(url,"#" + name), mime, null, tmp, false);
                    if (subDocs == null) continue;
                    for (final Document d: subDocs) docacc.add(d);
                } catch (final Parser.Failure e) {
                    this.log.logWarning("tar parser entry " + name + ": " + e.getMessage());
View Full Code Here

        }

        private void visitDir(FileCopyDetails dirDetails) {
            try {
                // Trailing slash on name indicates entry is a directory
                TarEntry archiveEntry = new TarEntry(dirDetails.getRelativePath().getPathString() + '/');
                archiveEntry.setModTime(dirDetails.getLastModified());
                archiveEntry.setMode(UnixStat.DIR_FLAG | dirDetails.getMode());
                tarOutStr.putNextEntry(archiveEntry);
                tarOutStr.closeEntry();
            } catch (Exception e) {
                throw new GradleException(String.format("Could not add %s to TAR '%s'.", dirDetails, tarFile), e);
            }
View Full Code Here

    }

    private void visitImpl(FileVisitor visitor, InputStream inputStream) throws IOException {
        AtomicBoolean stopFlag = new AtomicBoolean();
        NoCloseTarInputStream tar = new NoCloseTarInputStream(inputStream);
        TarEntry entry;
        while (!stopFlag.get() && (entry = tar.getNextEntry()) != null) {
            if (entry.isDirectory()) {
                visitor.visitDir(new DetailsImpl(entry, tar, stopFlag, chmod));
            } else {
                visitor.visitFile(new DetailsImpl(entry, tar, stopFlag, chmod));
            }
        }
View Full Code Here

            }
        }

        private void visitFile(FileCopyDetails fileDetails) {
            try {
                TarEntry archiveEntry = new TarEntry(fileDetails.getRelativePath().getPathString());
                archiveEntry.setModTime(fileDetails.getLastModified());
                archiveEntry.setSize(fileDetails.getSize());
                archiveEntry.setMode(UnixStat.FILE_FLAG | fileDetails.getMode());
                tarOutStr.putNextEntry(archiveEntry);
                fileDetails.copyTo(tarOutStr);
                tarOutStr.closeEntry();
            } catch (Exception e) {
                throw new GradleException(String.format("Could not add %s to TAR '%s'.", fileDetails, tarFile), e);
View Full Code Here

     * @param bundle   Compressed Bundle file
     * @param path
     * @param fileName
     */
    private void untar ( InputStream bundle, String path, String fileName ) {
        TarEntry entry;
        TarInputStream inputStream = null;
        FileOutputStream outputStream = null;

        try {
          //Clean the bundler folder if exist to clean dirty data
          String previousFolderPath = path.replace(fileName, "");
          File previousFolder = new File(previousFolderPath);
          if(previousFolder.exists()){
            FileUtils.cleanDirectory(previousFolder);
          }
            // get a stream to tar file
            InputStream gstream = new GZIPInputStream( bundle );
            inputStream = new TarInputStream( gstream );

            // For each entry in the tar, extract and save the entry to the file
            // system
            while ( null != (entry = inputStream.getNextEntry()) ) {
                // for each entry to be extracted
                int bytesRead;

                String pathWithoutName = path.substring( 0,
                        path.indexOf( fileName ) );

                // if the entry is a directory, create the directory
                if ( entry.isDirectory() ) {
                    File fileOrDir = new File( pathWithoutName + entry.getName() );
                    fileOrDir.mkdir();
                    continue;
                }

                // write to file
                byte[] buf = new byte[1024];
                outputStream = new FileOutputStream( pathWithoutName
                        + entry.getName() );
                while ( (bytesRead = inputStream.read( buf, 0, 1024 )) > -1 )
                    outputStream.write( buf, 0, bytesRead );
                try {
                    if ( null != outputStream ) {
                        outputStream.close();
View Full Code Here

TOP

Related Classes of org.apache.tools.tar.TarEntry

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.