package x7;

import d5.AbstractC0844a;
import java.io.IOException;
import java.io.InputStream;
import n4.u0;

/* JADX INFO: renamed from: x7.c, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C1727c implements H, AutoCloseable {

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final /* synthetic */ int f18752q = 1;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final Object f18753r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final Object f18754s;

    public C1727c(InputStream inputStream, J j8) {
        P6.g.e(inputStream, "input");
        this.f18753r = inputStream;
        this.f18754s = j8;
    }

    @Override // x7.H
    public final long M(C1731g c1731g, long j8) throws IOException {
        switch (this.f18752q) {
            case u0.f15495q /* 0 */:
                P6.g.e(c1731g, "sink");
                C1727c c1727c = (C1727c) this.f18754s;
                G g8 = (G) this.f18753r;
                g8.h();
                try {
                    long jM = c1727c.M(c1731g, j8);
                    if (g8.i()) {
                        throw g8.k(null);
                    }
                    return jM;
                } catch (IOException e8) {
                    if (g8.i()) {
                        throw g8.k(e8);
                    }
                    throw e8;
                } finally {
                    g8.i();
                }
            default:
                P6.g.e(c1731g, "sink");
                if (j8 == 0) {
                    return 0L;
                }
                if (j8 < 0) {
                    throw new IllegalArgumentException(AbstractC0844a.i(j8, "byteCount < 0: ").toString());
                }
                try {
                    ((J) this.f18754s).f();
                    C cQ0 = c1731g.q0(1);
                    int i = ((InputStream) this.f18753r).read(cQ0.f18727a, cQ0.f18729c, (int) Math.min(j8, 8192 - cQ0.f18729c));
                    if (i == -1) {
                        if (cQ0.f18728b == cQ0.f18729c) {
                            c1731g.f18764q = cQ0.a();
                            D.a(cQ0);
                        }
                        return -1L;
                    }
                    cQ0.f18729c += i;
                    long j9 = i;
                    c1731g.f18765r += j9;
                    return j9;
                } catch (AssertionError e9) {
                    if (s7.l.q(e9)) {
                        throw new IOException(e9);
                    }
                    throw e9;
                }
        }
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable
    public final void close() throws IOException {
        switch (this.f18752q) {
            case u0.f15495q /* 0 */:
                C1727c c1727c = (C1727c) this.f18754s;
                G g8 = (G) this.f18753r;
                g8.h();
                try {
                    c1727c.close();
                    if (g8.i()) {
                        throw g8.k(null);
                    }
                    return;
                } catch (IOException e8) {
                    if (!g8.i()) {
                        throw e8;
                    }
                    throw g8.k(e8);
                } finally {
                    g8.i();
                }
            default:
                ((InputStream) this.f18753r).close();
                return;
        }
    }

    @Override // x7.H
    public final J f() {
        switch (this.f18752q) {
            case u0.f15495q /* 0 */:
                return (G) this.f18753r;
            default:
                return (J) this.f18754s;
        }
    }

    public final String toString() {
        switch (this.f18752q) {
            case u0.f15495q /* 0 */:
                return "AsyncTimeout.source(" + ((C1727c) this.f18754s) + ')';
            default:
                return "source(" + ((InputStream) this.f18753r) + ')';
        }
    }

    public C1727c(G g8, C1727c c1727c) {
        this.f18753r = g8;
        this.f18754s = c1727c;
    }
}
