Example usage for org.apache.commons.compress.archivers.tar TarArchiveOutputStream closeArchiveEntry

List of usage examples for org.apache.commons.compress.archivers.tar TarArchiveOutputStream closeArchiveEntry

Introduction

In this page you can find the example usage for org.apache.commons.compress.archivers.tar TarArchiveOutputStream closeArchiveEntry.

Prototype

public void closeArchiveEntry() throws IOException 

Source Link

Document

Close an entry.

Usage

From source file:com.pinterest.deployservice.common.TarUtils.java

static void addInputStreamToTar(TarArchiveOutputStream taos, InputStream is, String path, long size, int mode)
        throws Exception {
    TarArchiveEntry entry = new TarArchiveEntry(path);
    entry.setSize(size);/* w  w w .j a v a  2  s .  co  m*/
    entry.setMode(mode);
    try {
        taos.putArchiveEntry(entry);
        IOUtils.copy(is, taos);
    } finally {
        taos.closeArchiveEntry();
        Closeables.closeQuietly(is);
    }
}

From source file:com.ttech.cordovabuild.infrastructure.archive.ArchiveUtils.java

private static void addFileToTarGz(TarArchiveOutputStream tOut, Path path, String base) throws IOException {
    File f = path.toFile();//from  w w w.  j a va2  s . c  o  m
    String entryName = base + f.getName();
    TarArchiveEntry tarEntry = new TarArchiveEntry(f, entryName);
    tOut.putArchiveEntry(tarEntry);
    if (f.isFile()) {
        IOUtils.copy(new FileInputStream(f), tOut);
        tOut.closeArchiveEntry();
    } else {
        tOut.closeArchiveEntry();
        File[] children = f.listFiles();
        if (children != null) {
            for (File child : children) {
                addFileToTarGz(tOut, child.toPath().toAbsolutePath(), entryName + "/");
            }
        }
    }
}

From source file:msec.org.TarUtil.java

private static void archiveDir(File dir, TarArchiveOutputStream taos, String basePath) throws Exception {

    File[] files = dir.listFiles();

    if (files.length < 1) {
        TarArchiveEntry entry = new TarArchiveEntry(basePath + dir.getName() + File.separator);

        taos.putArchiveEntry(entry);// ww  w . ja  va 2  s .  c  o  m
        taos.closeArchiveEntry();
    }

    for (File file : files) {

        // 
        archive(file, taos, basePath + dir.getName() + File.separator);

    }
}

From source file:com.codenvy.commons.lang.TarUtils.java

private static void addDirectoryEntry(TarArchiveOutputStream tarOut, String entryName, File directory,
        long modTime) throws IOException {
    final TarArchiveEntry tarEntry = new TarArchiveEntry(directory, entryName);
    if (modTime >= 0) {
        tarEntry.setModTime(modTime);//from w w w  .j  ava2 s  .  com
    }
    tarOut.putArchiveEntry(tarEntry);
    tarOut.closeArchiveEntry();
}

From source file:com.github.trask.comet.loadtest.aws.ChefBootstrap.java

private static void addToTarWithBase(File file, TarArchiveOutputStream tarOut, String base) throws IOException {

    String entryName = base + file.getName();
    TarArchiveEntry tarEntry = new TarArchiveEntry(file, entryName);

    tarOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
    tarOut.putArchiveEntry(tarEntry);/*from   w ww.j  a  v  a 2 s.  co  m*/

    if (file.isFile()) {
        IOUtils.copy(new FileInputStream(file), tarOut);
        tarOut.closeArchiveEntry();
    } else {
        tarOut.closeArchiveEntry();
        File[] children = file.listFiles();
        if (children != null) {
            for (File child : children) {
                addToTarWithBase(child, tarOut, entryName + "/");
            }
        }
    }
}

From source file:gobblin.util.io.StreamUtils.java

/**
 * Helper method for {@link #tar(FileSystem, FileSystem, Path, Path)} that adds a directory entry to a given
 * {@link TarArchiveOutputStream}./*from  ww  w . ja va2  s.  c  o m*/
 */
private static void dirToTarArchiveOutputStream(Path destDir, TarArchiveOutputStream tarArchiveOutputStream)
        throws IOException {
    TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(formatPathToDir(destDir));
    tarArchiveEntry.setModTime(System.currentTimeMillis());
    tarArchiveOutputStream.putArchiveEntry(tarArchiveEntry);
    tarArchiveOutputStream.closeArchiveEntry();
}

From source file:com.salsaberries.narchiver.Writer.java

private static void addFilesToCompression(TarArchiveOutputStream taos, File file, String dir)
        throws IOException {
    // Create an entry for the file
    taos.putArchiveEntry(new TarArchiveEntry(file, dir + FILE_SEPARATOR + file.getName()));
    if (file.isFile()) {
        // Add the file to the archive
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
        IOUtils.copy(bis, taos);//from w  w w. j a  v  a2s  .c  om
        taos.closeArchiveEntry();
        bis.close();
    } else if (file.isDirectory()) {
        // Close the archive entry
        taos.closeArchiveEntry();
        // Go through all the files in the directory and using recursion, add them to the archive
        for (File childFile : file.listFiles()) {
            addFilesToCompression(taos, childFile, file.getName());
        }
    }
}

From source file:company.gonapps.loghut.utils.FileUtils.java

private static void addFileToArchive(TarArchiveOutputStream tarArchiveOutputStream, String path, String base)
        throws IOException {
    File file = new File(path);
    String entryName = base + file.getName();
    tarArchiveOutputStream.putArchiveEntry(new TarArchiveEntry(file, entryName));

    if (file.isFile()) {
        try (FileInputStream fileInputStream = new FileInputStream(file)) {
            IOUtils.copy(fileInputStream, tarArchiveOutputStream);
        }//ww  w  . j a v  a2  s  . co m
        tarArchiveOutputStream.closeArchiveEntry();
    } else {
        tarArchiveOutputStream.closeArchiveEntry();
        File[] children = file.listFiles();
        if (children != null) {
            for (File child : children)
                addFileToArchive(tarArchiveOutputStream, child.getAbsolutePath(), entryName + "/");
        }
    }
}

From source file:com.shopzilla.hadoop.repl.commands.util.ClusterStateManager.java

private static void addFilesToCompression(TarArchiveOutputStream taos, File file, String dir)
        throws IOException {
    // Create an entry for the file
    taos.putArchiveEntry(new TarArchiveEntry(file, dir + File.separator + file.getName()));
    if (file.isFile()) {
        // Add the file to the archive
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
        IOUtils.copy(bis, taos);/*from w w  w  .j a  v  a  2s. c o  m*/
        taos.closeArchiveEntry();
        bis.close();
    } else if (file.isDirectory()) {
        // close the archive entry
        taos.closeArchiveEntry();
        // go through all the files in the directory and using recursion, add them to the archive
        for (File childFile : file.listFiles()) {
            addFilesToCompression(taos, childFile, dir + File.separator + file.getName());
        }
    }
}

From source file:com.twitter.heron.apiserver.utils.FileHelper.java

private static void addFileToArchive(TarArchiveOutputStream archiveOutputStream, File file, String base)
        throws IOException {
    final File absoluteFile = file.getAbsoluteFile();
    final String entryName = base + file.getName();
    final TarArchiveEntry tarArchiveEntry = new TarArchiveEntry(file, entryName);
    archiveOutputStream.putArchiveEntry(tarArchiveEntry);

    if (absoluteFile.isFile()) {
        Files.copy(file.toPath(), archiveOutputStream);
        archiveOutputStream.closeArchiveEntry();
    } else {//from w  w  w  . j  av  a  2 s.  c  om
        archiveOutputStream.closeArchiveEntry();
        if (absoluteFile.listFiles() != null) {
            for (File f : absoluteFile.listFiles()) {
                addFileToArchive(archiveOutputStream, f, entryName + "/");
            }
        }
    }
}