package m4;

import androidx.navigation.C1134i;
import java.io.OutputStream;
import java.util.ArrayList;

/* JADX INFO: renamed from: m4.d1, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes3.dex */
public final class C2499d1 extends OutputStream {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final ArrayList f20980a = new ArrayList();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public n4.u f20981b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final /* synthetic */ C2505f1 f20982c;

    public C2499d1(C2505f1 c2505f1) {
        this.f20982c = c2505f1;
    }

    @Override // java.io.OutputStream
    public final void write(int i6) {
        n4.u uVar = this.f20981b;
        if (uVar == null || uVar.f21768b <= 0) {
            write(new byte[]{(byte) i6}, 0, 1);
            return;
        }
        uVar.f21767a.Q((byte) i6);
        uVar.f21768b--;
        uVar.f21769c++;
    }

    @Override // java.io.OutputStream
    public final void write(byte[] bArr, int i6, int i7) {
        n4.u uVar = this.f20981b;
        ArrayList arrayList = this.f20980a;
        C2505f1 c2505f1 = this.f20982c;
        if (uVar == null) {
            c2505f1.f21019h.getClass();
            n4.u uVarH = C1134i.h(i7);
            this.f20981b = uVarH;
            arrayList.add(uVarH);
        }
        while (i7 > 0) {
            int iMin = Math.min(i7, this.f20981b.f21768b);
            if (iMin == 0) {
                int iMax = Math.max(i7, this.f20981b.f21769c * 2);
                c2505f1.f21019h.getClass();
                n4.u uVarH2 = C1134i.h(iMax);
                this.f20981b = uVarH2;
                arrayList.add(uVarH2);
            } else {
                this.f20981b.a(bArr, i6, iMin);
                i6 += iMin;
                i7 -= iMin;
            }
        }
    }
}
