/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.util.Charsets
 *  org.apache.mina.core.buffer.IoBuffer
 *  org.apache.mina.core.session.IoSession
 *  org.apache.mina.filter.codec.ProtocolEncoderAdapter
 *  org.apache.mina.filter.codec.ProtocolEncoderOutput
 */
package com.l7tech.server.log.syslog.impl;

import com.l7tech.server.log.syslog.impl.d;
import com.l7tech.util.Charsets;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;

class h
extends ProtocolEncoderAdapter {
    private static final String a;
    private static final d b;

    h() {
    }

    public void encode(IoSession ioSession, Object object, ProtocolEncoderOutput protocolEncoderOutput) throws Exception {
        String string;
        int n2;
        String string2;
        Charset charset;
        Object object2;
        if (object instanceof d) {
            object2 = (d)object;
            charset = ((d)object2).a;
            string2 = ((d)object2).b;
            n2 = ((d)object2).c;
            string = ((d)object2).d;
        } else {
            charset = h.b.a;
            string2 = h.b.b;
            n2 = h.b.c;
            string = object.toString();
        }
        object2 = (CharsetEncoder)ioSession.getAttribute((Object)(a + charset.name()));
        if (object2 == null) {
            object2 = charset.newEncoder();
            ioSession.setAttribute((Object)(a + charset.name()), object2);
        }
        IoBuffer ioBuffer = IoBuffer.allocate((int)string.length()).setAutoExpand(true);
        ioBuffer.putString((CharSequence)string, (CharsetEncoder)object2);
        int n3 = ioBuffer.position();
        try {
            ioBuffer.putString((CharSequence)string2, (CharsetEncoder)object2);
            if (ioBuffer.position() > n2) {
                ioBuffer.position(n2 - (ioBuffer.position() - n3));
                ioBuffer.putString((CharSequence)string2, (CharsetEncoder)object2);
            }
        }
        catch (Exception exception) {
            throw h.a(exception);
        }
        ioBuffer.flip();
        protocolEncoderOutput.write((Object)ioBuffer);
    }

    /*
     * Enabled aggressive block sorting
     */
    static {
        String[] stringArray = new String[2];
        int n2 = 0;
        String string = "R\b\tqgIKc=\u007f-,";
        int n3 = "R\b\tqgIKc=\u007f-,".length();
        int n4 = 2;
        int n5 = -1;
        while (true) {
            int n6 = ++n5;
            stringArray[n2++] = h.a(100, h.a(string.substring(n6, n6 + n4)));
            if ((n5 += n4) >= n3) {
                a = h.class.getName() + stringArray[1];
                b = new d(Charsets.UTF8, stringArray[0], 1024, null);
                return;
            }
            n4 = string.charAt(n5);
        }
    }

    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] ^ 0x7E);
        }
        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 -> 59;
                    case 1 -> 102;
                    case 2 -> 67;
                    case 3 -> 76;
                    case 4 -> 104;
                    case 5 -> 61;
                    default -> 126;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

