Example usage for org.apache.commons.compress.archivers.tar TarArchiveEntry TarArchiveEntry

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

Introduction

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

Prototype

public TarArchiveEntry(File file, String fileName) 

Source Link

Document

Construct an entry for a file.

Usage

From source file:org.vafer.jdeb.producers.Producers.java

/**
 * Creates a tar directory entry with defaults parameters.
 * @param dirName the directory name//from  ww w . jav  a 2s  .c o  m
 * @return dir entry with reasonable defaults
 */
static TarArchiveEntry defaultDirEntryWithName(final String dirName) {
    TarArchiveEntry entry = new TarArchiveEntry(dirName, true);
    entry.setUserId(ROOT_UID);
    entry.setUserName(ROOT_NAME);
    entry.setGroupId(ROOT_UID);
    entry.setGroupName(ROOT_NAME);
    entry.setMode(TarArchiveEntry.DEFAULT_DIR_MODE);
    return entry;
}

From source file:org.wso2.carbon.connector.util.FileCompressUtil.java

/**
 * Add the files to compression/*from   w w w.j av a 2 s  .  c  o  m*/
 * 
 * @param taos
 * @param file
 * @param dir
 * @param archiveType
 * @throws IOException
 */
private void addFilesToCompression(ArchiveOutputStream taos, File file, String dir, ArchiveType archiveType)
        throws IOException {

    // Create an entry for the file
    switch (archiveType) {

    case TAR_GZIP:
        taos.putArchiveEntry(new TarArchiveEntry(file, dir + "/" + file.getName()));
        break;

    case ZIP:
        taos.putArchiveEntry(new ZipArchiveEntry(file, dir + "/" + file.getName()));
        break;
    }

    if (file.isFile()) {
        // Add the file to the archive
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
        IOUtils.copy(bis, taos);
        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(), archiveType);
        }
    }

}

From source file:org.xlcloud.commons.compress.CompressUtils.java

/**
 * Creates tar.gz entry for file recursively
 * /*  ww  w  .ja v  a  2s.  c o  m*/
 * @param archiveStream
 * @param absoluteFile
 * @param string
 * @throws IOException
 */
private static void addFileToArchive(TarArchiveOutputStream archiveStream, File file, String base)
        throws IOException {
    String entryName = base + file.getName();
    TarArchiveEntry tarEntry = new TarArchiveEntry(file, entryName);
    archiveStream.putArchiveEntry(tarEntry);
    if (file.isFile()) {
        FileInputStream fInputStream = null;
        try {
            fInputStream = new FileInputStream(file);
            IOUtils.copy(fInputStream, archiveStream);
            archiveStream.closeArchiveEntry();
        } finally {
            IOUtils.closeQuietly(fInputStream);
        }

    } else {
        archiveStream.closeArchiveEntry();
        File[] children = file.listFiles();
        if (children != null) {
            for (File child : children) {
                addFileToArchive(archiveStream, child, entryName + "/");
            }
        }
    }
}

From source file:psef.handler.ProjectGetHandler.java

/**
 * Add files to a tar.gz archive recursively
 * @param tOut the tar archive output stream
 * @param path the absolute path to the file/dir to add
 * @param base the base path inside the tar.gz archive
 * @throws IOException /*w ww .  j  av  a 2  s  .c  o m*/
 */
private void addFilesToTarGz(TarArchiveOutputStream tOut, String path, String base) throws IOException {
    File f = new File(path);
    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) {
                addFilesToTarGz(tOut, child.getAbsolutePath(), entryName + "/");
            }
        }
    }
}