package kr;

import java.io.OutputStream;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes4.dex */
public final class s implements y {

    /* renamed from: p, reason: collision with root package name */
    private final OutputStream f26675p;

    /* renamed from: q, reason: collision with root package name */
    private final b0 f26676q;

    public s(OutputStream out, b0 timeout) {
        kotlin.jvm.internal.t.g(out, "out");
        kotlin.jvm.internal.t.g(timeout, "timeout");
        this.f26675p = out;
        this.f26676q = timeout;
    }

    @Override // kr.y
    public void U(d source, long j10) {
        kotlin.jvm.internal.t.g(source, "source");
        b.b(source.X(), 0L, j10);
        while (j10 > 0) {
            this.f26676q.f();
            v vVar = source.f26638p;
            kotlin.jvm.internal.t.d(vVar);
            int min = (int) Math.min(j10, vVar.f26687c - vVar.f26686b);
            this.f26675p.write(vVar.f26685a, vVar.f26686b, min);
            vVar.f26686b += min;
            long j11 = min;
            j10 -= j11;
            source.V(source.X() - j11);
            if (vVar.f26686b == vVar.f26687c) {
                source.f26638p = vVar.b();
                w.b(vVar);
            }
        }
    }

    @Override // kr.y, java.io.Closeable, java.lang.AutoCloseable
    public void close() {
        this.f26675p.close();
    }

    @Override // kr.y, java.io.Flushable
    public void flush() {
        this.f26675p.flush();
    }

    @Override // kr.y
    public b0 l() {
        return this.f26676q;
    }

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