package j;

import java.io.IOException;
import java.io.OutputStream;

/* JADX INFO: compiled from: JvmOkio.kt */
/* JADX INFO: loaded from: classes.dex */
public final class s implements z {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final OutputStream f4634b;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final c0 f4635e;

    public s(OutputStream outputStream, c0 c0Var) {
        g.h0.c.l.f(outputStream, "out");
        g.h0.c.l.f(c0Var, "timeout");
        this.f4634b = outputStream;
        this.f4635e = c0Var;
    }

    @Override // j.z, java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.Channel
    public void close() throws IOException {
        this.f4634b.close();
    }

    @Override // j.z, java.io.Flushable
    public void flush() throws IOException {
        this.f4634b.flush();
    }

    @Override // j.z
    public c0 timeout() {
        return this.f4635e;
    }

    public String toString() {
        StringBuilder sbB = d.b.a.a.a.B("sink(");
        sbB.append(this.f4634b);
        sbB.append(')');
        return sbB.toString();
    }

    @Override // j.z
    public void write(d dVar, long j2) throws IOException {
        g.h0.c.l.f(dVar, "source");
        f.a.y.a.z(dVar.f4601e, 0L, j2);
        while (j2 > 0) {
            this.f4635e.throwIfReached();
            w wVar = dVar.f4600b;
            g.h0.c.l.c(wVar);
            int iMin = (int) Math.min(j2, wVar.f4650c - wVar.f4649b);
            this.f4634b.write(wVar.a, wVar.f4649b, iMin);
            int i2 = wVar.f4649b + iMin;
            wVar.f4649b = i2;
            long j3 = iMin;
            j2 -= j3;
            dVar.f4601e -= j3;
            if (i2 == wVar.f4650c) {
                dVar.f4600b = wVar.a();
                x.a(wVar);
            }
        }
    }
}
