/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.mime.ContentTypeHeader
 *  com.l7tech.gateway.common.custom.ContentTypeHeaderToCustomConverter
 *  com.l7tech.message.Message
 *  com.l7tech.message.MimeKnob
 *  com.l7tech.policy.assertion.ext.message.CustomContentType
 *  com.l7tech.policy.assertion.ext.message.CustomMessage
 *  com.l7tech.policy.assertion.ext.message.CustomMessageAccessException
 *  com.l7tech.policy.assertion.ext.message.format.CustomMessageFormat
 *  com.l7tech.policy.assertion.ext.message.format.CustomMessageFormatFactory
 *  com.l7tech.policy.assertion.ext.message.format.NoSuchMessageFormatException
 *  com.l7tech.policy.assertion.ext.message.knob.CustomMessageKnob
 *  com.l7tech.policy.assertion.ext.message.knob.NoSuchKnobException
 *  org.jetbrains.annotations.NotNull
 */
package com.l7tech.server.custom;

import com.l7tech.common.mime.ContentTypeHeader;
import com.l7tech.gateway.common.custom.ContentTypeHeaderToCustomConverter;
import com.l7tech.message.Message;
import com.l7tech.message.MimeKnob;
import com.l7tech.policy.assertion.ext.message.CustomContentType;
import com.l7tech.policy.assertion.ext.message.CustomMessage;
import com.l7tech.policy.assertion.ext.message.CustomMessageAccessException;
import com.l7tech.policy.assertion.ext.message.format.CustomMessageFormat;
import com.l7tech.policy.assertion.ext.message.format.CustomMessageFormatFactory;
import com.l7tech.policy.assertion.ext.message.format.NoSuchMessageFormatException;
import com.l7tech.policy.assertion.ext.message.knob.CustomMessageKnob;
import com.l7tech.policy.assertion.ext.message.knob.NoSuchKnobException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jetbrains.annotations.NotNull;

/*
 * Exception performing whole class analysis ignored.
 */
public class CustomMessageImpl
implements CustomMessage {
    final Logger a;
    private final Message b;
    private final CustomMessageFormatFactory c;
    private final Map<Class<? extends CustomMessageKnob>, CustomMessageKnob> d;
    private static final String[] e;

    public final Message getMessage() {
        return this.b;
    }

    public CustomMessageImpl(@NotNull CustomMessageFormatFactory customMessageFormatFactory, @NotNull Message message) {
        if (customMessageFormatFactory == null) {
            CustomMessageImpl.a(0);
        }
        if (message == null) {
            CustomMessageImpl.a(1);
        }
        this.a = Logger.getLogger(CustomMessageImpl.class.getName());
        this.b = message;
        this.c = customMessageFormatFactory;
        this.d = new HashMap<Class<? extends CustomMessageKnob>, CustomMessageKnob>();
    }

    public static ContentTypeHeader extractContentTypeHeader(@NotNull Message message) {
        ContentTypeHeader contentTypeHeader;
        try {
            if (message == null) {
                CustomMessageImpl.a(2);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw CustomMessageImpl.a(illegalArgumentException);
        }
        ContentTypeHeader contentTypeHeader2 = null;
        MimeKnob mimeKnob = (MimeKnob)message.getKnob(MimeKnob.class);
        if (mimeKnob != null) {
            contentTypeHeader2 = mimeKnob.getOuterContentType();
        }
        try {
            contentTypeHeader = contentTypeHeader2 != null ? contentTypeHeader2 : ContentTypeHeader.OCTET_STREAM_DEFAULT;
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw CustomMessageImpl.a(illegalArgumentException);
        }
        return contentTypeHeader;
    }

    public CustomContentType getContentType() {
        return new ContentTypeHeaderToCustomConverter(CustomMessageImpl.extractContentTypeHeader(this.b));
    }

    public void setContentType(CustomContentType customContentType) throws IllegalArgumentException {
        block11: {
            block10: {
                try {
                    if (customContentType == null) {
                        throw new IllegalArgumentException(e[8]);
                    }
                }
                catch (IOException iOException) {
                    throw CustomMessageImpl.a(iOException);
                }
                try {
                    if (!(customContentType instanceof ContentTypeHeaderToCustomConverter)) break block10;
                    this.b.getMimeKnob().setOuterContentType(((ContentTypeHeaderToCustomConverter)customContentType).getContentTypeHeader());
                    break block11;
                }
                catch (IOException iOException) {
                    throw CustomMessageImpl.a(iOException);
                }
            }
            try {
                if (this.a.isLoggable(Level.FINE)) {
                    this.a.fine(e[7] + customContentType.getClass().getName());
                }
            }
            catch (IOException iOException) {
                throw CustomMessageImpl.a(iOException);
            }
            try {
                String string = customContentType.getFullValue();
                this.b.getMimeKnob().setOuterContentType(ContentTypeHeader.parseValue((String)string));
            }
            catch (IOException iOException) {
                throw new IllegalArgumentException(e[10], iOException);
            }
        }
    }

    public InputStream getInputStream() throws CustomMessageAccessException {
        try {
            return (InputStream)this.extract(this.c.getStreamFormat());
        }
        catch (NoSuchMessageFormatException noSuchMessageFormatException) {
            this.a.log(Level.WARNING, e[0], noSuchMessageFormatException);
            return null;
        }
    }

    public void setInputStream(InputStream inputStream) throws CustomMessageAccessException {
        try {
            this.overwrite(this.c.getStreamFormat(), inputStream);
        }
        catch (NoSuchMessageFormatException noSuchMessageFormatException) {
            this.a.log(Level.WARNING, e[6], noSuchMessageFormatException);
        }
    }

    public <T> T extract(CustomMessageFormat<T> customMessageFormat) throws CustomMessageAccessException {
        try {
            if (customMessageFormat == null) {
                throw new CustomMessageAccessException(e[11]);
            }
        }
        catch (CustomMessageAccessException customMessageAccessException) {
            throw CustomMessageImpl.a((Exception)((Object)customMessageAccessException));
        }
        return (T)customMessageFormat.extract((CustomMessage)this);
    }

    public <T> void overwrite(CustomMessageFormat<T> customMessageFormat, T t2) throws CustomMessageAccessException {
        try {
            if (customMessageFormat == null) {
                throw new CustomMessageAccessException(e[1]);
            }
        }
        catch (CustomMessageAccessException customMessageAccessException) {
            throw CustomMessageImpl.a((Exception)((Object)customMessageAccessException));
        }
        customMessageFormat.overwrite((CustomMessage)this, t2);
    }

    public <T extends CustomMessageKnob> T getKnob(Class<T> clazz) throws NoSuchKnobException {
        try {
            if (clazz == null) {
                throw new NoSuchKnobException(null, e[14]);
            }
        }
        catch (NoSuchKnobException noSuchKnobException) {
            throw CustomMessageImpl.a((Exception)((Object)noSuchKnobException));
        }
        CustomMessageKnob customMessageKnob = this.d.get(clazz);
        try {
            if (customMessageKnob == null) {
                throw new NoSuchKnobException(clazz);
            }
        }
        catch (NoSuchKnobException noSuchKnobException) {
            throw CustomMessageImpl.a((Exception)((Object)noSuchKnobException));
        }
        return (T)customMessageKnob;
    }

    public Collection<CustomMessageKnob> getAttachedKnobs() {
        return Collections.unmodifiableCollection(this.d.values());
    }

    public <T extends CustomMessageKnob> void attachKnob(@NotNull Class<T> clazz, @NotNull T t2) throws IllegalArgumentException {
        try {
            if (clazz == null) {
                CustomMessageImpl.a(3);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw CustomMessageImpl.a(illegalArgumentException);
        }
        try {
            if (t2 == null) {
                CustomMessageImpl.a(4);
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw CustomMessageImpl.a(illegalArgumentException);
        }
        try {
            if (!clazz.isAssignableFrom(t2.getClass())) {
                throw new IllegalArgumentException(e[9] + String.valueOf(clazz));
            }
        }
        catch (IllegalArgumentException illegalArgumentException) {
            throw CustomMessageImpl.a(illegalArgumentException);
        }
        this.d.put(clazz, t2);
    }

    /*
     * Exception decompiling
     */
    private static /* synthetic */ void a(int var0) {
        /*
         * This method has failed to decompile.  When submitting a bug report, please provide this stack trace, and (if you hold appropriate legal rights) the relevant class file.
         * 
         * org.benf.cfr.reader.util.ConfusedCFRException: Tried to end blocks [0[TRYBLOCK]], but top level block is 2[SWITCH]
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.processEndingBlocks(Op04StructuredStatement.java:435)
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op04StructuredStatement.buildNestedBlocks(Op04StructuredStatement.java:484)
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op03SimpleStatement.createInitialStructuredBlock(Op03SimpleStatement.java:736)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisInner(CodeAnalyser.java:850)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisOrWrapFail(CodeAnalyser.java:278)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysis(CodeAnalyser.java:201)
         *     at org.benf.cfr.reader.entities.attributes.AttributeCode.analyse(AttributeCode.java:94)
         *     at org.benf.cfr.reader.entities.Method.analyse(Method.java:531)
         *     at org.benf.cfr.reader.entities.ClassFile.analyseMid(ClassFile.java:1050)
         *     at org.benf.cfr.reader.entities.ClassFile.analyseTop(ClassFile.java:942)
         *     at org.benf.cfr.reader.Driver.doJarVersionTypes(Driver.java:257)
         *     at org.benf.cfr.reader.Driver.doJar(Driver.java:139)
         *     at org.benf.cfr.reader.CfrDriverImpl.analyse(CfrDriverImpl.java:76)
         *     at org.benf.cfr.reader.Main.main(Main.java:54)
         */
        throw new IllegalStateException("Decompilation failed");
    }

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

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[18];
                var3_1 = 0;
                var2_2 = "KNl\u001e\u0002p>Xxl%\ta&\fY}#\u0019r%EE\u007fw\u0002u'@\u000bk>\u0002c.\fBlw\na\"@N|w\u0019n.T[}4\u0018e/@R8 \u0005t#\fN`4\tp?EDvmf\u0015JDj:\rtkOJv9\u0003tkNN89\u0019l'\tGEw5/l*_X\u0004GEw5\u0006\u0010Bv>\u0018>\nM_l6\u000fh\u0000BDz3_Nl\u001e\u0002p>Xxl%\ta&\fMy>\u0000e/\f^v2\u0014p.O_}3\u0000yk[Bl?Le3ONh#\u0005o%\u0016!PODv#\tn?xRh2Li8\fEw#Li%__y9\u000fe$J\u000b[8\u0002t.B_L.\u001ce\u0003IJ|2\u001eT$o^k#\u0003m\bCEn2\u001et.^\u00078>\u0018skMHl\"\rl'U\u00118\u0017ODv#\tn?xRh2Li8\fY}&\u0019i9IO+GEw5Li8\fEw#La%\fBu'\u0000e&IEl6\u0018i$B\u000bw1Lk%CI[;\rs8\f4ODv#\tn?xRh2Li8\fNq#\u0004e9\fNu'\u0018ykCY8$\u0015n?MHl>\u000fa'@R8>\u0002v*@B|\u0015JDj:\rtkOJv9\u0003tkNN89\u0019l'\u0018ISl%\rc?oDv#\tn?xRh2$e*HNj\u0007ANk$\rg.\u0011GEw5/l*_X8>\u001f %YGt*ODux\u00007?IHpx\u001fe9ZNjx\u000fu8XDux/u8XDu\u001a\ts8ML}\u001e\u0001p'";
                var4_3 = "KNl\u001e\u0002p>Xxl%\ta&\fY}#\u0019r%EE\u007fw\u0002u'@\u000bk>\u0002c.\fBlw\na\"@N|w\u0019n.T[}4\u0018e/@R8 \u0005t#\fN`4\tp?EDvmf\u0015JDj:\rtkOJv9\u0003tkNN89\u0019l'\tGEw5/l*_X\u0004GEw5\u0006\u0010Bv>\u0018>\nM_l6\u000fh\u0000BDz3_Nl\u001e\u0002p>Xxl%\ta&\fMy>\u0000e/\f^v2\u0014p.O_}3\u0000yk[Bl?Le3ONh#\u0005o%\u0016!PODv#\tn?xRh2Li8\fEw#Li%__y9\u000fe$J\u000b[8\u0002t.B_L.\u001ce\u0003IJ|2\u001eT$o^k#\u0003m\bCEn2\u001et.^\u00078>\u0018skMHl\"\rl'U\u00118\u0017ODv#\tn?xRh2Li8\fY}&\u0019i9IO+GEw5Li8\fEw#La%\fBu'\u0000e&IEl6\u0018i$B\u000bw1Lk%CI[;\rs8\f4ODv#\tn?xRh2Li8\fNq#\u0004e9\fNu'\u0018ykCY8$\u0015n?MHl>\u000fa'@R8>\u0002v*@B|\u0015JDj:\rtkOJv9\u0003tkNN89\u0019l'\u0018ISl%\rc?oDv#\tn?xRh2$e*HNj\u0007ANk$\rg.\u0011GEw5/l*_X8>\u001f %YGt*ODux\u00007?IHpx\u001fe9ZNjx\u000fu8XDux/u8XDu\u001a\ts8ML}\u001e\u0001p'".length();
                var1_4 = 75;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = CustomMessageImpl.a(v0, CustomMessageImpl.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "EqW\n)M\rp#V\u00106\b#JlD11D\u000f$sQ\r%E\u0006pfB_c\r\u0010##_\u0019d\r\u0010*&C_)]\u0010p#^\u00100\b\u0001a#^\n(D\u0014ifC\f%O\u0006BlB\u0012%\\%e`D\u00106Q";
                    var4_3 = "EqW\n)M\rp#V\u00106\b#JlD11D\u000f$sQ\r%E\u0006pfB_c\r\u0010##_\u0019d\r\u0010*&C_)]\u0010p#^\u00100\b\u0001a#^\n(D\u0014ifC\f%O\u0006BlB\u0012%\\%e`D\u00106Q".length();
                    var1_4 = 62;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 80;
                        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++] = CustomMessageImpl.a(v0, CustomMessageImpl.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;
            }
        }
        CustomMessageImpl.e = var5;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x33);
        }
        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 -> 84;
                    case 1 -> 83;
                    case 2 -> 96;
                    case 3 -> 47;
                    case 4 -> 20;
                    case 5 -> 120;
                    default -> 51;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

