AdobeJarSupport.java 2.77 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.apache.commons.io.FileUtils
 *  org.apache.commons.io.IOUtils
 */
package com.adobe.aemds.bedrock.installer.internal;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

public class AdobeJarSupport {
    private JarInputStream jarStream = null;

    public AdobeJarSupport(InputStream inStream) throws IOException {
        this.jarStream = new JarInputStream(new BufferedInputStream(inStream));
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    private void unjar(File inDirectory, InputStream inJarStream, JarEntry inEntryName, boolean setSharedXbit) throws IOException {
        File destFile = null;
        int pos = inEntryName.getName().lastIndexOf(47);
        if (pos == -1) {
            pos = inEntryName.getName().lastIndexOf(File.separator);
        }
        if (pos != -1) {
            String path = inEntryName.getName().substring(0, pos);
            File destDir = new File(inDirectory, path);
            FileUtils.forceMkdir((File)destDir);
            destFile = new File(inDirectory, inEntryName.getName());
        } else {
            destFile = new File(inDirectory, inEntryName.getName());
        }
        if (!destFile.isDirectory()) {
            block9 : {
                if (destFile.exists() && destFile.canWrite() || destFile.createNewFile()) {
                    FileOutputStream destStream = null;
                    try {
                        destStream = new FileOutputStream(destFile);
                        if (inJarStream != null) {
                            IOUtils.copyLarge((InputStream)inJarStream, (OutputStream)destStream);
                        }
                        break block9;
                    }
                    finally {
                        IOUtils.closeQuietly((OutputStream)destStream);
                    }
                }
                throw new IOException("Can't unjar file '" + inEntryName.getName() + "' into directory '" + inDirectory + "'");
            }
            destFile.setLastModified(inEntryName.getTime());
        }
    }

    public void extractAll(File directory, boolean setSharedXbit) throws IOException {
        JarEntry entry;
        FileUtils.forceMkdir((File)directory);
        while ((entry = this.jarStream.getNextJarEntry()) != null) {
            this.unjar(directory, this.jarStream, entry, setSharedXbit);
        }
    }

    public void close() throws IOException {
        this.jarStream.close();
    }
}