/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.objectmodel.Goid
 *  com.l7tech.util.OpaqueId
 */
package com.l7tech.server.audit;

import com.l7tech.objectmodel.Goid;
import com.l7tech.server.audit.AuditDownloadManager;
import com.l7tech.server.audit.AuditExporter;
import com.l7tech.server.audit.ax;
import com.l7tech.server.audit.r;
import com.l7tech.server.audit.s;
import com.l7tech.util.OpaqueId;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.security.PrivateKey;
import java.security.cert.X509Certificate;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;

class q {
    private final OpaqueId a = new OpaqueId();
    private final X509Certificate b;
    private final PrivateKey c;
    private final PipedOutputStream d = new PipedOutputStream();
    private final PipedInputStream e = new PipedInputStream(this.d);
    private final Timer f;
    private final long g;
    private final long h;
    private final Goid[] i;
    private final int j;
    private final Thread k;
    private final AuditExporter l;
    private volatile Throwable m;
    private long n;
    private final Object o;
    private static final String[] p;

    private q(long l2, long l3, Goid[] goidArray, int n2, AuditExporter auditExporter, X509Certificate x509Certificate, PrivateKey privateKey) throws IOException {
        String[] stringArray = p;
        this.f = new Timer(stringArray[1], true);
        this.k = new Thread(new r(this));
        this.m = null;
        this.n = System.currentTimeMillis();
        this.o = new Object();
        if (n2 < 1) {
            n2 = 8192;
        }
        this.g = l2;
        this.h = l3;
        this.i = goidArray;
        this.j = n2;
        this.b = x509Certificate;
        this.c = privateKey;
        this.l = auditExporter;
        this.k.start();
        AuditDownloadManager.a.info(p[9] + String.valueOf(this));
    }

    synchronized OpaqueId a() {
        return this.a;
    }

    synchronized long b() {
        return this.n;
    }

    synchronized InputStream c() {
        return this.e;
    }

    private synchronized void d() {
        this.n = System.currentTimeMillis();
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     * Loose catch block
     */
    private s a(PipedInputStream pipedInputStream, byte[] byArray, long l2) throws IOException {
        int n2 = 0;
        Thread thread = Thread.currentThread();
        boolean[] blArray = new boolean[]{true};
        Object object = this;
        synchronized (object) {
            blArray[0] = true;
        }
        object = new ax(this, blArray, thread);
        try {
            int n3;
            this.f.schedule((TimerTask)object, l2);
            for (int i2 = byArray.length; i2 > 0; i2 -= n3) {
                block32: {
                    n3 = pipedInputStream.read(byArray, n2, i2);
                    if (n3 >= 0) break block32;
                    s s2 = new s(this, n2, true);
                    return s2;
                }
                try {
                    try {
                        if (n3 == 0) {
                            Thread.sleep(250L);
                        }
                    }
                    catch (InterruptedIOException interruptedIOException) {
                        throw q.a(interruptedIOException);
                    }
                    n2 += n3;
                    continue;
                }
                catch (InterruptedIOException interruptedIOException) {
                    s s3 = new s(this, n2, false);
                    q q2 = this;
                    synchronized (q2) {
                        blArray[0] = false;
                        ((TimerTask)object).cancel();
                        Thread.interrupted();
                    }
                    return s3;
                }
                catch (InterruptedException interruptedException) {
                    s s4 = new s(this, n2, false);
                    q q3 = this;
                    synchronized (q3) {
                        blArray[0] = false;
                        ((TimerTask)object).cancel();
                        Thread.interrupted();
                    }
                    return s4;
                }
            }
            s s5 = new s(this, n2, false);
            return s5;
            {
                catch (Throwable throwable) {
                    throw throwable;
                }
            }
        }
        finally {
            q q4 = this;
            synchronized (q4) {
                blArray[0] = false;
                ((TimerTask)object).cancel();
                Thread.interrupted();
            }
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    private byte[] e() {
        Object object = this.o;
        synchronized (object) {
            return this.h();
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    private long f() {
        long l2 = 1L;
        q q2 = this;
        synchronized (q2) {
            if (this.l != null) {
                l2 = this.l.getApproxNumToExport();
            }
        }
        return l2;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    private long g() {
        long l2 = 0L;
        q q2 = this;
        synchronized (q2) {
            if (this.l != null) {
                l2 = this.l.getNumExportedSoFar();
            }
        }
        return l2;
    }

    private byte[] h() {
        this.d();
        this.checkForException();
        byte[] byArray = new byte[this.j];
        try {
            int n2;
            block8: {
                s s2 = this.a(this.e, byArray, 10000L);
                String[] stringArray = p;
                AuditDownloadManager.a.log(Level.FINER, stringArray[2] + String.valueOf(this));
                n2 = s2.a;
                try {
                    if (!s2.b) break block8;
                    this.k.join(5000L);
                    this.checkForException();
                    if (n2 != 0) break block8;
                }
                catch (IOException iOException) {
                    throw q.a(iOException);
                }
                return null;
            }
            byte[] byArray2 = new byte[n2];
            try {
                if (n2 > 0) {
                    System.arraycopy(byArray, 0, byArray2, 0, n2);
                }
            }
            catch (IOException iOException) {
                throw q.a(iOException);
            }
            this.d();
            this.checkForException();
            return byArray2;
        }
        catch (IOException iOException) {
            this.close();
            String[] stringArray = p;
            throw new RuntimeException(stringArray[4], iOException);
        }
        catch (InterruptedException interruptedException) {
            this.close();
            throw new RuntimeException(p[8], interruptedException);
        }
    }

    public void checkForException() {
        Throwable throwable = this.getProducerException();
        try {
            if (throwable != null) {
                this.close();
                throw new RuntimeException(p[6] + throwable.getMessage(), throwable);
            }
        }
        catch (RuntimeException runtimeException) {
            throw q.a(runtimeException);
        }
    }

    public synchronized void close() {
        AuditDownloadManager.a.log(Level.INFO, p[7] + String.valueOf(this));
        AuditDownloadManager.d.remove(this.a());
        try {
            this.k.interrupt();
        }
        catch (Throwable throwable) {
            // empty catch block
        }
        try {
            this.e.close();
        }
        catch (Throwable throwable) {
            // empty catch block
        }
        try {
            this.d.close();
        }
        catch (Throwable throwable) {
            // empty catch block
        }
    }

    public synchronized boolean equals(Object object) {
        try {
            if (this == object) {
                return true;
            }
        }
        catch (RuntimeException runtimeException) {
            throw q.a(runtimeException);
        }
        try {
            if (!(object instanceof q)) {
                return false;
            }
        }
        catch (RuntimeException runtimeException) {
            throw q.a(runtimeException);
        }
        q q2 = (q)object;
        try {
            if (!this.a.equals((Object)q2.a)) {
                return false;
            }
        }
        catch (RuntimeException runtimeException) {
            throw q.a(runtimeException);
        }
        return true;
    }

    public synchronized int hashCode() {
        return this.a.hashCode();
    }

    public synchronized String toString() {
        String string = String.valueOf(new Date(this.h));
        String string2 = String.valueOf(new Date(this.g));
        String string3 = this.a.toString();
        String[] stringArray = p;
        return stringArray[0] + string3 + stringArray[3] + string2 + stringArray[5] + string + "]";
    }

    public synchronized Throwable getProducerException() {
        return this.m;
    }

    public synchronized void setProducerException(Throwable throwable) {
        this.m = throwable;
    }

    private static Exception a(Exception exception) {
        return exception;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[10];
                var3_1 = 0;
                var2_2 = "_=\n\u0005\u0001^\u000b\u007f\u0011\u0012\u0005\u0019T\u0012ozT0\u0004UW\u0014_=\n\u0005\u0001^\u000b\u007f\u0011\u0012\u0005\u0019T\u0012o\u0006\u0014\u0006\bC0I7\t\u001e\u001f_\u0003u5]\u0005\bI\u001e;3\b\u000f\u0004EJ\u007f=\n\u0005\u0001^\u000b\u007fr\u001e\u0003\u0018_\u0001;4\u0012\u0019MR\u0005u&\u0018\u0013\u0019\u0011\u00077r\u001b\u0019\u0002\\W$N<\u001c\t\u0001TJo=]\u0019\bP\u000e;7\u0005\u001b\u0002C\u001e~6]\n\u0018U\u0003or\u000e\u001f\u001fT\u000bv\u0005 r\t\u0004P&Z'\u0019\u0002\u0019\u0011Da;\rK\u001dC\u0005\u007f'\u001e\u000e\u001f\u0011\u001es \u0018\n\t\u0011\u000fc1\u0018\u001b\u0019X\u0005uh]\u001fX>\u0012\u0018\u0004_\r;3\b\u000f\u0004EJ\u007f=\n\u0005\u0001^\u000b\u007fr\u001e\u0004\u0003E\u000fc&]";
                var4_3 = "_=\n\u0005\u0001^\u000b\u007f\u0011\u0012\u0005\u0019T\u0012ozT0\u0004UW\u0014_=\n\u0005\u0001^\u000b\u007f\u0011\u0012\u0005\u0019T\u0012o\u0006\u0014\u0006\bC0I7\t\u001e\u001f_\u0003u5]\u0005\bI\u001e;3\b\u000f\u0004EJ\u007f=\n\u0005\u0001^\u000b\u007fr\u001e\u0003\u0018_\u0001;4\u0012\u0019MR\u0005u&\u0018\u0013\u0019\u0011\u00077r\u001b\u0019\u0002\\W$N<\u001c\t\u0001TJo=]\u0019\bP\u000e;7\u0005\u001b\u0002C\u001e~6]\n\u0018U\u0003or\u000e\u001f\u001fT\u000bv\u0005 r\t\u0004P&Z'\u0019\u0002\u0019\u0011Da;\rK\u001dC\u0005\u007f'\u001e\u000e\u001f\u0011\u001es \u0018\n\t\u0011\u000fc1\u0018\u001b\u0019X\u0005uh]\u001fX>\u0012\u0018\u0004_\r;3\b\u000f\u0004EJ\u007f=\n\u0005\u0001^\u000b\u007fr\u001e\u0004\u0003E\u000fc&]".length();
                var1_4 = 21;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = q.a(v0, q.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "3Aat|)7\u0012@ du-sFJxf\u007f>c\u0003K we(~\u0012\u000fsbb)v\u000b\u001f%]ewd)sFNury87\u0002@wx|#v\u0002\u000fcy~8r\u001e[ ";
                    var4_3 = "3Aat|)7\u0012@ du-sFJxf\u007f>c\u0003K we(~\u0012\u000fsbb)v\u000b\u001f%]ewd)sFNury87\u0002@wx|#v\u0002\u000fcy~8r\u001e[ ".length();
                    var1_4 = 36;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 60;
                        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++] = q.a(v0, q.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;
            }
        }
        q.p = var5;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x2B);
        }
        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 -> 90;
                    case 1 -> 19;
                    case 2 -> 60;
                    case 3 -> 42;
                    case 4 -> 44;
                    case 5 -> 112;
                    default -> 43;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

