Package org.apache.tools.tar

Examples of org.apache.tools.tar.TarInputStream


            } 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) : "");
View Full Code Here


   * @throws Exception (IOException or FileNotFoundException)
   */
  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 {
          destPath.mkdir();
        }
        tarEntry = tin.getNextEntry();
      }
      tin.close();
    } else { // untarDir doesn't exist
      Log.logWarning("UNTAR", "destination " + untarDir + " doesn't exist.");
    }
    Log.logInfo("UNTAR", "finished");
  }
View Full Code Here

    String prefix = tarFileSet.getPrefix();
    if (prefix.length() > 0 && !prefix.endsWith("/")) {
      // '/' is appended for compatibility with the zip task.
      prefix = prefix + "/";
    }
    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;
            }
            tOut.write(buffer, 0, count);
          }
        }
        tOut.closeEntry();
      }

    } catch (IOException e) {
      throw new BuildException("Error while expanding " + file.getPath(), e,
          getLocation());
    } finally {
      if (tIn != null) {
        try {
          tIn.close();
        } catch (IOException ignored) {
        }
      }
    }
  }
View Full Code Here

    /**
     * @since Ant 1.7
     */
    private void expandStream(String name, InputStream stream, File dir)
        throws IOException {
        TarInputStream tis = null;
        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);
View Full Code Here

    public InputStream getInputStream() throws IOException {
        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;
            }
        }
View Full Code Here

    /**
     * fetches information from the named entry inside the archive.
     */
    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;
                }
            }
View Full Code Here

    public void setCompression(UntarCompressionMethod method) {
        compression = method;
    }

    protected void expandFile(FileUtils fileUtils, File srcF, File dir) {
        TarInputStream tis = null;
        try {
            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(),
                                     ioe, location);
        } finally {
            if (tis != null) {
                try {
                    tis.close();
                } catch (IOException e) {}
            }
        }
    }
View Full Code Here

                                 + " task doesn't support the encoding"
                                 + " attribute", getLocation());
    }

    protected void expandFile(FileUtils fileUtils, File srcF, File dir) {
        TarInputStream tis = null;
        try {
            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(),
                                     ioe, getLocation());
        } finally {
            if (tis != null) {
                try {
                    tis.close();
                } catch (IOException e) {
                    // ignore
                }
            }
        }
View Full Code Here

     * TODO If the verify option is set, the original archive is backed up before operating
     *      on it, and verified before exiting. If the archive is bad, the original is restored.
     */
    private void concat(File[] archives) throws IOException {
        InputStream in;
        TarInputStream tin;
        TarOutputStream tout;
       
        // Setup archive for appending
        tout = appendTarOutputStream();
       
        // Concatenate new archives
        for (File arch : archives) {
            if ((in = openFileRead(arch)) == null) {
                continue;
            }
            bzip = gzip = false;
            decompress = checkCompressed(arch);
            if (decompress != 0) {
                in = wrapInputStream(in);
            }
            tin = new TarInputStream(in);
            copy(tin, tout);
        }
        tout.close();
    }
View Full Code Here

    }
   
    // TODO
    private void update(File[] files) throws IOException {
        InputStream in;
        TarInputStream tin;
        TarEntry entry;
        TreeMap<String, Long> entries = new TreeMap<String, Long>();
       
        if ((in = openFileRead(archive)) == null) {
            fatal(" ", 1);
        }
        if (decompress != 0) {
            in = wrapInputStream(in);
        }
       
        tin = new TarInputStream(in);
       
        while ((entry = tin.getNextEntry()) != null) {
            entries.put(entry.getName(), entry.getModTime().getTime());
        }
        tin.close();
       
        long etime, ftime;
        ArrayList<File> list = new ArrayList<File>();
        for (File file : files) {
            if (entries.containsKey(file.getPath())) {
View Full Code Here

TOP

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

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.