package Nm6q_10;

import java.io.OutputStream;
/* compiled from: Okio.kt */
/* loaded from: classes.dex */
public final class JZJr_16 implements H5YG8fq_22 {
    public final KVtv3R_25 KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final OutputStream f330KQgRr5e_0;

    public JZJr_16(OutputStream outputStream, KVtv3R_25 kVtv3R_25) {
        FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.QxJ9d_1(outputStream, "out");
        FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.QxJ9d_1(kVtv3R_25, "timeout");
        this.f330KQgRr5e_0 = outputStream;
        this.KQgRr5e_0 = kVtv3R_25;
    }

    @Override // Nm6q_10.H5YG8fq_22
    public void KQgRr5e_0(X6FRs_4 x6FRs_4, long j) {
        FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.QxJ9d_1(x6FRs_4, "source");
        PGPF6hQ_2.KQgRr5e_0(x6FRs_4.PGPF6hQ_2(), 0L, j);
        while (j > 0) {
            this.KQgRr5e_0.m173KQgRr5e_0();
            BVpCZyH_19 bVpCZyH_19 = x6FRs_4.f348KQgRr5e_0;
            if (bVpCZyH_19 != null) {
                int min = (int) Math.min(j, bVpCZyH_19.QxJ9d_1 - bVpCZyH_19.KQgRr5e_0);
                this.f330KQgRr5e_0.write(bVpCZyH_19.f320KQgRr5e_0, bVpCZyH_19.KQgRr5e_0, min);
                bVpCZyH_19.KQgRr5e_0 += min;
                long j2 = min;
                j -= j2;
                x6FRs_4.m182PGPF6hQ_2(x6FRs_4.PGPF6hQ_2() - j2);
                if (bVpCZyH_19.KQgRr5e_0 == bVpCZyH_19.QxJ9d_1) {
                    x6FRs_4.f348KQgRr5e_0 = bVpCZyH_19.KQgRr5e_0();
                    ZzDuCHW_20.KQgRr5e_0(bVpCZyH_19);
                }
            } else {
                FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.KQgRr5e_0();
                throw null;
            }
        }
    }

    @Override // Nm6q_10.H5YG8fq_22, java.io.Closeable, java.lang.AutoCloseable
    public void close() {
        this.f330KQgRr5e_0.close();
    }

    @Override // Nm6q_10.H5YG8fq_22, java.io.Flushable
    public void flush() {
        this.f330KQgRr5e_0.flush();
    }

    public String toString() {
        return "sink(" + this.f330KQgRr5e_0 + ')';
    }

    @Override // Nm6q_10.H5YG8fq_22
    public KVtv3R_25 KQgRr5e_0() {
        return this.KQgRr5e_0;
    }
}
