package okio;

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

/* JADX INFO: loaded from: classes2.dex */
final class p implements E {

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private final F f6050g;

    public p(InputStream input, F timeout) {
        kotlin.jvm.internal.l.e(input, "input");
        kotlin.jvm.internal.l.e(timeout, "timeout");
        this.f6049b = input;
        this.f6050g = timeout;
    }

    @Override // okio.E, java.io.Closeable, java.lang.AutoCloseable
    public void close() throws IOException {
        this.f6049b.close();
    }

    @Override // okio.E
    public long read(C0688f sink, long j2) throws IOException {
        kotlin.jvm.internal.l.e(sink, "sink");
        if (j2 == 0) {
            return 0L;
        }
        if (!(j2 >= 0)) {
            throw new IllegalArgumentException(("byteCount < 0: " + j2).toString());
        }
        try {
            this.f6050g.throwIfReached();
            y yVarK = sink.K(1);
            int i2 = this.f6049b.read(yVarK.f6071a, yVarK.f6073c, (int) Math.min(j2, 8192 - yVarK.f6073c));
            if (i2 != -1) {
                yVarK.f6073c += i2;
                long j3 = i2;
                sink.F(sink.G() + j3);
                return j3;
            }
            if (yVarK.f6072b != yVarK.f6073c) {
                return -1L;
            }
            sink.f6021b = yVarK.b();
            A.b(yVarK);
            return -1L;
        } catch (AssertionError e2) {
            if (q.e(e2)) {
                throw new IOException(e2);
            }
            throw e2;
        }
    }

    @Override // okio.E
    public F timeout() {
        return this.f6050g;
    }

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