/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.mime.NoSuchPartException
 *  com.l7tech.message.Message
 *  com.l7tech.message.MimeKnob
 *  com.l7tech.policy.assertion.ext.message.CustomMessage
 *  com.l7tech.policy.assertion.ext.message.CustomMessageAccessException
 *  org.jetbrains.annotations.NotNull
 */
package com.l7tech.server.custom.format;

import com.l7tech.common.mime.NoSuchPartException;
import com.l7tech.message.Message;
import com.l7tech.message.MimeKnob;
import com.l7tech.policy.assertion.ext.message.CustomMessage;
import com.l7tech.policy.assertion.ext.message.CustomMessageAccessException;
import com.l7tech.server.StashManagerFactory;
import com.l7tech.server.custom.CustomMessageImpl;
import com.l7tech.server.custom.format.CustomMessageFormatBase;
import com.l7tech.server.custom.format.a;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import org.jetbrains.annotations.NotNull;

/*
 * Exception performing whole class analysis ignored.
 */
public class CustomMessageInputStreamFormat
extends CustomMessageFormatBase<InputStream> {
    private static final String[] b;

    public CustomMessageInputStreamFormat(@NotNull StashManagerFactory stashManagerFactory, @NotNull String string, @NotNull String string2) {
        if (stashManagerFactory == null) {
            CustomMessageInputStreamFormat.b(0);
        }
        if (string == null) {
            CustomMessageInputStreamFormat.b(1);
        }
        if (string2 == null) {
            CustomMessageInputStreamFormat.b(2);
        }
        super(stashManagerFactory, string, string2);
    }

    public Class<InputStream> getRepresentationClass() {
        return InputStream.class;
    }

    public InputStream extract(CustomMessage customMessage) throws CustomMessageAccessException {
        try {
            if (customMessage == null) {
                throw new CustomMessageAccessException(b[6]);
            }
        }
        catch (IOException iOException) {
            throw CustomMessageInputStreamFormat.a(iOException);
        }
        try {
            if (!(customMessage instanceof CustomMessageImpl)) {
                throw new CustomMessageAccessException(b[10]);
            }
        }
        catch (IOException iOException) {
            throw CustomMessageInputStreamFormat.a(iOException);
        }
        Message message = ((CustomMessageImpl)customMessage).getMessage();
        try {
            MimeKnob mimeKnob;
            if (message.isInitialized() && (mimeKnob = (MimeKnob)message.getKnob(MimeKnob.class)) != null) {
                return mimeKnob.getEntireMessageBodyAsInputStream();
            }
        }
        catch (NoSuchPartException | IOException throwable) {
            throw new CustomMessageAccessException(b[13], throwable);
        }
        return null;
    }

    public void overwrite(CustomMessage customMessage, InputStream inputStream) throws CustomMessageAccessException {
        try {
            if (customMessage == null) {
                throw new CustomMessageAccessException(b[11]);
            }
        }
        catch (IOException iOException) {
            throw CustomMessageInputStreamFormat.a(iOException);
        }
        try {
            if (!(customMessage instanceof CustomMessageImpl)) {
                throw new CustomMessageAccessException(b[9]);
            }
        }
        catch (IOException iOException) {
            throw CustomMessageInputStreamFormat.a(iOException);
        }
        Message message = ((CustomMessageImpl)customMessage).getMessage();
        try {
            message.initialize(this.stashManagerFactory.createStashManager(), CustomMessageImpl.extractContentTypeHeader(message), inputStream);
        }
        catch (IOException iOException) {
            throw new CustomMessageAccessException(b[3], (Throwable)iOException);
        }
    }

    public <K> InputStream createBody(K k2) throws CustomMessageAccessException {
        try {
            if (k2 == null) {
                throw new CustomMessageAccessException(b[8]);
            }
        }
        catch (CustomMessageAccessException customMessageAccessException) {
            throw CustomMessageInputStreamFormat.a((Exception)((Object)customMessageAccessException));
        }
        if (k2 instanceof String) {
            StringReader stringReader = new StringReader((String)k2);
            return new a(this, stringReader);
        }
        try {
            if (k2 instanceof InputStream) {
                return (InputStream)k2;
            }
        }
        catch (CustomMessageAccessException customMessageAccessException) {
            throw CustomMessageInputStreamFormat.a((Exception)((Object)customMessageAccessException));
        }
        throw new CustomMessageAccessException(b[7] + k2.getClass().getSimpleName());
    }

    /*
     * Exception decompiling
     */
    private static /* synthetic */ void b(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 1[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[14];
                var3_1 = 0;
                var2_2 = "\u0019%6\t*f{\u000400\u001f0m{\t%8\b;\u0006V89\u00136\u0015\u0004\u00040:\u001f1/#%\u00150\u000bm\u00028;\u001fbDl\u000f# \b+_s\u00046w3,[o\u001e\u0002#\b'JwJ<2\t1J}\u000fq!\u001b.^\u007f>+#0\u000f/Nt\u001eq1\u00150\u000bZ$>#47GvJ!6\b#F\u007f\u001e4%Ze\u000eiMq8\u001cb\u000eiDt$Z/^i\u001eq9\u00156\u000bx\u000fq9\u000f.G>\t>:U.\u001cn\u000f2?U1Nh\u001c4%U!^i\u001e>:U$Dh\u00070#U\u0001^i\u001e>:7'Xi\u000b623,[o\u001e\u0002#\b'Jw,>%\u0017#_\u0016\u00074$\t#L\u007fJ26\u0014,DnJ32Z,^v\u0006\u001a??$\u000f2[u\u0018%2\u001ebHu\u0004%2\u00146\u000bn\u0013!2@b\u0016\t>9\u000e'EnJ26\u0014,DnJ32Z,^v\u0006\u001e\u00074$\t#L\u007fJ8$Z-M:\u001f?$\u000f2[u\u0018%2\u001eb_c\u001a4\u001e\u00074$\t#L\u007fJ8$Z-M:\u001f?$\u000f2[u\u0018%2\u001eb_c\u001a4\u0016\u00074$\t#L\u007fJ26\u0014,DnJ32Z,^v\u0006";
                var4_3 = "\u0019%6\t*f{\u000400\u001f0m{\t%8\b;\u0006V89\u00136\u0015\u0004\u00040:\u001f1/#%\u00150\u000bm\u00028;\u001fbDl\u000f# \b+_s\u00046w3,[o\u001e\u0002#\b'JwJ<2\t1J}\u000fq!\u001b.^\u007f>+#0\u000f/Nt\u001eq1\u00150\u000bZ$>#47GvJ!6\b#F\u007f\u001e4%Ze\u000eiMq8\u001cb\u000eiDt$Z/^i\u001eq9\u00156\u000bx\u000fq9\u000f.G>\t>:U.\u001cn\u000f2?U1Nh\u001c4%U!^i\u001e>:U$Dh\u00070#U\u0001^i\u001e>:7'Xi\u000b623,[o\u001e\u0002#\b'Jw,>%\u0017#_\u0016\u00074$\t#L\u007fJ26\u0014,DnJ32Z,^v\u0006\u001a??$\u000f2[u\u0018%2\u001ebHu\u0004%2\u00146\u000bn\u0013!2@b\u0016\t>9\u000e'EnJ26\u0014,DnJ32Z,^v\u0006\u001e\u00074$\t#L\u007fJ8$Z-M:\u001f?$\u000f2[u\u0018%2\u001eb_c\u001a4\u001e\u00074$\t#L\u007fJ8$Z-M:\u001f?$\u000f2[u\u0018%2\u001eb_c\u001a4\u0016\u00074$\t#L\u007fJ26\u0014,DnJ32Z,^v\u0006".length();
                var1_4 = 19;
                var0_5 = -1;
lbl7:
                // 2 sources

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

                while (true) {
                    var5[var3_1++] = CustomMessageInputStreamFormat.b(v0, CustomMessageInputStreamFormat.b(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "qK[fO=\u0015aGGk0P\\ZjOt\u0012}GD`\u001d1\u001da\\IfI=\u000br\u000eakM!\u0011FZZ`\\9ExK[v\\3\u00005XIiH1";
                    var4_3 = "qK[fO=\u0015aGGk0P\\ZjOt\u0012}GD`\u001d1\u001da\\IfI=\u000br\u000eakM!\u0011FZZ`\\9ExK[v\\3\u00005XIiH1".length();
                    var1_4 = 11;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 78;
                        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++] = CustomMessageInputStreamFormat.b(v0, CustomMessageInputStreamFormat.b(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;
            }
        }
        CustomMessageInputStreamFormat.b = var5;
    }

    private static char[] b(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 b(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 -> 91;
                    case 1 -> 96;
                    case 2 -> 102;
                    case 3 -> 75;
                    case 4 -> 115;
                    case 5 -> 26;
                    default -> 43;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

