/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.util.ShutdownExceptionHandler
 *  jakarta.servlet.ReadListener
 *  jakarta.servlet.ServletInputStream
 */
package com.l7tech.server.transport.http;

import com.l7tech.server.transport.http.m;
import com.l7tech.server.transport.http.n;
import com.l7tech.server.transport.http.o;
import com.l7tech.util.ShutdownExceptionHandler;
import jakarta.servlet.ReadListener;
import jakarta.servlet.ServletInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level;
import java.util.logging.Logger;

public class TimeoutInputStream
extends ServletInputStream {
    private static final Logger a;
    private static final long b = 20000L;
    private static final long c = 20000L;
    private static final int d = 1024;
    private static final Queue<m> e;
    private static final Object f;
    private static Exception g;
    private static Thread h;
    private ServletInputStream i;
    private m j;
    private ReentrantLock k;
    private static final String[] l;

    public TimeoutInputStream(ServletInputStream servletInputStream) throws IOException {
        this(servletInputStream, 20000L, 20000L, 1024);
    }

    public TimeoutInputStream(InputStream inputStream, long l2, long l3, int n2) throws IOException {
        this((ServletInputStream)inputStream, l2, l3, n2);
    }

    public TimeoutInputStream(ServletInputStream servletInputStream, long l2, long l3, int n2) throws IOException {
        if (servletInputStream == null) {
            throw new IOException(l[4]);
        }
        this.i = servletInputStream;
        this.j = new m((InputStream)((Object)this), l2, l3, n2);
        this.k = new ReentrantLock();
        e.add(this.j);
    }

    public int read() throws IOException {
        this.enterBlocking();
        try {
            a.log(Level.FINEST, l[2]);
            int n2 = this.trackBytes(this.i.read());
            return n2;
        }
        finally {
            this.exitBlocking();
        }
    }

    public int read(byte[] byArray) throws IOException {
        this.enterBlocking();
        try {
            a.log(Level.FINEST, l[1], byArray.length);
            int n2 = this.trackBytes(this.i.read(byArray));
            return n2;
        }
        finally {
            this.exitBlocking();
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public int read(byte[] byArray, int n2, int n3) throws IOException {
        this.enterBlocking();
        try {
            a.log(Level.FINEST, l[3], n3);
            int n4 = this.trackBytes(this.i.read(byArray, n2, n3));
            return n4;
        }
        finally {
            this.exitBlocking();
        }
    }

    public int readLine(byte[] byArray, int n2, int n3) throws IOException {
        this.enterBlocking();
        try {
            String[] stringArray = l;
            a.log(Level.FINEST, stringArray[1], n3);
            int n4 = this.trackBytes(this.i.readLine(byArray, n2, n3));
            return n4;
        }
        catch (ClassCastException classCastException) {
            throw new UnsupportedOperationException(l[6]);
        }
        finally {
            this.exitBlocking();
        }
    }

    public boolean isFinished() {
        return this.i.isFinished();
    }

    public boolean isReady() {
        return this.i.isReady();
    }

    public void setReadListener(ReadListener readListener) {
        this.i.setReadListener(readListener);
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public long skip(long l2) throws IOException {
        this.enterBlocking();
        try {
            long l3 = this.trackBytes(this.i.skip(l2));
            return l3;
        }
        finally {
            this.exitBlocking();
        }
    }

    public int available() throws IOException {
        this.d();
        return this.i.available();
    }

    public void close() throws IOException {
        try {
            if (!this.j.g()) {
                this.i.close();
                this.doneBlocking();
            }
        }
        catch (IOException iOException) {
            throw TimeoutInputStream.a(iOException);
        }
    }

    public synchronized void mark(int n2) {
        this.i.mark(n2);
    }

    public synchronized void reset() throws IOException {
        this.d();
        this.i.reset();
    }

    public boolean markSupported() {
        return this.i.markSupported();
    }

    public final void done() {
        a.log(Level.FINEST, l[7]);
        this.j.d();
    }

    protected final void enterBlocking() throws IOException {
        this.a();
        try {
            this.d();
        }
        catch (IOException iOException) {
            this.b();
            throw iOException;
        }
        try {
            if (this.c()) {
                this.j.a();
            }
        }
        catch (IOException iOException) {
            throw TimeoutInputStream.a(iOException);
        }
    }

    protected final void exitBlocking() throws IOException {
        try {
            try {
                if (this.c()) {
                    this.j.b();
                }
            }
            catch (IOException iOException) {
                throw TimeoutInputStream.a(iOException);
            }
            this.d();
        }
        finally {
            this.b();
        }
    }

    protected final void doneBlocking() {
        this.j.c();
    }

    protected final int trackBytes(int n2) {
        this.j.a(n2);
        return n2;
    }

    protected final long trackBytes(long l2) {
        this.j.a(l2);
        return l2;
    }

    private void a() {
        this.k.lock();
    }

    private void b() {
        this.k.unlock();
    }

    private boolean c() {
        boolean bl2;
        try {
            bl2 = this.k.getHoldCount() == 1;
        }
        catch (ClassCastException classCastException) {
            throw TimeoutInputStream.a(classCastException);
        }
        return bl2;
    }

    private void d() throws IOException {
        try {
            if (this.j.g()) {
                throw new TimeoutIOException();
            }
        }
        catch (IOException iOException) {
            throw TimeoutInputStream.a(iOException);
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     * Unable to fully structure code
     */
    static {
        block13: {
            block12: {
                var5 = new String[8];
                var3_1 = 0;
                var2_2 = "\u001e{>`DO\u0013:p!`DO\u0012%p/qgz\u000e4}*zW\u0019\u0000t'aYu\u001dwa!5B~\u001b355%M;\u0018.a+f\u0016\u0000t'aYu\u001dwa!5B~\u001b35\u007f5Rb\u000e2\u0019\u0000t'aYu\u001dwa!5B~\u001b355%M;\u0018.a+f\u00109`\"y\u0010r\u0014'`:FDi\u001f6x\u0012\u001e{>`DO\u0013:p!`DO\u0012%p/q";
                var4_3 = "\u001e{>`DO\u0013:p!`DO\u0012%p/qgz\u000e4}*zW\u0019\u0000t'aYu\u001dwa!5B~\u001b355%M;\u0018.a+f\u0016\u0000t'aYu\u001dwa!5B~\u001b35\u007f5Rb\u000e2\u0019\u0000t'aYu\u001dwa!5B~\u001b355%M;\u0018.a+f\u00109`\"y\u0010r\u0014'`:FDi\u001f6x\u0012\u001e{>`DO\u0013:p!`DO\u0012%p/q".length();
                var1_4 = 26;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = TimeoutInputStream.a(v0, TimeoutInputStream.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "3M\u001b\u0005uE.\u0002W\u0012\\iE-GV\nWeJ'GA\u0011@s\u000b$\bQ^Vu[:\bW\n\u0005rN+\u0003i\u0017Ke\n\u0017!L\u0010LsC/\u0003\u0005\f@aO#\tB^VtY/\u0006H";
                    var4_3 = "3M\u001b\u0005uE.\u0002W\u0012\\iE-GV\nWeJ'GA\u0011@s\u000b$\bQ^Vu[:\bW\n\u0005rN+\u0003i\u0017Ke\n\u0017!L\u0010LsC/\u0003\u0005\f@aO#\tB^VtY/\u0006H".length();
                    var1_4 = 48;
                    var0_5 = -1;
lbl22:
                    // 2 sources

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

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

                ** continue;
            }
        }
        TimeoutInputStream.l = var5;
        TimeoutInputStream.a = Logger.getLogger(TimeoutInputStream.class.getName());
        TimeoutInputStream.e = new ConcurrentLinkedQueue<m>();
        TimeoutInputStream.f = new Object();
        TimeoutInputStream.g = null;
        TimeoutInputStream.h = null;
        var6_7 = TimeoutInputStream.f;
        synchronized (var6_7) {
            TimeoutInputStream.h = new Thread(new n());
            TimeoutInputStream.h.setDaemon(true);
            var0_6 = TimeoutInputStream.l;
            TimeoutInputStream.h.setName(var0_6[5]);
            TimeoutInputStream.h.setUncaughtExceptionHandler((Thread.UncaughtExceptionHandler)ShutdownExceptionHandler.getInstance());
            TimeoutInputStream.h.start();
        }
        var6_7 = new Thread(new o());
        var6_7.setDaemon(true);
        var6_7.setName(TimeoutInputStream.l[0]);
        var6_7.setUncaughtExceptionHandler((Thread.UncaughtExceptionHandler)ShutdownExceptionHandler.getInstance());
        var6_7.start();
    }

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

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x20);
        }
        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 -> 13;
                    case 1 -> 79;
                    case 2 -> 20;
                    case 3 -> 79;
                    case 4 -> 106;
                    case 5 -> 65;
                    default -> 32;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }

    public static final class TimeoutIOException
    extends IOException {
        static final long serialVersionUID = 2838001492102031198L;
        private static final String a = TimeoutIOException.a(45, TimeoutIOException.a("\u000e!W/JF4)<H/D^`"));

        private TimeoutIOException() {
            super(a);
        }

        private static char[] a(String string) {
            char[] cArray = string.toCharArray();
            if (cArray.length < 2) {
                cArray = cArray;
                cArray[0] = (char)(cArray[0] ^ 0x39);
            }
            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 -> 112;
                        case 1 -> 120;
                        case 2 -> 8;
                        case 3 -> 103;
                        case 4 -> 6;
                        case 5 -> 6;
                        default -> 57;
                    })));
                    ++n3;
                    n4 = n4;
                } while (n4 > n3);
            }
            return new String(cArray2).intern();
        }
    }
}

