package okio;

import g.a.a.a.a;
import io.netty.handler.codec.rtsp.RtspHeaders;
import java.io.IOException;
import java.io.InputStream;
import kotlin.Metadata;
import kotlin.jvm.internal.o;
import kotlin.reflect.w.internal.y0.n.c2.c;

/* JADX INFO: renamed from: z.m, reason: from Kotlin metadata */
/* JADX INFO: loaded from: classes2.dex */
@Metadata(d1 = {"\u00002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\t\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0000\b\u0012\u0018\u00002\u00020\u0001B\u0015\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005¢\u0006\u0002\u0010\u0006J\b\u0010\u0007\u001a\u00020\bH\u0016J\u0018\u0010\t\u001a\u00020\n2\u0006\u0010\u000b\u001a\u00020\f2\u0006\u0010\r\u001a\u00020\nH\u0016J\b\u0010\u0004\u001a\u00020\u0005H\u0016J\b\u0010\u000e\u001a\u00020\u000fH\u0016R\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0004\u001a\u00020\u0005X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\u0010"}, d2 = {"Lokio/InputStreamSource;", "Lokio/Source;", "input", "Ljava/io/InputStream;", RtspHeaders.Values.TIMEOUT, "Lokio/Timeout;", "(Ljava/io/InputStream;Lokio/Timeout;)V", "close", "", "read", "", "sink", "Lokio/Buffer;", "byteCount", "toString", "", "okio"}, k = 1, mv = {1, 6, 0}, xi = 48)
public class InputStreamSource implements Source {

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final InputStream f10137f;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final Timeout f10138m;

    public InputStreamSource(InputStream inputStream, Timeout timeout) {
        o.f(inputStream, "input");
        o.f(timeout, RtspHeaders.Values.TIMEOUT);
        this.f10137f = inputStream;
        this.f10138m = timeout;
    }

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

    @Override // okio.Source
    public long r(Buffer buffer, long j2) throws IOException {
        o.f(buffer, "sink");
        if (j2 == 0) {
            return 0L;
        }
        if (!(j2 >= 0)) {
            throw new IllegalArgumentException(a.q("byteCount < 0: ", j2).toString());
        }
        try {
            this.f10138m.f();
            Segment segmentX = buffer.x(1);
            int i2 = this.f10137f.read(segmentX.a, segmentX.f10152c, (int) Math.min(j2, 8192 - segmentX.f10152c));
            if (i2 != -1) {
                segmentX.f10152c += i2;
                long j3 = i2;
                buffer.f10118m += j3;
                return j3;
            }
            if (segmentX.f10151b != segmentX.f10152c) {
                return -1L;
            }
            buffer.f10117f = segmentX.a();
            SegmentPool.a(segmentX);
            return -1L;
        } catch (AssertionError e2) {
            if (c.a0(e2)) {
                throw new IOException(e2);
            }
            throw e2;
        }
    }

    @Override // okio.Source
    /* JADX INFO: renamed from: timeout, reason: from getter */
    public Timeout getF10138m() {
        return this.f10138m;
    }

    public String toString() {
        StringBuilder sbF = a.F("source(");
        sbF.append(this.f10137f);
        sbF.append(')');
        return sbF.toString();
    }
}
