package defpackage;

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

/* renamed from: ᵞᵨـ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C2988 implements InterfaceC3226 {

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public final C2753 f11533;

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public final CRC32 f11534;

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public byte f11535;

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public final C3452 f11536;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public final Inflater f11537;

    public C2988(InterfaceC4777 interfaceC4777) {
        C2753 c2753 = new C2753(interfaceC4777);
        this.f11533 = c2753;
        Inflater inflater = new Inflater(true);
        this.f11537 = inflater;
        this.f11536 = new C3452(c2753, inflater);
        this.f11534 = new CRC32();
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public static void m7303(int i, int i2, String str) throws IOException {
        if (i2 == i) {
            return;
        }
        throw new IOException(str + ": actual 0x" + AbstractC1789.m5078(8, ᵩʛʽ.ˑᵥˁ(i2)) + " != expected 0x" + AbstractC1789.m5078(8, ᵩʛʽ.ˑᵥˁ(i)));
    }

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

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final void m7304(C0963 c0963, long j, long j2) {
        C3514 c3514 = c0963.f4315;
        while (true) {
            int i = c3514.f13188;
            int i2 = c3514.f13190;
            if (j < i - i2) {
                break;
            }
            j -= i - i2;
            c3514 = c3514.f13187;
        }
        while (j2 > 0) {
            int iMin = (int) Math.min(c3514.f13188 - r6, j2);
            this.f11534.update(c3514.f13189, (int) (c3514.f13190 + j), iMin);
            j2 -= iMin;
            c3514 = c3514.f13187;
            j = 0;
        }
    }

    @Override // defpackage.InterfaceC3226
    /* renamed from: ᵝᵵᵺ */
    public final C3948 mo2227() {
        return this.f11533.f10637.mo2227();
    }

    @Override // defpackage.InterfaceC3226
    /* renamed from: ᵳٴᵶ */
    public final long mo2229(C0963 c0963, long j) throws DataFormatException, IOException {
        C2988 c2988 = this;
        byte b = c2988.f11535;
        CRC32 crc32 = c2988.f11534;
        C2753 c2753 = c2988.f11533;
        if (b == 0) {
            c2753.mo3256(10L);
            C0963 c09632 = c2753.f10636;
            byte bM3267 = c09632.m3267(3L);
            boolean z = ((bM3267 >> 1) & 1) == 1;
            if (z) {
                c2988.m7304(c09632, 0L, 10L);
            }
            m7303(8075, c2753.readShort(), "ID1ID2");
            c2753.skip(8L);
            if (((bM3267 >> 2) & 1) == 1) {
                c2753.mo3256(2L);
                if (z) {
                    m7304(c09632, 0L, 2L);
                }
                long jM3265 = c09632.m3265() & 65535;
                c2753.mo3256(jM3265);
                if (z) {
                    m7304(c09632, 0L, jM3265);
                }
                c2753.skip(jM3265);
            }
            if (((bM3267 >> 3) & 1) == 1) {
                long jM6791 = c2753.m6791((byte) 0, 0L, Long.MAX_VALUE);
                if (jM6791 == -1) {
                    throw new EOFException();
                }
                if (z) {
                    m7304(c09632, 0L, jM6791 + 1);
                }
                c2753.skip(jM6791 + 1);
            }
            if (((bM3267 >> 4) & 1) == 1) {
                long jM67912 = c2753.m6791((byte) 0, 0L, Long.MAX_VALUE);
                if (jM67912 == -1) {
                    throw new EOFException();
                }
                if (z) {
                    c2988 = this;
                    c2988.m7304(c09632, 0L, jM67912 + 1);
                } else {
                    c2988 = this;
                }
                c2753.skip(jM67912 + 1);
            } else {
                c2988 = this;
            }
            if (z) {
                m7303(c2753.m6790(), (short) crc32.getValue(), "FHCRC");
                crc32.reset();
            }
            c2988.f11535 = (byte) 1;
        }
        if (c2988.f11535 == 1) {
            long j2 = c0963.f4314;
            long jMo2229 = c2988.f11536.mo2229(c0963, 8192L);
            if (jMo2229 != -1) {
                c2988.m7304(c0963, j2, jMo2229);
                return jMo2229;
            }
            c2988.f11535 = (byte) 2;
        }
        if (c2988.f11535 == 2) {
            m7303(c2753.m6789(), (int) crc32.getValue(), "CRC");
            m7303(c2753.m6789(), (int) c2988.f11537.getBytesWritten(), "ISIZE");
            c2988.f11535 = (byte) 3;
            if (!c2753.mo3284()) {
                C0910.m3045("gzip finished without exhausting source");
                return 0L;
            }
        }
        return -1L;
    }
}
