Package org.apache.tools.tar

Examples of org.apache.tools.tar.TarEntry


     */
    private void insert(File[] files) throws IOException {
        InputStream in;
        OutputStream out;
        TarOutputStream tout = null;
        TarEntry entry;
       
        if (mode == TAR_APPEND && archive.exists()) {
            tout = appendTarOutputStream();
        } else {
            createArchive();
            if ((out = openFileWrite(archive, false, false)) == null) {
                fatal(" ", 1);
            }
            if (compress != 0) {
                out = wrapOutputStream(out);
            }
            tout = new TarOutputStream(out);
        }
       
        // Insert new entries
        for (File file : files) {
            notice(file.getPath());
            entry = new TarEntry(file);
            tout.putNextEntry(entry);
           
            if (!file.isDirectory()) {
                if ((in = openFileRead(file)) == null) continue;
                processStream(in, tout);
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>();
View Full Code Here

     * TODO Need to parse Path for choosing specific files/directories either by direct naming
     *      or by wildcard patterns.
     * TODO Read list of entries to extract from FileList if its set.
     */
    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));
                    }
View Full Code Here

     *
     * TODO Need to parse Path for choosing specific files/directories either by direct naming
     *      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;
            }
           
            if (file.lastModified() != entry.getModTime().getTime()) {
                out(file + ": Mod time is different");
            }
           
            if (file.length() != entry.getSize()) {
                out(file + ": Size is different");
            }
           
            // TODO check file mode
            // TODO check file ownership
View Full Code Here

     * and to copy entries from another archive into another archive.
     *
     * FIXME does not verify that tin is actually a tar archive (Concat)
     */
    private void copy(TarInputStream tin, TarOutputStream tout) throws IOException {
        TarEntry entry;
        while ((entry = tin.getNextEntry()) != null) {
            tout.putNextEntry(entry);
            tin.copyEntryContents(tout);
            tout.closeEntry();
        }
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);
                    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

            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(),
View Full Code Here

        }
    }

    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);
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.