/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  org.apache.tomcat.util.net.Nio2Channel
 *  org.apache.tomcat.util.net.SocketBufferHandler
 *  org.apache.tomcat.util.net.SocketWrapperBase
 */
package com.l7tech.server.tomcat.nio2;

import com.l7tech.server.tomcat.TraceChannel;
import com.l7tech.server.tomcat.nio2.SsgNio2Endpoint;
import com.l7tech.server.tomcat.nio2.a;
import com.l7tech.server.tomcat.nio2.b;
import com.l7tech.server.tomcat.nio2.c;
import com.l7tech.server.tomcat.nio2.d;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.CompletionHandler;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import org.apache.tomcat.util.net.Nio2Channel;
import org.apache.tomcat.util.net.SocketBufferHandler;
import org.apache.tomcat.util.net.SocketWrapperBase;

class i
extends Nio2Channel {
    private TraceChannel a;
    private TraceChannel b;
    private static final String[] c;

    i(SsgNio2Endpoint ssgNio2Endpoint, SocketBufferHandler socketBufferHandler) {
        super(socketBufferHandler);
    }

    public void reset(AsynchronousSocketChannel asynchronousSocketChannel, SocketWrapperBase<Nio2Channel> socketWrapperBase) throws IOException {
        super.reset(asynchronousSocketChannel, socketWrapperBase);
        String[] stringArray = c;
        this.a = new TraceChannel(stringArray[0], false);
        this.b = new TraceChannel(stringArray[1], false);
    }

    public void close() throws IOException {
        this.a.close();
        this.b.close();
        super.close();
    }

    private Future<Integer> a(Future<Integer> future, Function<Integer, Integer> function) {
        if (future instanceof CompletableFuture) {
            return ((CompletableFuture)future).thenApply(function);
        }
        return CompletableFuture.completedFuture(null).thenCompose(arg_0 -> i.lambda$withCompletableFuture$0(future, function, arg_0));
    }

    public Future<Integer> read(ByteBuffer byteBuffer) {
        return this.a(super.read(byteBuffer), arg_0 -> this.lambda$read$1(byteBuffer, arg_0));
    }

    public <A> void read(ByteBuffer byteBuffer, long l2, TimeUnit timeUnit, A a10, CompletionHandler<Integer, ? super A> completionHandler) {
        if (this.a.traceEnabled()) {
            super.read(byteBuffer, l2, timeUnit, a10, (CompletionHandler)new a(this, byteBuffer, completionHandler));
        } else {
            super.read(byteBuffer, l2, timeUnit, a10, completionHandler);
        }
    }

    public <A> void read(ByteBuffer[] byteBufferArray, int n2, int n3, long l2, TimeUnit timeUnit, A a10, CompletionHandler<Long, ? super A> completionHandler) {
        if (this.a.traceEnabled()) {
            super.read(byteBufferArray, n2, n3, l2, timeUnit, a10, (CompletionHandler)new b(this, byteBufferArray, n2, n3, completionHandler));
        } else {
            super.read(byteBufferArray, n2, n3, l2, timeUnit, a10, completionHandler);
        }
    }

    public Future<Integer> write(ByteBuffer byteBuffer) {
        return this.a(super.write(byteBuffer), arg_0 -> this.lambda$write$2(byteBuffer, arg_0));
    }

    public <A> void write(ByteBuffer byteBuffer, A a10, CompletionHandler<Integer, ? super A> completionHandler) {
        super.write(byteBuffer, a10, (CompletionHandler)new c(this, byteBuffer, completionHandler));
    }

    public <A> void write(ByteBuffer[] byteBufferArray, int n2, int n3, long l2, TimeUnit timeUnit, A a10, CompletionHandler<Long, ? super A> completionHandler) {
        if (this.b.traceEnabled()) {
            super.write(byteBufferArray, n2, n3, l2, timeUnit, a10, (CompletionHandler)new d(this, byteBufferArray, n2, n3, completionHandler));
        } else {
            super.write(byteBufferArray, n2, n3, l2, timeUnit, a10, completionHandler);
        }
    }

    private Integer lambda$write$2(ByteBuffer byteBuffer, Integer n2) {
        return this.b.trace(byteBuffer, 0, n2);
    }

    private Integer lambda$read$1(ByteBuffer byteBuffer, Integer n2) {
        return this.a.trace(byteBuffer, 0, n2);
    }

    private static CompletionStage lambda$withCompletableFuture$0(Future future, Function function, Object object) {
        try {
            return CompletableFuture.completedFuture((Integer)future.get()).thenApply(function);
        }
        catch (InterruptedException interruptedException) {
            return CompletableFuture.failedFuture(interruptedException);
        }
        catch (ExecutionException executionException) {
            return CompletableFuture.failedFuture(executionException.getCause());
        }
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[2];
        int n2 = 0;
        String string = "\n\u0013A^0R]h\t\n\u0013A^0TF\u0016m";
        int n3 = "\n\u0013A^0R]h\t\n\u0013A^0TF\u0016m".length();
        int n4 = 8;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = i.a(64, i.a(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                c = stringArray;
                return;
            }
            n4 = string.charAt(n5);
        }
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x73);
        }
        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 -> 34;
                    case 1 -> 39;
                    case 2 -> 117;
                    case 3 -> 110;
                    case 4 -> 93;
                    case 5 -> 123;
                    default -> 115;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

