package vq;

import java.io.IOException;
import kotlin.jvm.internal.t;
import uq.e0;
import uq.x;

/* loaded from: classes3.dex */
public abstract class k {

    /* loaded from: classes3.dex */
    public static final class a extends e0 {

        /* renamed from: r, reason: collision with root package name */
        final /* synthetic */ x f40467r;

        /* renamed from: s, reason: collision with root package name */
        final /* synthetic */ long f40468s;

        /* renamed from: t, reason: collision with root package name */
        final /* synthetic */ kr.f f40469t;

        a(x xVar, long j10, kr.f fVar) {
            this.f40467r = xVar;
            this.f40468s = j10;
            this.f40469t = fVar;
        }

        @Override // uq.e0
        public long e() {
            return this.f40468s;
        }

        @Override // uq.e0
        public x f() {
            return this.f40467r;
        }

        @Override // uq.e0
        public kr.f h() {
            return this.f40469t;
        }
    }

    public static final e0 a(kr.f fVar, x xVar, long j10) {
        t.g(fVar, "<this>");
        return new a(xVar, j10, fVar);
    }

    public static final byte[] b(e0 e0Var) {
        byte[] bArr;
        t.g(e0Var, "<this>");
        long e10 = e0Var.e();
        if (e10 > 2147483647L) {
            throw new IOException("Cannot buffer entire body for content length: " + e10);
        }
        kr.f h10 = e0Var.h();
        Throwable th2 = null;
        try {
            bArr = h10.B();
        } catch (Throwable th3) {
            bArr = null;
            th2 = th3;
        }
        if (h10 != null) {
            try {
                h10.close();
            } catch (Throwable th4) {
                if (th2 == null) {
                    th2 = th4;
                } else {
                    rm.h.a(th2, th4);
                }
            }
        }
        if (th2 != null) {
            throw th2;
        }
        t.d(bArr);
        int length = bArr.length;
        if (e10 == -1 || e10 == length) {
            return bArr;
        }
        throw new IOException("Content-Length (" + e10 + ") and stream length (" + length + ") disagree");
    }

    public static final void c(e0 e0Var) {
        t.g(e0Var, "<this>");
        m.f(e0Var.h());
    }

    public static final e0 d(byte[] bArr, x xVar) {
        t.g(bArr, "<this>");
        return e0.f37448q.b(new kr.d().z0(bArr), xVar, bArr.length);
    }
}
