Package org.apache.tools.tar

Examples of org.apache.tools.tar.TarInputStream


     */
    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);
                    }
                } else {
                    fileEntries.put(name, r);
                    if (match(name)) {
                        matchFileEntries.put(name, r);
                    }
                }
            }
        } catch (IOException ex) {
            throw new BuildException("problem reading " + srcFile, ex);
        } finally {
            if (ti != null) {
                try {
                    ti.close();
                } catch (IOException ex) {
                    // swallow
                }
            }
        }
View Full Code Here


    /**
     * @see Expand#expandFile(FileUtils, File, File)
     */
    protected void expandFile(FileUtils fileUtils, File srcF, File dir) {
        FileInputStream fis = null;
        TarInputStream tis = null;
        try {
            log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO);
            fis = new FileInputStream(srcF);
            tis = new TarInputStream(
                compression.decompress(srcF, new BufferedInputStream(fis)));
            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
                }
            } else if (fis != null) {
                try {
View Full Code Here

public class UnTarTool
{

  public static void unTarGz(File file,File outDir) throws IOException

    TarInputStream tarIn = null

    try

      tarIn = new TarInputStream(new GZIPInputStream
          new BufferedInputStream(new FileInputStream(file)))
          1024);         
     
      TarEntry entry = null;
            //tarIn.getNextEntry(); 
      //File outputDir = new File(outDir, "myBag");
      //outputDir.mkdirs();
      while( (entry = tarIn.getNextEntry()) != null ){ 
        File f = new File(outDir,entry.getName());
        if(entry.isDirectory()){
          f.mkdirs();
        }else{                    
          f.getParentFile().mkdirs();
          f.createNewFile();
          OutputStream out = null
          try
            out = new FileOutputStream(f)
            int length = 0
            byte[] b = new byte[1024]
            while((length = tarIn.read(b)) != -1){ 
              out.write(b, 0, length)
           

          }catch(IOException ex){ 
            throw ex; 
          }finally
            if(out!=null
            out.close()
         
        } 
      } 
    }catch(IOException ex){ 
      throw ex; 
    } finally
      try
        if(tarIn != null){ 
          tarIn.close()
       
      }catch(IOException ex){ 
        throw ex; 
     
    } 
View Full Code Here

    @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

    /**
     * @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;
            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);
            }
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

     */
    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);
View Full Code Here

    zis.close();
  }

  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

    tin.close();
  }

  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

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.