package h;

import d.C0424d;
import e.InterfaceC0451b;
import g.C0474a;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Map;
import java.util.zip.GZIPInputStream;
import l.C0611c;

/* JADX INFO: loaded from: classes.dex */
public class f extends l {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    protected t f4131c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    protected boolean f4132d;

    public f(g.i iVar, Class cls, C0611c c0611c) {
        super(cls, c0611c);
        boolean z2 = false;
        this.f4132d = false;
        InterfaceC0451b interfaceC0451bD = c0611c.d();
        if (interfaceC0451bD != null) {
            Class clsDeserializeUsing = interfaceC0451bD.deserializeUsing();
            if (clsDeserializeUsing != null && clsDeserializeUsing != Void.class) {
                z2 = true;
            }
            this.f4132d = z2;
        }
    }

    @Override // h.l
    public int b() {
        t tVar = this.f4131c;
        if (tVar != null) {
            return tVar.d();
        }
        return 2;
    }

    @Override // h.l
    public void c(C0474a c0474a, Object obj, Type type, Map map) {
        Object objB;
        C0611c c0611c;
        int i2;
        if (this.f4131c == null) {
            j(c0474a.i());
        }
        t tVarN = this.f4131c;
        Type typeH = this.f4139a.f5243H;
        if (type instanceof ParameterizedType) {
            g.h hVarJ = c0474a.j();
            if (hVarJ != null) {
                hVarJ.f3988e = type;
            }
            if (typeH != type) {
                typeH = C0611c.h(this.f4140b, type, typeH);
                tVarN = c0474a.i().n(typeH);
            }
        }
        Type type2 = typeH;
        if (!(tVarN instanceof o) || (i2 = (c0611c = this.f4139a).f5247Q) == 0) {
            C0611c c0611c2 = this.f4139a;
            String str = c0611c2.f5259i0;
            objB = (str == null || !(tVarN instanceof AbstractC0503e)) ? tVarN.b(c0474a, type2, c0611c2.f5250b) : ((AbstractC0503e) tVarN).e(c0474a, type2, c0611c2.f5250b, str, c0611c2.f5247Q);
        } else {
            objB = ((o) tVarN).g(c0474a, type2, c0611c.f5250b, i2);
        }
        if ((objB instanceof byte[]) && ("gzip".equals(this.f4139a.f5259i0) || "gzip,base64".equals(this.f4139a.f5259i0))) {
            try {
                GZIPInputStream gZIPInputStream = new GZIPInputStream(new ByteArrayInputStream((byte[]) objB));
                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                while (true) {
                    byte[] bArr = new byte[1024];
                    int i3 = gZIPInputStream.read(bArr);
                    if (i3 == -1) {
                        break;
                    } else if (i3 > 0) {
                        byteArrayOutputStream.write(bArr, 0, i3);
                    }
                }
                objB = byteArrayOutputStream.toByteArray();
            } catch (IOException e2) {
                throw new C0424d("unzip bytes error.", e2);
            }
        }
        if (c0474a.u() == 1) {
            C0474a.C0072a c0072aQ = c0474a.q();
            c0072aQ.f3961c = this;
            c0072aQ.f3962d = c0474a.j();
            c0474a.e0(0);
            return;
        }
        if (obj == null) {
            map.put(this.f4139a.f5250b, objB);
        } else {
            g(obj, objB);
        }
    }

    public t j(g.i iVar) {
        if (this.f4131c == null) {
            InterfaceC0451b interfaceC0451bD = this.f4139a.d();
            if (interfaceC0451bD == null || interfaceC0451bD.deserializeUsing() == Void.class) {
                C0611c c0611c = this.f4139a;
                this.f4131c = iVar.m(c0611c.f5264y, c0611c.f5243H);
            } else {
                try {
                    this.f4131c = (t) interfaceC0451bD.deserializeUsing().newInstance();
                } catch (Exception e2) {
                    throw new C0424d("create deserializeUsing ObjectDeserializer error", e2);
                }
            }
        }
        return this.f4131c;
    }
}
