Package org.apache.tools.tar

Examples of org.apache.tools.tar.TarOutputStream


                    outStr.write('B');
                    outStr.write('Z');
                    outStr = new CBZip2OutputStream(outStr);
                    break;
            }
            tarOutStr = new TarOutputStream(outStr);
            tarOutStr.setLongFileMode(TarOutputStream.LONGFILE_GNU);
        } catch (Exception e) {
            throw new GradleException(String.format("Could not create TAR '%s'.", tarFile), e);
        }
    }
View Full Code Here


    setupDirs();
   
    // make a simple tar:
    final File simpleTar = new File(del, FILE);
    OutputStream os = new FileOutputStream(simpleTar);
    TarOutputStream tos = new TarOutputStream(os);
    try {
      TarEntry te = new TarEntry("foo");
      byte[] data = "some-content".getBytes("UTF-8");
      te.setSize(data.length);
      tos.putNextEntry(te);
      tos.write(data);
      tos.closeEntry();
      tos.flush();
      tos.finish();
    } finally {
      tos.close();
    }

    // successfully untar it into an existing dir:
    FileUtil.unTar(simpleTar, tmp);
    // check result:
View Full Code Here

                return;
            }

            log("Building tar: " + tarFile.getAbsolutePath(), Project.MSG_INFO);

            TarOutputStream tOut = null;
            try {
                tOut = new TarOutputStream(
                    compression.compress(
                        new BufferedOutputStream(
                            new FileOutputStream(tarFile))));
                tOut.setDebug(true);
                if (longFileMode.isTruncateMode()) {
                    tOut.setLongFileMode(TarOutputStream.LONGFILE_TRUNCATE);
                } else if (longFileMode.isFailMode()
                            || longFileMode.isOmitMode()) {
                    tOut.setLongFileMode(TarOutputStream.LONGFILE_ERROR);
                } else {
                    // warn or GNU
                    tOut.setLongFileMode(TarOutputStream.LONGFILE_GNU);
                }

                longWarningGiven = false;
                for (Enumeration e = filesets.elements();
                     e.hasMoreElements();) {
View Full Code Here

                return;
            }

            log("Building tar: " + tarFile.getAbsolutePath(), Project.MSG_INFO);

            TarOutputStream tOut = null;
            try {
                tOut = new TarOutputStream(
                    compression.compress(
                        new BufferedOutputStream(
                            new FileOutputStream(tarFile))));
                tOut.setDebug(true);
                if (longFileMode.isTruncateMode()) {
                    tOut.setLongFileMode(TarOutputStream.LONGFILE_TRUNCATE);
                } else if (longFileMode.isFailMode() ||
                         longFileMode.isOmitMode()) {
                    tOut.setLongFileMode(TarOutputStream.LONGFILE_ERROR);
                } else {
                    // warn or GNU
                    tOut.setLongFileMode(TarOutputStream.LONGFILE_GNU);
                }

                longWarningGiven = false;
                for (Enumeration e = filesets.elements();
                     e.hasMoreElements();) {
                    TarFileSet fs = (TarFileSet) e.nextElement();
                    String[] files = fs.getFiles(project);
                    if (files.length > 1 && fs.getFullpath().length() > 0) {
                        throw new BuildException("fullpath attribute may only "
                                                 + "be specified for "
                                                 + "filesets that specify a "
                                                 + "single file.");
                    }
                    for (int i = 0; i < files.length; i++) {
                        File f = new File(fs.getDir(project), files[i]);
                        String name = files[i].replace(File.separatorChar, '/');
                        tarFile(f, tOut, name, fs);
                    }
                }
            } catch (IOException ioe) {
                String msg = "Problem creating TAR: " + ioe.getMessage();
                throw new BuildException(msg, ioe, location);
            } finally {
                if (tOut != null) {
                    try {
                        // close up
                        tOut.close();
                    } catch (IOException e) {}
                }
            }
        } finally {
            filesets = savedFileSets;
View Full Code Here

                return;
            }

            log("Building tar: " + tarFile.getAbsolutePath(), Project.MSG_INFO);

            TarOutputStream tOut = null;
            try {
                tOut = new TarOutputStream(
                    compression.compress(
                        new BufferedOutputStream(
                            new FileOutputStream(tarFile))));
                tOut.setDebug(true);
                if (longFileMode.isTruncateMode()) {
                    tOut.setLongFileMode(TarOutputStream.LONGFILE_TRUNCATE);
                } else if (longFileMode.isFailMode()
                            || longFileMode.isOmitMode()) {
                    tOut.setLongFileMode(TarOutputStream.LONGFILE_ERROR);
                } else {
                    // warn or GNU
                    tOut.setLongFileMode(TarOutputStream.LONGFILE_GNU);
                }

                longWarningGiven = false;
                for (Enumeration e = filesets.elements();
                     e.hasMoreElements();) {
                    TarFileSet fs = (TarFileSet) e.nextElement();
                    String[] files = fs.getFiles(getProject());
                    if (files.length > 1 && fs.getFullpath().length() > 0) {
                        throw new BuildException("fullpath attribute may only "
                                                 + "be specified for "
                                                 + "filesets that specify a "
                                                 + "single file.");
                    }
                    for (int i = 0; i < files.length; i++) {
                        File f = new File(fs.getDir(getProject()), files[i]);
                        String name = files[i].replace(File.separatorChar, '/');
                        tarFile(f, tOut, name, fs);
                    }
                }
            } catch (IOException ioe) {
                String msg = "Problem creating TAR: " + ioe.getMessage();
                throw new BuildException(msg, ioe, getLocation());
            } finally {
                if (tOut != null) {
                    try {
                        // close up
                        tOut.close();
                    } catch (IOException e) {
                        // ignore
                    }
                }
            }
View Full Code Here

     *      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

     *      on it, and verified before exiting. If the archive is bad, the original is restored.
     */
    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);
                in.close();
            }
            tout.closeEntry();
        }
        tout.close();
    }
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) {
View Full Code Here

                                         + " directory for " + tarFile);
            }

            log("Building tar: " + tarFile.getAbsolutePath(), Project.MSG_INFO);

            TarOutputStream tOut = null;
            try {
                tOut = new TarOutputStream(
                    compression.compress(
                        new BufferedOutputStream(
                            new FileOutputStream(tarFile))));
                tOut.setDebug(true);
                if (longFileMode.isTruncateMode()) {
                    tOut.setLongFileMode(TarOutputStream.LONGFILE_TRUNCATE);
                } else if (longFileMode.isFailMode()
                            || longFileMode.isOmitMode()) {
                    tOut.setLongFileMode(TarOutputStream.LONGFILE_ERROR);
                } else if (longFileMode.isPosixMode()) {
                    tOut.setLongFileMode(TarOutputStream.LONGFILE_POSIX);
                } else {
                    // warn or GNU
                    tOut.setLongFileMode(TarOutputStream.LONGFILE_GNU);
                }

                longWarningGiven = false;
                for (Enumeration e = filesets.elements();
                     e.hasMoreElements();) {
View Full Code Here

            gos.close();
        }
    }

    protected void tarToOutputStream(Project project, OutputStream os) throws IOException {
        TarOutputStream tos = new TarOutputStream(os);
        try {
            ProjectManager.singleton.exportProject(project.id, tos);
        } finally {
            tos.close();
        }
    }
View Full Code Here

TOP

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

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.