package i;

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

/* JADX INFO: compiled from: JvmOkio.kt */
/* JADX INFO: loaded from: classes.dex */
final class p implements d0 {
    private final InputStream b;

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

    public p(InputStream inputStream, e0 e0Var) {
        h.x.d.k.d(inputStream, "input");
        h.x.d.k.d(e0Var, "timeout");
        this.b = inputStream;
        this.f1039e = e0Var;
    }

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

    @Override // i.d0
    public long read(f fVar, long j2) throws IOException {
        h.x.d.k.d(fVar, "sink");
        if (j2 == 0) {
            return 0L;
        }
        if (!(j2 >= 0)) {
            throw new IllegalArgumentException(("byteCount < 0: " + j2).toString());
        }
        try {
            this.f1039e.throwIfReached();
            y yVarP = fVar.P(1);
            int i2 = this.b.read(yVarP.a, yVarP.f1053c, (int) Math.min(j2, 8192 - yVarP.f1053c));
            if (i2 != -1) {
                yVarP.f1053c += i2;
                long j3 = i2;
                fVar.H(fVar.J() + j3);
                return j3;
            }
            if (yVarP.b != yVarP.f1053c) {
                return -1L;
            }
            fVar.b = yVarP.b();
            z.b(yVarP);
            return -1L;
        } catch (AssertionError e2) {
            if (q.e(e2)) {
                throw new IOException(e2);
            }
            throw e2;
        }
    }

    @Override // i.d0
    public e0 timeout() {
        return this.f1039e;
    }

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