Package org.apache.tools.tar

Examples of org.apache.tools.tar.TarEntry


        this.spec = spec;
    }

    public void visitFile(FileVisitDetails fileDetails) {
        try {
            TarEntry archiveEntry = new TarEntry(fileDetails.getRelativePath().getPathString());
            archiveEntry.setModTime(fileDetails.getLastModified());
            archiveEntry.setSize(fileDetails.getSize());
            archiveEntry.setMode(UnixStat.FILE_FLAG | spec.getFileMode());
            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


    }

    public void visitDir(FileVisitDetails 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 | spec.getDirMode());
            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

        AtomicBoolean stopFlag = new AtomicBoolean();
        try {
            FileInputStream inputStream = new FileInputStream(tarFile);
            try {
                NoCloseTarInputStream tar = new NoCloseTarInputStream(inputStream);
                TarEntry entry;
                while (!stopFlag.get() && (entry = tar.getNextEntry()) != null) {
                    if (entry.isDirectory()) {
                        visitor.visitDir(new DetailsImpl(entry, tar, stopFlag));
                    } else {
                        visitor.visitFile(new DetailsImpl(entry, tar, stopFlag));
                    }
View Full Code Here

                source = new GZIPInputStream(source);
            } catch (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);
                    if (subDocs == null) continue;
                    for (final Document d: subDocs) docacc.add(d);
                } catch (final Parser.Failure e) {
                    log.logWarning("tar parser entry " + name + ": " + e.getMessage());
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

    // make a simple tar:
    final File simpleTar = new File(del, FILE);
    OutputStream os = new FileOutputStream(simpleTar);
    TarOutputStream tos = new TarOutputStream(os);
    try {
      TarEntry te = new TarEntry("foo");
      byte[] data = "some-content".getBytes("UTF-8");
      te.setSize(data.length);
      tos.putNextEntry(te);
      tos.write(data);
      tos.closeEntry();
      tos.flush();
      tos.finish();
View Full Code Here

    }
    TarInputStream tIn = null;
    try {
      tIn = new TarInputStream(includeTar.compression.decompress(file,
          new BufferedInputStream(new FileInputStream(file))));
      TarEntry te = null;
      while ((te = tIn.getNextEntry()) != null) {
        vPath = te.getName();

        // don't add "" to the archive
        if (vPath.length() <= 0) {
          continue;
        }

        if (te.isDirectory() && !vPath.endsWith("/")) {
          vPath += "/";
        }

        vPath = prefix + vPath;

        te.setName(vPath);
        tOut.putNextEntry(te);

        if (te.getSize() > 0) {
          byte[] buffer = new byte[8 * 1024];
          while (true) {
            int count = tIn.read(buffer, 0, buffer.length);
            if (count < 0) {
              break;
View Full Code Here

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

        TarEntry te = new TarEntry(vPath);
        te.setModTime(r.getLastModified());
        // preserve permissions
        if (r instanceof ArchiveResource) {
            ArchiveResource ar = (ArchiveResource) r;
            te.setMode(ar.getMode());
            if (r instanceof TarResource) {
                TarResource tr = (TarResource) r;
                te.setUserName(tr.getUserName());
                te.setUserId(tr.getUid());
                te.setGroupName(tr.getGroup());
                te.setGroupId(tr.getGid());
            }
        }

        if (!r.isDirectory()) {
            if (r.size() > TarConstants.MAXSIZE) {
                throw new BuildException(
                    "Resource: " + r + " larger than "
                    + TarConstants.MAXSIZE + " bytes.");
            }
            te.setSize(r.getSize());
            // override permissions if set explicitly
            if (tarFileSet != null && tarFileSet.hasFileModeBeenSet()) {
                te.setMode(tarFileSet.getMode());
            }
        } else if (tarFileSet != null && tarFileSet.hasDirModeBeenSet()) {
            // override permissions if set explicitly
            te.setMode(tarFileSet.getDirMode(this.getProject()));
        }

        if (tarFileSet != null) {
            // only override permissions if set explicitly
            if (tarFileSet.hasUserNameBeenSet()) {
                te.setUserName(tarFileSet.getUserName());
            }
            if (tarFileSet.hasGroupBeenSet()) {
                te.setGroupName(tarFileSet.getGroup());
            }
            if (tarFileSet.hasUserIdBeenSet()) {
                te.setUserId(tarFileSet.getUid());
            }
            if (tarFileSet.hasGroupIdBeenSet()) {
                te.setGroupId(tarFileSet.getGid());
            }
        }

        InputStream in = null;
        try {
View Full Code Here

        try {
            tis =
                new TarInputStream(compression.decompress(name,
                                                          new BufferedInputStream(stream)));
            log("Expanding: " + name + " into " + dir, Project.MSG_INFO);
            TarEntry te = null;
            FileNameMapper mapper = getMapper();
            while ((te = tis.getNextEntry()) != null) {
                extractFile(FileUtils.getFileUtils(), null, dir, tis,
                            te.getName(), te.getModTime(),
                            te.isDirectory(), mapper);
            }
            log("expand complete", Project.MSG_VERBOSE);
        } finally {
            FileUtils.close(tis);
        }
View Full Code Here

        if (isReference()) {
            return ((Resource) getCheckedRef()).getInputStream();
        }
        Resource archive = getArchive();
        final TarInputStream i = new TarInputStream(archive.getInputStream());
        TarEntry te = null;
        while ((te = i.getNextEntry()) != null) {
            if (te.getName().equals(getName())) {
                return i;
            }
        }

        FileUtils.close(i);
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.