package d;

import java.io.IOException;
import java.io.InputStream;

/* JADX INFO: compiled from: Okio.kt */
/* JADX INFO: loaded from: classes.dex */
final class o implements a0 {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final InputStream f1587b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final b0 f1588c;

    public o(InputStream inputStream, b0 b0Var) {
        c.q.d.j.c(inputStream, "input");
        c.q.d.j.c(b0Var, "timeout");
        this.f1587b = inputStream;
        this.f1588c = b0Var;
    }

    @Override // d.a0, java.io.Closeable, java.lang.AutoCloseable
    public void close() throws IOException {
        this.f1587b.close();
    }

    @Override // d.a0
    public long read(f fVar, long j) throws IOException {
        c.q.d.j.c(fVar, "sink");
        if (j == 0) {
            return 0L;
        }
        if (!(j >= 0)) {
            throw new IllegalArgumentException(("byteCount < 0: " + j).toString());
        }
        try {
            this.f1588c.throwIfReached();
            v vVarE0 = fVar.e0(1);
            int i = this.f1587b.read(vVarE0.f1606a, vVarE0.f1608c, (int) Math.min(j, 8192 - vVarE0.f1608c));
            if (i == -1) {
                return -1L;
            }
            vVarE0.f1608c += i;
            long j2 = i;
            fVar.a0(fVar.b0() + j2);
            return j2;
        } catch (AssertionError e2) {
            if (p.e(e2)) {
                throw new IOException(e2);
            }
            throw e2;
        }
    }

    @Override // d.a0
    public b0 timeout() {
        return this.f1588c;
    }

    public String toString() {
        return "source(" + this.f1587b + ')';
    }
}
