package i;

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

/* JADX INFO: compiled from: JvmOkio.kt */
/* JADX INFO: loaded from: classes.dex */
final class u implements b0 {
    private final OutputStream b;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private final e0 f1043e;

    public u(OutputStream outputStream, e0 e0Var) {
        h.x.d.k.d(outputStream, "out");
        h.x.d.k.d(e0Var, "timeout");
        this.b = outputStream;
        this.f1043e = e0Var;
    }

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

    @Override // i.b0, java.io.Flushable
    public void flush() throws IOException {
        this.b.flush();
    }

    @Override // i.b0
    public e0 timeout() {
        return this.f1043e;
    }

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

    @Override // i.b0
    public void write(f fVar, long j2) throws IOException {
        h.x.d.k.d(fVar, "source");
        c.b(fVar.J(), 0L, j2);
        while (j2 > 0) {
            this.f1043e.throwIfReached();
            y yVar = fVar.b;
            h.x.d.k.b(yVar);
            int iMin = (int) Math.min(j2, yVar.f1053c - yVar.b);
            this.b.write(yVar.a, yVar.b, iMin);
            yVar.b += iMin;
            long j3 = iMin;
            j2 -= j3;
            fVar.H(fVar.J() - j3);
            if (yVar.b == yVar.f1053c) {
                fVar.b = yVar.b();
                z.b(yVar);
            }
        }
    }
}
