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

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

Introduction

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

Prototype

public void setName(String name) 

Source Link

Document

Set this entry's name.

Usage

From source file:org.jclouds.docker.compute.features.internal.Archives.java

public static File tar(File baseDir, File tarFile) throws IOException {
    // Check that the directory is a directory, and get its contents
    checkArgument(baseDir.isDirectory(), "%s is not a directory", baseDir);
    File[] files = baseDir.listFiles();

    String token = getLast(Splitter.on("/").split(baseDir.getAbsolutePath()));

    byte[] buf = new byte[1024];
    int len;/* w  w w  .  j a va  2s. c  o m*/
    TarArchiveOutputStream tos = new TarArchiveOutputStream(new FileOutputStream(tarFile));
    tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
    for (File file : files) {
        TarArchiveEntry tarEntry = new TarArchiveEntry(file);
        tarEntry.setName("/" + getLast(Splitter.on(token).split(file.toString())));
        tos.putArchiveEntry(tarEntry);
        if (!file.isDirectory()) {
            FileInputStream fin = new FileInputStream(file);
            BufferedInputStream in = new BufferedInputStream(fin);
            while ((len = in.read(buf)) != -1) {
                tos.write(buf, 0, len);
            }
            in.close();
        }
        tos.closeArchiveEntry();
    }
    tos.close();
    return tarFile;
}

From source file:org.jclouds.docker.features.internal.Archives.java

public static File tar(File baseDir, File tarFile) throws IOException {
    // Check that the directory is a directory, and get its contents
    checkArgument(baseDir.isDirectory(), "%s is not a directory", baseDir);
    File[] files = baseDir.listFiles();
    String token = getLast(Splitter.on("/").split(baseDir.getAbsolutePath()));
    TarArchiveOutputStream tos = new TarArchiveOutputStream(new FileOutputStream(tarFile));
    tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
    try {/*from www. j  a v  a  2 s.c  o m*/
        for (File file : files) {
            TarArchiveEntry tarEntry = new TarArchiveEntry(file);
            tarEntry.setName("/" + getLast(Splitter.on(token).split(file.toString())));
            tos.putArchiveEntry(tarEntry);
            if (!file.isDirectory()) {
                Files.asByteSource(file).copyTo(tos);
            }
            tos.closeArchiveEntry();
        }
    } finally {
        tos.close();
    }
    return tarFile;
}

From source file:org.xenmaster.web.SetupHook.java

protected void writePluginsToTarball(TarArchiveOutputStream tos) throws IOException {
    File f = new File("store/xapi/plugins");
    if (!f.exists() || !f.isDirectory()) {
        throw new IOException("Plugin directory is not present");
    }//from   w w w. ja v  a 2  s .c om

    for (File plugin : f.listFiles()) {
        TarArchiveEntry tae = new TarArchiveEntry(plugin);
        tae.setName(plugin.getName());
        tae.setUserId(0);
        tae.setMode(0755);
        tos.putArchiveEntry(tae);
        IOUtils.copy(new FileInputStream(plugin), tos);
        tos.closeArchiveEntry();
    }
}