Search in sources :

Example 1 with TarInputStream

use of hudson.org.apache.tools.tar.TarInputStream in project hudson-2.x by hudson.

the class FilePath method readFromTar.

/**
     * Reads from a tar stream and stores obtained files to the base dir.
     */
private static void readFromTar(String name, File baseDir, InputStream in) throws IOException {
    TarInputStream t = new TarInputStream(in);
    try {
        TarEntry te;
        while ((te = t.getNextEntry()) != null) {
            File f = new File(baseDir, te.getName());
            if (te.isDirectory()) {
                f.mkdirs();
            } else {
                File parent = f.getParentFile();
                if (parent != null)
                    parent.mkdirs();
                IOUtils.copy(t, f);
                f.setLastModified(te.getModTime().getTime());
                int mode = te.getMode() & 0777;
                if (// be defensive
                mode != 0 && !Functions.isWindows())
                    _chmod(f, mode);
            }
        }
    } catch (IOException e) {
        throw new IOException2("Failed to extract " + name, e);
    } finally {
        t.close();
    }
}
Also used : TarInputStream(hudson.org.apache.tools.tar.TarInputStream) TarEntry(org.apache.tools.tar.TarEntry) IOException(java.io.IOException) File(java.io.File) IOException2(hudson.util.IOException2)

Aggregations

TarInputStream (hudson.org.apache.tools.tar.TarInputStream)1 IOException2 (hudson.util.IOException2)1 File (java.io.File)1 IOException (java.io.IOException)1 TarEntry (org.apache.tools.tar.TarEntry)1