/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.common.mime.ByteArrayStashManager
 *  com.l7tech.common.mime.ContentTypeHeader
 *  com.l7tech.policy.variable.NoSuchVariableException
 */
package com.l7tech.server.message;

import com.l7tech.common.mime.ByteArrayStashManager;
import com.l7tech.common.mime.ContentTypeHeader;
import com.l7tech.policy.variable.NoSuchVariableException;
import com.l7tech.server.message.ContextVariableKnob;
import com.l7tech.server.message.PolicyEnforcementContext;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;

class a
extends ByteArrayStashManager {
    final ContentTypeHeader val$contentType;
    final ContextVariableKnob val$cvk;
    final PolicyEnforcementContext val$context;
    final String val$variableName;

    a(ContentTypeHeader contentTypeHeader, ContextVariableKnob contextVariableKnob, PolicyEnforcementContext policyEnforcementContext, String string) {
        this.val$contentType = contentTypeHeader;
        this.val$cvk = contextVariableKnob;
        this.val$context = policyEnforcementContext;
        this.val$variableName = string;
    }

    public void stash(int n2, byte[] byArray, int n3, int n4) {
        try {
            super.stash(n2, byArray, n3, n4);
            if (n2 != 0) {
                return;
            }
        }
        catch (UnsupportedCharsetException unsupportedCharsetException) {
            throw a.a(unsupportedCharsetException);
        }
        try {
            Charset charset = this.val$contentType.getEncoding();
            if (this.val$cvk.getOverrideEncoding() != null) {
                charset = this.val$cvk.getOverrideEncoding();
            }
            String string = new String(byArray, n3, n4, charset);
            try {
                if (!string.equals(this.val$context.getVariable(this.val$variableName))) {
                    this.val$context.setVariable(this.val$variableName, string);
                }
            }
            catch (UnsupportedCharsetException unsupportedCharsetException) {
                throw a.a(unsupportedCharsetException);
            }
        }
        catch (UnsupportedCharsetException unsupportedCharsetException) {
            throw new RuntimeException(unsupportedCharsetException);
        }
        catch (NoSuchVariableException noSuchVariableException) {
            throw new RuntimeException(noSuchVariableException);
        }
    }

    private static UnsupportedCharsetException a(UnsupportedCharsetException unsupportedCharsetException) {
        return unsupportedCharsetException;
    }
}

