package x7;

import java.io.IOException;
import java.io.OutputStream;
import n4.u0;

/* JADX INFO: renamed from: x7.b, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C1726b implements F, AutoCloseable {

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

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

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

    public /* synthetic */ C1726b(Object obj, int i, Object obj2) {
        this.f18749q = i;
        this.f18750r = obj;
        this.f18751s = obj2;
    }

    @Override // x7.F
    public final void X(C1731g c1731g, long j8) throws IOException {
        switch (this.f18749q) {
            case u0.f15495q /* 0 */:
                P6.g.e(c1731g, "source");
                s7.d.g(c1731g.f18765r, 0L, j8);
                long j9 = j8;
                while (true) {
                    long j10 = 0;
                    if (j9 <= 0) {
                        return;
                    }
                    C c3 = c1731g.f18764q;
                    P6.g.b(c3);
                    while (true) {
                        if (j10 < 65536) {
                            j10 += (long) (c3.f18729c - c3.f18728b);
                            if (j10 >= j9) {
                                j10 = j9;
                            } else {
                                c3 = c3.f18732f;
                                P6.g.b(c3);
                            }
                        }
                    }
                    C1726b c1726b = (C1726b) this.f18751s;
                    G g8 = (G) this.f18750r;
                    g8.h();
                    try {
                        try {
                            c1726b.X(c1731g, j10);
                            if (g8.i()) {
                                throw g8.k(null);
                            }
                            j9 -= j10;
                        } catch (IOException e8) {
                            if (!g8.i()) {
                                throw e8;
                            }
                            throw g8.k(e8);
                        }
                    } catch (Throwable th) {
                        g8.i();
                        throw th;
                    }
                }
                break;
            default:
                P6.g.e(c1731g, "source");
                s7.d.g(c1731g.f18765r, 0L, j8);
                while (j8 > 0) {
                    ((J) this.f18751s).f();
                    C c8 = c1731g.f18764q;
                    P6.g.b(c8);
                    int iMin = (int) Math.min(j8, c8.f18729c - c8.f18728b);
                    ((OutputStream) this.f18750r).write(c8.f18727a, c8.f18728b, iMin);
                    int i = c8.f18728b + iMin;
                    c8.f18728b = i;
                    long j11 = iMin;
                    j8 -= j11;
                    c1731g.f18765r -= j11;
                    if (i == c8.f18729c) {
                        c1731g.f18764q = c8.a();
                        D.a(c8);
                    }
                }
                return;
        }
    }

    @Override // x7.F, java.io.Closeable, java.lang.AutoCloseable
    public final void close() throws IOException {
        switch (this.f18749q) {
            case u0.f15495q /* 0 */:
                C1726b c1726b = (C1726b) this.f18751s;
                G g8 = (G) this.f18750r;
                g8.h();
                try {
                    c1726b.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:
                ((OutputStream) this.f18750r).close();
                return;
        }
    }

    @Override // x7.F
    public final J f() {
        switch (this.f18749q) {
            case u0.f15495q /* 0 */:
                return (G) this.f18750r;
            default:
                return (J) this.f18751s;
        }
    }

    @Override // x7.F, java.io.Flushable
    public final void flush() throws IOException {
        switch (this.f18749q) {
            case u0.f15495q /* 0 */:
                C1726b c1726b = (C1726b) this.f18751s;
                G g8 = (G) this.f18750r;
                g8.h();
                try {
                    c1726b.flush();
                    if (g8.i()) {
                        throw g8.k(null);
                    }
                    return;
                } catch (IOException e8) {
                    if (!g8.i()) {
                        throw e8;
                    }
                    throw g8.k(e8);
                } finally {
                    g8.i();
                }
            default:
                ((OutputStream) this.f18750r).flush();
                return;
        }
    }

    public final String toString() {
        switch (this.f18749q) {
            case u0.f15495q /* 0 */:
                return "AsyncTimeout.sink(" + ((C1726b) this.f18751s) + ')';
            default:
                return "sink(" + ((OutputStream) this.f18750r) + ')';
        }
    }
}
