/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.util.IOUtils
 *  com.l7tech.util.PoolByteArrayOutputStream
 *  com.l7tech.util.ResourceUtils
 */
package com.l7tech.server.policy.module;

import com.l7tech.util.IOUtils;
import com.l7tech.util.PoolByteArrayOutputStream;
import com.l7tech.util.ResourceUtils;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;

class g
implements Closeable {
    protected static final Logger logger;
    private final ZipFile a;
    private final String b;
    private final Map<String, Reference<byte[]>> c = new ConcurrentHashMap<String, Reference<byte[]>>();
    private final Set<String> d;
    private final Map<String, Long> e;
    private final boolean f;
    private static final String[] g;

    /*
     * Enabled aggressive block sorting
     * Enabled unnecessary exception pruning
     * Enabled aggressive exception aggregation
     */
    public g(ZipFile zipFile, String string, boolean bl2) throws IOException {
        if (zipFile == null) throw new NullPointerException();
        try {
            if (string == null) {
                throw new NullPointerException();
            }
        }
        catch (Throwable throwable) {
            throw com.l7tech.server.policy.module.g.a(throwable);
        }
        this.a = zipFile;
        this.b = string;
        ZipEntry zipEntry = zipFile.getEntry(string);
        try {
            if (zipEntry == null) {
                throw new IOException(g[4] + string + g[3] + zipFile.getName());
            }
        }
        catch (Throwable throwable) {
            throw com.l7tech.server.policy.module.g.a(throwable);
        }
        Object object = zipFile.getInputStream(zipEntry);
        try {
            if (object == null) {
                String[] stringArray = g;
                throw new IOException(stringArray[5] + string + stringArray[2] + zipFile.getName());
            }
        }
        catch (Throwable throwable) {
            if (object == null) throw throwable;
            try {
                ((InputStream)object).close();
                throw throwable;
            }
            catch (Throwable throwable2) {
                throwable.addSuppressed(throwable2);
            }
            throw throwable;
        }
        try {
            if (object != null) {
                ((InputStream)object).close();
            }
        }
        catch (Throwable throwable) {
            throw com.l7tech.server.policy.module.g.a(throwable);
        }
        object = new HashSet();
        HashMap<String, Long> hashMap = new HashMap<String, Long>();
        this.a(null, (Set<String>)object, hashMap);
        this.d = Collections.unmodifiableSet(object);
        this.e = Collections.unmodifiableMap(hashMap);
        this.f = bl2;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     * Unable to fully structure code
     */
    private synchronized byte[] a(String var1_1, Set<String> var2_2, Map<String, Long> var3_3) throws IOException {
        var4_4 = this.a.getEntry(this.b);
        try {
            if (var4_4 == null) {
                throw new IOException(com.l7tech.server.policy.module.g.g[0] + this.b + com.l7tech.server.policy.module.g.g[2] + this.a.getName());
            }
        }
        catch (IOException v0) {
            throw com.l7tech.server.policy.module.g.a(v0);
        }
        var5_5 = this.a.getInputStream(var4_4);
        try {
            if (var5_5 == null) {
                throw new IOException(com.l7tech.server.policy.module.g.g[1] + this.b + com.l7tech.server.policy.module.g.g[2] + this.a.getName());
            }
        }
        catch (IOException v1) {
            throw com.l7tech.server.policy.module.g.a(v1);
        }
        var6_6 = null;
        var7_7 = null;
        try {
            var7_7 = new ZipInputStream(var5_5);
            while (true) lbl-1000:
            // 6 sources

            {
                block21: {
                    var8_8 = var7_7.getNextEntry();
                    if (var8_8 == null) ** break;
                    try {
                        block22: {
                            if (!var8_8.isDirectory()) break block21;
                            break block22;
                            catch (IOException v2) {
                                throw com.l7tech.server.policy.module.g.a(v2);
                            }
                        }
                        if (var2_2 == null) continue;
                    }
                    catch (IOException v3) {
                        throw com.l7tech.server.policy.module.g.a(v3);
                    }
                    var2_2.add(var8_8.getName());
                    continue;
                }
                try {
                    if (var3_3 != null) {
                        var3_3.put(var8_8.getName(), var8_8.getSize());
                    }
                }
                catch (IOException v4) {
                    throw com.l7tech.server.policy.module.g.a(v4);
                }
                var9_9 = new PoolByteArrayOutputStream();
                try {
                    IOUtils.copyStream((InputStream)var7_7, (OutputStream)var9_9);
                    var10_10 = var9_9.toByteArray();
                    try {
                        this.c.put(var8_8.getName(), new SoftReference<byte[]>(var10_10));
                        if (var1_1 == null || !var1_1.equals(var8_8.getName())) ** GOTO lbl-1000
                    }
                    catch (IOException v5) {
                        throw com.l7tech.server.policy.module.g.a(v5);
                    }
                    var6_6 = var10_10;
                }
                finally {
                    var9_9.close();
                    continue;
                }
                break;
            }
        }
        catch (Throwable var12_12) {
            ResourceUtils.closeQuietly(var7_7);
            throw var12_12;
        }
        ** GOTO lbl-1000
        ResourceUtils.closeQuietly((Closeable)var7_7);
        return var6_6;
    }

    ZipFile a() {
        return this.a;
    }

    public String getEntryName() {
        return this.b;
    }

    public Set<String> getFiles() {
        return Collections.unmodifiableSet(this.c.keySet());
    }

    public Set<String> getDirectories() {
        return Collections.unmodifiableSet(this.d);
    }

    public byte[] getFile(String string) throws IOException {
        byte[] byArray;
        Reference<byte[]> reference = this.c.get(string);
        try {
            byArray = reference == null ? null : reference.get();
        }
        catch (IOException iOException) {
            throw com.l7tech.server.policy.module.g.a(iOException);
        }
        byte[] byArray2 = byArray;
        try {
            if (byArray2 != null) {
                return byArray2;
            }
        }
        catch (IOException iOException) {
            throw com.l7tech.server.policy.module.g.a(iOException);
        }
        try {
            if (!this.e.containsKey(string)) {
                return null;
            }
        }
        catch (IOException iOException) {
            throw com.l7tech.server.policy.module.g.a(iOException);
        }
        return this.a(string, null, null);
    }

    @Override
    public void close() throws IOException {
        this.c.clear();
    }

    public boolean isPrivateLibrary() {
        return this.f;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[6];
                var3_1 = 0;
                var2_2 = "X\u0010-\\\u0019.&y\u0011lX\u001c%b-\u0010)M\u0001.b-\u0004%N\u0013\"jh^)P\u00019\u007f7^+c\u000b RU\u0002h}\u000b8m\u00019cl\u0013lX\u001a9&c\u001b?J\u0010/&w\u0017<X\u001c'c-\u001b\"J\u00072<-\u000e-\u0017\"\u001e\u000f\"v-\u0018%R\u0010q&\u000e-\u0017\"\u001e\u000f\"v-\u0018%R\u0010q&";
                var4_3 = "X\u0010-\\\u0019.&y\u0011lX\u001c%b-\u0010)M\u0001.b-\u0004%N\u0013\"jh^)P\u00019\u007f7^+c\u000b RU\u0002h}\u000b8m\u00019cl\u0013lX\u001a9&c\u001b?J\u0010/&w\u0017<X\u001c'c-\u001b\"J\u00072<-\u000e-\u0017\"\u001e\u000f\"v-\u0018%R\u0010q&\u000e-\u0017\"\u001e\u000f\"v-\u0018%R\u0010q&".length();
                var1_4 = 37;
                var0_5 = -1;
lbl7:
                // 2 sources

                while (true) {
                    v0 = 61;
                    v1 = ++var0_5;
                    v2 = var2_2.substring(v1, v1 + var1_4);
                    v3 = -1;
                    break block9;
                    break;
                }
lbl13:
                // 1 sources

                while (true) {
                    var5[var3_1++] = com.l7tech.server.policy.module.g.a(v0, com.l7tech.server.policy.module.g.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "6~C2w@H\u0017\u007f\u00026rK\fC~G#o@\fCjK }L\u0004\u00060G>oW\u0011Y0+\reN<;l\u0006\u0013eV\u0003oW\r\u0002}\u00026tWH\ruQ$~AH\u0019yR6rI\rCuL$i\\RC";
                    var4_3 = "6~C2w@H\u0017\u007f\u00026rK\fC~G#o@\fCjK }L\u0004\u00060G>oW\u0011Y0+\reN<;l\u0006\u0013eV\u0003oW\r\u0002}\u00026tWH\ruQ$~AH\u0019yR6rI\rCuL$i\\RC".length();
                    var1_4 = 37;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 83;
                        v4 = ++var0_5;
                        v2 = var2_2.substring(v4, v4 + var1_4);
                        v3 = 0;
                        break block9;
                        break;
                    }
                    break;
                }
lbl28:
                // 1 sources

                while (true) {
                    var5[var3_1++] = com.l7tech.server.policy.module.g.a(v0, com.l7tech.server.policy.module.g.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    break block10;
                    break;
                }
            }
            switch (v3) {
                default: {
                    ** continue;
                }
                ** case 0:
lbl39:
                // 1 sources

                ** continue;
            }
        }
        com.l7tech.server.policy.module.g.g = var5;
        com.l7tech.server.policy.module.g.logger = Logger.getLogger(g.class.getName());
    }

    private static Throwable a(Throwable throwable) {
        return throwable;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x3B);
        }
        return cArray;
    }

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String a(int n2, char[] cArray) {
        char[] cArray2;
        block11: {
            int n3;
            int n4;
            int n5;
            block10: {
                n5 = n2;
                cArray2 = cArray;
                n4 = cArray.length;
                n3 = 0;
                if (!true) break block10;
                n4 = n4;
                if (n4 <= n3) break block11;
            }
            do {
                n5 = n5;
                cArray2 = cArray2;
                int n6 = n3;
                cArray2[n6] = (char)(cArray2[n6] ^ (n5 ^ (switch (n3 % 7) {
                    case 0 -> 48;
                    case 1 -> 67;
                    case 2 -> 113;
                    case 3 -> 3;
                    case 4 -> 72;
                    case 5 -> 118;
                    default -> 59;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

