package f;

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

/* JADX INFO: compiled from: InflaterSource.java */
/* JADX INFO: loaded from: classes.dex */
public final class l implements t {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final e f3091c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private final Inflater f3092d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private int f3093e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private boolean f3094f;

    l(e eVar, Inflater inflater) {
        if (eVar == null) {
            throw new IllegalArgumentException("source == null");
        }
        if (inflater == null) {
            throw new IllegalArgumentException("inflater == null");
        }
        this.f3091c = eVar;
        this.f3092d = inflater;
    }

    private void c() throws IOException {
        int i = this.f3093e;
        if (i == 0) {
            return;
        }
        int remaining = i - this.f3092d.getRemaining();
        this.f3093e -= remaining;
        this.f3091c.skip(remaining);
    }

    public boolean b() throws IOException {
        if (!this.f3092d.needsInput()) {
            return false;
        }
        c();
        if (this.f3092d.getRemaining() != 0) {
            throw new IllegalStateException("?");
        }
        if (this.f3091c.m()) {
            return true;
        }
        p pVar = this.f3091c.buffer().f3075d;
        int i = pVar.f3110c;
        int i2 = pVar.f3109b;
        int i3 = i - i2;
        this.f3093e = i3;
        this.f3092d.setInput(pVar.f3108a, i2, i3);
        return false;
    }

    @Override // f.t, java.io.Closeable, java.lang.AutoCloseable
    public void close() throws IOException {
        if (this.f3094f) {
            return;
        }
        this.f3092d.end();
        this.f3094f = true;
        this.f3091c.close();
    }

    @Override // f.t
    public long read(c cVar, long j) throws IOException {
        boolean zB;
        if (j < 0) {
            throw new IllegalArgumentException("byteCount < 0: " + j);
        }
        if (this.f3094f) {
            throw new IllegalStateException("closed");
        }
        if (j == 0) {
            return 0L;
        }
        do {
            zB = b();
            try {
                p pVarD = cVar.D(1);
                Inflater inflater = this.f3092d;
                byte[] bArr = pVarD.f3108a;
                int i = pVarD.f3110c;
                int iInflate = inflater.inflate(bArr, i, 8192 - i);
                if (iInflate > 0) {
                    pVarD.f3110c += iInflate;
                    long j2 = iInflate;
                    cVar.f3076e += j2;
                    return j2;
                }
                if (!this.f3092d.finished() && !this.f3092d.needsDictionary()) {
                }
                c();
                if (pVarD.f3109b != pVarD.f3110c) {
                    return -1L;
                }
                cVar.f3075d = pVarD.b();
                q.a(pVarD);
                return -1L;
            } catch (DataFormatException e2) {
                throw new IOException(e2);
            }
        } while (!zB);
        throw new EOFException("source exhausted prematurely");
    }

    @Override // f.t
    public u timeout() {
        return this.f3091c.timeout();
    }
}
