package defpackage;

import androidx.media3.container.NalUnitUtil;
import java.io.IOException;
import java.io.InputStream;
import kotlin.Metadata;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\n\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\b\u0012\u0018\u00002\u00020\u0001¨\u0006\u0002"}, d2 = {"Lgn4;", "Lpx8;", "okio"}, k = 1, mv = {1, 9, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@vx8
class gn4 implements px8 {
    public final InputStream a;
    public final ko9 b;

    public gn4(InputStream inputStream, ko9 ko9Var) {
        cr4.g(inputStream, "input");
        cr4.g(ko9Var, "timeout");
        this.a = inputStream;
        this.b = ko9Var;
    }

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

    @Override // defpackage.px8
    public final long read(lg0 lg0Var, long j) throws IOException {
        cr4.g(lg0Var, "sink");
        if (j == 0) {
            return 0L;
        }
        if (j < 0) {
            throw new IllegalArgumentException(n41.j(j, "byteCount < 0: ").toString());
        }
        try {
            this.b.throwIfReached();
            me8 me8VarAf = lg0Var.af(1);
            int i = this.a.read(me8VarAf.a, me8VarAf.c, (int) Math.min(j, 8192 - me8VarAf.c));
            if (i != -1) {
                me8VarAf.c += i;
                long j2 = i;
                lg0Var.b += j2;
                return j2;
            }
            if (me8VarAf.b != me8VarAf.c) {
                return -1L;
            }
            lg0Var.a = me8VarAf.a();
            te8.a(me8VarAf);
            return -1L;
        } catch (AssertionError e) {
            if (eu6.e(e)) {
                throw new IOException(e);
            }
            throw e;
        }
    }

    @Override // defpackage.px8
    /* JADX INFO: renamed from: timeout, reason: from getter */
    public final ko9 getB() {
        return this.b;
    }

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