package o;

import java.io.EOFException;
import java.io.IOException;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.kH, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C1658kH implements T90 {
    public final C1822m00 l;
    public final Inflater m;
    public int n;

    /* renamed from: o, reason: collision with root package name */
    public boolean f611o;

    public C1658kH(C1822m00 c1822m00, Inflater inflater) {
        this.l = c1822m00;
        this.m = inflater;
    }

    @Override // o.T90
    public final long C(long j, C0732af c0732af) throws DataFormatException, IOException {
        long j2;
        while (j >= 0) {
            if (this.f611o) {
                throw new IllegalStateException("closed");
            }
            C1822m00 c1822m00 = this.l;
            Inflater inflater = this.m;
            if (j == 0) {
                j2 = 0;
            } else {
                try {
                    C2496t50 c2496t50Y = c0732af.y(1);
                    int iMin = (int) Math.min(j, 8192 - c2496t50Y.c);
                    if (inflater.needsInput() && !c1822m00.b()) {
                        C2496t50 c2496t50 = c1822m00.m.l;
                        int i = c2496t50.c;
                        int i2 = c2496t50.b;
                        int i3 = i - i2;
                        this.n = i3;
                        inflater.setInput(c2496t50.a, i2, i3);
                    }
                    int iInflate = inflater.inflate(c2496t50Y.a, c2496t50Y.c, iMin);
                    int i4 = this.n;
                    if (i4 != 0) {
                        int remaining = i4 - inflater.getRemaining();
                        this.n -= remaining;
                        c1822m00.skip(remaining);
                    }
                    if (iInflate > 0) {
                        c2496t50Y.c += iInflate;
                        j2 = iInflate;
                        c0732af.m += j2;
                    } else {
                        if (c2496t50Y.b == c2496t50Y.c) {
                            c0732af.l = c2496t50Y.a();
                            AbstractC2781w50.a(c2496t50Y);
                        }
                        j2 = 0;
                    }
                } catch (DataFormatException e) {
                    throw new IOException(e);
                }
            }
            if (j2 > 0) {
                return j2;
            }
            if (inflater.finished() || inflater.needsDictionary()) {
                return -1L;
            }
            if (c1822m00.b()) {
                throw new EOFException("source exhausted prematurely");
            }
        }
        throw new IllegalArgumentException(AbstractC0126Ew.l("byteCount < 0: ", j).toString());
    }

    @Override // o.T90
    public final Cf0 a() {
        return this.l.l.a();
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable
    public final void close() throws IOException {
        if (this.f611o) {
            return;
        }
        this.m.end();
        this.f611o = true;
        this.l.close();
    }
}
