Package org.apache.tools.tar

Examples of org.apache.tools.tar.TarInputStream


     */
    private void extract() throws IOException {
        TarEntry entry;
        InputStream in = null;
        OutputStream out;
        TarInputStream tin;
        File file;
       
        if (archive != null) {
            if ((in = openFileRead(archive)) == null) {
                fatal(" ", 1);
            }
        } else {
            in = stdin;
        }
       
        if (decompress != 0) {
            in = wrapInputStream(in);
        }
        tin = new TarInputStream(in);
       
        if (use_stdout) {
            out = stdout;
        }
       
        while ((entry = tin.getNextEntry()) != null) {
            notice(entry.getName());
            file = new File(entry.getName());
            if (entry.isDirectory()) {
                if (!file.exists()) {
                    file.mkdirs();
                }
                continue;
            } else {
                if (file.exists()) {
                    if (keepOld || (keepNew && (file.lastModified() >= entry.getModTime().getTime()))) {
                        continue;
                    }
                    if (backup) {
                        file.renameTo(new File(file.getPath() + suffix));
                    }
                }
            }
            if ((out = openFileWrite(file, true, true)) == null) {
                continue;
            }
            tin.copyEntryContents(out);
            out.close();
        }
        tin.close();
    }
View Full Code Here


     *      or by wildcard patterns.
     */
    private void list() throws IOException {
        TarEntry entry;
        InputStream in = null;
        TarInputStream tin;
       
        if ((in = openFileRead(archive)) == null) {
            fatal(" ", 1);
        }
       
        if (decompress != 0) {
            in = wrapInputStream(in);
        }
        tin = new TarInputStream(in);
       
        while ((entry = tin.getNextEntry()) != null) {
            out(entry.getName());
        }
    }
View Full Code Here

     * Outputs the differences found between the archive and the file system.
     */
    private void diff() throws IOException {
        TarEntry entry;
        InputStream in = null;
        TarInputStream tin;
        File file;
       
        if ((in = openFileRead(archive)) == null) {
            exit(1);
        }
       
        if (decompress != 0) {
            in = wrapInputStream(in);
        }
        tin = new TarInputStream(in);
       
        while ((entry = tin.getNextEntry()) != null) {
            file = new File(entry.getName());
           
            if (!file.exists()) {
                out(file + ": Warning: No such file or directory");
                continue;
View Full Code Here

    private TarOutputStream appendTarOutputStream() throws IOException {
        // FIXME this isnt working.
        OutputStream out;
        InputStream in;
        TarOutputStream tout;
        TarInputStream tin;
        File tmpArchive;
       
        tmpArchive = archive.getAbsoluteFile();
        tmpArchive.renameTo(new File(archive.getName() + ".tmp"));
       
        createArchive();
       
        if ((out = openFileWrite(archive, false, false)) == null) {
            fatal(" ", 1);
        }
        if (compress != 0) {
            out = wrapOutputStream(out);
        }
        tout = new TarOutputStream(out);
       
        if ((in = openFileRead(tmpArchive)) == null) {
            fatal(" ", 1);
        }
        if (decompress != 0) {
            in = wrapInputStream(in);
        }
        tin = new TarInputStream(in);
        copy(tin, tout);
        tmpArchive.delete();
       
        return tout;
    }
View Full Code Here

    protected void fillMapsFromArchive(Resource src, String encoding,
            Map<String, Resource> fileEntries, Map<String, Resource> matchFileEntries,
            Map<String, Resource> dirEntries, Map<String, Resource> 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

    /**
     * @see Expand#expandFile(FileUtils, File, File)
     */
    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

            untar(destDir, inputStream);
        }
    }

    protected void untar(File destDir, InputStream inputStream) throws IOException {
        TarInputStream tin = new TarInputStream(inputStream);
        TarEntry tarEntry = null;

        while ((tarEntry = tin.getNextEntry()) != null) {
            File destEntry = new File(destDir, tarEntry.getName());
            File parent = destEntry.getParentFile();

            if (!parent.exists()) {
                parent.mkdirs();
            }

            if (tarEntry.isDirectory()) {
                destEntry.mkdirs();
            } else {
                FileOutputStream fout = new FileOutputStream(destEntry);
                try {
                    tin.copyEntryContents(fout);
                } finally {
                    fout.close();
                }
            }
        }
       
        tin.close();
    }
View Full Code Here

   
    static public InputStream tryOpenAsArchive(File file, String mimeType, String contentType) {
        String fileName = file.getName();
        try {
            if (fileName.endsWith(".tar.gz") || fileName.endsWith(".tgz")) {
                return new TarInputStream(new GZIPInputStream(new FileInputStream(file)));
            } else if (fileName.endsWith(".tar.bz2")) {
                return new TarInputStream(new CBZip2InputStream(new FileInputStream(file)));
            } else if (fileName.endsWith(".tar") || "application/x-tar".equals(contentType)) {
                return new TarInputStream(new FileInputStream(file));
            } else if (fileName.endsWith(".zip")
                    || "application/x-zip-compressed".equals(contentType)
                    || "application/zip".equals(contentType)
                    || "application/x-compressed".equals(contentType)
                    || "multipar/x-zip".equals(contentType)) {
View Full Code Here

        JSONObject archiveFileRecord,
        JSONArray fileRecords,
        final Progress progress
    ) {
        if (archiveIS instanceof TarInputStream) {
            TarInputStream tis = (TarInputStream) archiveIS;
            try {
                TarEntry te;
                while (!progress.isCanceled() && (te = tis.getNextEntry()) != null) {
                    if (!te.isDirectory()) {
                        String fileName2 = te.getName();
                        File file2 = allocateFile(rawDataDir, fileName2);
                       
                        progress.setProgress("Extracting " + fileName2, -1);
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

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.