package p461;

import java.io.EOFException;
import java.io.IOException;
import java.util.Arrays;
import java.util.zip.CRC32;
import java.util.zip.Inflater;
import p138.p139.p143.p144.C2803;
import p402.p411.p413.C6635;

/* JADX INFO: renamed from: ޑ.މ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C7113 implements InterfaceC7129 {

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public byte f20641;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final C7121 f20642;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public final Inflater f20643;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public final C7114 f20644;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public final CRC32 f20645;

    public C7113(InterfaceC7129 interfaceC7129) {
        if (interfaceC7129 == null) {
            C6635.m9824("source");
            throw null;
        }
        this.f20642 = new C7121(interfaceC7129);
        Inflater inflater = new Inflater(true);
        this.f20643 = inflater;
        this.f20644 = new C7114(this.f20642, inflater);
        this.f20645 = new CRC32();
    }

    @Override // p461.InterfaceC7129, java.io.Closeable, java.lang.AutoCloseable
    public void close() {
        this.f20644.close();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m10465(C7103 c7103, long j, long j2) {
        C7123 c7123 = c7103.f20629;
        if (c7123 == null) {
            C6635.m9822();
            throw null;
        }
        do {
            int i = c7123.f20667;
            int i2 = c7123.f20666;
            if (j < i - i2) {
                while (j2 > 0) {
                    int i3 = (int) (((long) c7123.f20666) + j);
                    int iMin = (int) Math.min(c7123.f20667 - i3, j2);
                    this.f20645.update(c7123.f20665, i3, iMin);
                    j2 -= (long) iMin;
                    c7123 = c7123.f20670;
                    if (c7123 == null) {
                        C6635.m9822();
                        throw null;
                    }
                    j = 0;
                }
                return;
            }
            j -= (long) (i - i2);
            c7123 = c7123.f20670;
        } while (c7123 != null);
        C6635.m9822();
        throw null;
    }

    @Override // p461.InterfaceC7129
    /* JADX INFO: renamed from: ؠ */
    public long mo10207(C7103 c7103, long j) throws IOException {
        long j2;
        if (c7103 == null) {
            C6635.m9824("sink");
            throw null;
        }
        if (!(j >= 0)) {
            throw new IllegalArgumentException(C2803.m4874("byteCount < 0: ", j).toString());
        }
        if (j == 0) {
            return 0L;
        }
        if (this.f20641 == 0) {
            this.f20642.mo10431(10L);
            byte bM10433 = this.f20642.f20661.m10433(3L);
            boolean z = ((bM10433 >> 1) & 1) == 1;
            if (z) {
                m10465(this.f20642.f20661, 0L, 10L);
            }
            C7121 c7121 = this.f20642;
            c7121.mo10431(2L);
            m10466("ID1ID2", 8075, c7121.f20661.readShort());
            this.f20642.skip(8L);
            if (((bM10433 >> 2) & 1) == 1) {
                this.f20642.mo10431(2L);
                if (z) {
                    m10465(this.f20642.f20661, 0L, 2L);
                }
                long jM10434 = this.f20642.f20661.m10434();
                this.f20642.mo10431(jM10434);
                if (z) {
                    j2 = jM10434;
                    m10465(this.f20642.f20661, 0L, jM10434);
                } else {
                    j2 = jM10434;
                }
                this.f20642.skip(j2);
            }
            if (((bM10433 >> 3) & 1) == 1) {
                long jM10473 = this.f20642.m10473((byte) 0);
                if (jM10473 == -1) {
                    throw new EOFException();
                }
                if (z) {
                    m10465(this.f20642.f20661, 0L, jM10473 + 1);
                }
                this.f20642.skip(jM10473 + 1);
            }
            if (((bM10433 >> 4) & 1) == 1) {
                long jM104732 = this.f20642.m10473((byte) 0);
                if (jM104732 == -1) {
                    throw new EOFException();
                }
                if (z) {
                    m10465(this.f20642.f20661, 0L, jM104732 + 1);
                }
                this.f20642.skip(jM104732 + 1);
            }
            if (z) {
                C7121 c71212 = this.f20642;
                c71212.mo10431(2L);
                m10466("FHCRC", c71212.f20661.m10434(), (short) this.f20645.getValue());
                this.f20645.reset();
            }
            this.f20641 = (byte) 1;
        }
        if (this.f20641 == 1) {
            long j3 = c7103.f20630;
            long jMo10207 = this.f20644.mo10207(c7103, j);
            if (jMo10207 != -1) {
                m10465(c7103, j3, jMo10207);
                return jMo10207;
            }
            this.f20641 = (byte) 2;
        }
        if (this.f20641 == 2) {
            m10466("CRC", this.f20642.m10472(), (int) this.f20645.getValue());
            m10466("ISIZE", this.f20642.m10472(), (int) this.f20643.getBytesWritten());
            this.f20641 = (byte) 3;
            if (!this.f20642.mo10436()) {
                throw new IOException("gzip finished without exhausting source");
            }
        }
        return -1L;
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final void m10466(String str, int i, int i2) throws IOException {
        if (i2 == i) {
            return;
        }
        String str2 = String.format("%s: actual 0x%08x != expected 0x%08x", Arrays.copyOf(new Object[]{str, Integer.valueOf(i2), Integer.valueOf(i)}, 3));
        C6635.m9823((Object) str2, "java.lang.String.format(this, *args)");
        throw new IOException(str2);
    }

    @Override // p461.InterfaceC7129
    /* JADX INFO: renamed from: ށ */
    public C7130 mo10277() {
        return this.f20642.mo10277();
    }
}
