Package org.apache.tools.tar

Examples of org.apache.tools.tar.TarEntry


    @Override
    public void analyze(Document doc, StreamSource src, Writer xrefOut) throws IOException {
        ArrayList<String> names = new ArrayList<>();

        try (TarInputStream zis = new TarInputStream(src.getStream())) {
            TarEntry entry;
            while ((entry = zis.getNextEntry()) != null) {
                String name = entry.getName();
                names.add(name);
                if (xrefOut != null) {
                    Util.htmlize(name, xrefOut);
                    xrefOut.append("<br/>");
                }
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;
            boolean empty = true;
            FileNameMapper mapper = getMapper();
            while ((te = tis.getNextEntry()) != null) {
                empty = false;
                extractFile(FileUtils.getFileUtils(), null, dir, tis,
                            te.getName(), te.getModTime(),
                            te.isDirectory(), mapper);
            }
            if (empty && getFailOnEmptyArchive()) {
                throw new BuildException("archive '" + name + "' is empty");
            }
            log("expand complete", Project.MSG_VERBOSE);
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

    protected void fetchEntry() {
        Resource archive = getArchive();
        TarInputStream i = null;
        try {
            i = new TarInputStream(archive.getInputStream());
            TarEntry te = null;
            while ((te = i.getNextEntry()) != null) {
                if (te.getName().equals(getName())) {
                    setEntry(te);
                    return;
                }
            }
        } catch (IOException e) {
View Full Code Here

     * patterns and didn't match any exclude patterns.
     */
    protected void fillMapsFromArchive(Resource src, String encoding,
                                       Map fileEntries, Map matchFileEntries,
                                       Map dirEntries, Map matchDirEntries) {
        TarEntry entry = null;
        TarInputStream ti = null;

        try {
            try {
                ti = new TarInputStream(src.getInputStream());
            } catch (IOException ex) {
                throw new BuildException("problem opening " + srcFile, ex);
            }
            while ((entry = ti.getNextEntry()) != null) {
                Resource r = new TarResource(src, entry);
                String name = entry.getName();
                if (entry.isDirectory()) {
                    name = trimSeparator(name);
                    dirEntries.put(name, r);
                    if (match(name)) {
                        matchDirEntries.put(name, r);
                    }
View Full Code Here

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

        TarEntry te = new TarEntry(vPath, preserveLeadingSlashes);
        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

  }

  protected void readTGZFile(byte[] fileBytes) throws IOException {
    contents.clear();
    TarInputStream tin = new TarInputStream(new GZIPInputStream(new ByteArrayInputStream(fileBytes)));
    TarEntry tarEntry = tin.getNextEntry();
    while (tarEntry != null) {
      if (!tarEntry.isDirectory()) {
        // tar.getName()
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        tin.copyEntryContents(os);
        os.close();
        contents.put(tarEntry.getName(), os.toByteArray());
      }
      tarEntry = tin.getNextEntry();
    }
    tin.close();
  }
View Full Code Here

  }

  protected void readTarFile(byte[] fileBytes) throws IOException {
    contents.clear();
    TarInputStream tin = new TarInputStream(new ByteArrayInputStream(fileBytes));
    TarEntry tarEntry = tin.getNextEntry();
    while (tarEntry != null) {
      if (!tarEntry.isDirectory()) {
        // tar.getName()
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        tin.copyEntryContents(os);
        os.close();
        contents.put(tarEntry.getName(), os.toByteArray());
      }
      tarEntry = tin.getNextEntry();
    }
    tin.close();
  }
View Full Code Here

      targetFile.getParentFile().mkdirs();
      TarOutputStream out = new TarOutputStream(new GZIPOutputStream(new FileOutputStream(targetFile)));
      out.setLongFileMode(TarOutputStream.LONGFILE_GNU);
     
      for( String f : fileList ) {
        TarEntry e = new TarEntry(sourceDir.getName() + "/" + f);
        File tarFile = new File(sourceDir, f);
        if( tarFile.canExecute() ) {
          e.setMode(0755);
        }
        e.setSize(tarFile.length());
        out.putNextEntry(e);
       
        FileInputStream in = new FileInputStream(tarFile);
        byte[] buf = new byte[1024];
        int l;
View Full Code Here

  private static File uncompress(File compressedFile, File targetDirectory) {
    File targetDir = null;
    if( compressedFile.getName().endsWith(".tar.gz") ) {
      try {
        TarInputStream in = new TarInputStream(new GZIPInputStream(new FileInputStream(compressedFile)));
        TarEntry e;
        while( (e = in.getNextEntry()) != null ) {
          if( e.isDirectory() ) {
            File f = new File(targetDirectory,e.getName());
            f.mkdirs();
            if( targetDir == null ) {
              targetDir = f;
            }
          } else {
            File f = new File(targetDirectory,e.getName());
            if( ! f.getParentFile().exists() ) {
              f.getParentFile().mkdirs();
            }
            in.copyEntryContents(new FileOutputStream(f));
           
            int m = e.getMode();
            if( (m & OWNER_EXEC) == OWNER_EXEC
                || (m & GROUP_EXEC) == GROUP_EXEC
                || (m & OTHER_EXEC) == OTHER_EXEC ) {
              f.setExecutable(true, false);
            } else if( e.getLinkName() != null && e.getLinkName().trim().length() > 0 ) {
              //TODO Handle symlinks
//              System.err.println("A LINK: " + e.getLinkName());
            }
          }
        }
        in.close();
       
        if( targetDir == null ) {
          targetDir = new File(targetDirectory,"eclipse");
        }
      } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
    } else if( compressedFile.getName().endsWith(".zip") ) {
      try {
        ZipInputStream in = new ZipInputStream(new FileInputStream(compressedFile));
        ZipEntry e;
        while( (e = in.getNextEntry()) != null ) {
          if( e.isDirectory() ) {
            File f = new File(targetDirectory,e.getName());
            f.mkdirs();
            if( targetDir == null ) {
              targetDir = f;
            }
          } else {
            File f = new File(targetDirectory,e.getName());
            if( ! f.getParentFile().exists() ) {
              f.getParentFile().mkdirs();
            }
            FileOutputStream out = new FileOutputStream(f);
            byte[] buf = new byte[1024];
            int l;
            while( (l = in.read(buf, 0, 1024)) != -1 ) {
              out.write(buf,0,l);
            }
            out.close();
          }
          in.closeEntry();
        }
        in.close();
       
        if( targetDir == null ) {
          targetDir = new File(targetDirectory,"eclipse");
        }
      } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
    }
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.