package okio;

import g.a.a.a.a;
import io.netty.handler.codec.rtsp.RtspHeaders;
import java.io.EOFException;
import java.io.IOException;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;
import kotlin.Metadata;
import kotlin.jvm.internal.o;

/* JADX INFO: renamed from: z.l, reason: from Kotlin metadata */
/* JADX INFO: loaded from: classes2.dex */
@Metadata(d1 = {"\u0000@\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0000\n\u0002\u0010\u000b\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\t\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0000\u0018\u00002\u00020\u0001B\u0017\b\u0016\u0012\u0006\u0010\u0002\u001a\u00020\u0001\u0012\u0006\u0010\u0003\u001a\u00020\u0004¢\u0006\u0002\u0010\u0005B\u0017\b\u0000\u0012\u0006\u0010\u0002\u001a\u00020\u0006\u0012\u0006\u0010\u0003\u001a\u00020\u0004¢\u0006\u0002\u0010\u0007J\b\u0010\f\u001a\u00020\rH\u0016J\u0018\u0010\u000e\u001a\u00020\u000f2\u0006\u0010\u0010\u001a\u00020\u00112\u0006\u0010\u0012\u001a\u00020\u000fH\u0016J\u0016\u0010\u0013\u001a\u00020\u000f2\u0006\u0010\u0010\u001a\u00020\u00112\u0006\u0010\u0012\u001a\u00020\u000fJ\u0006\u0010\u0014\u001a\u00020\u000bJ\b\u0010\u0015\u001a\u00020\rH\u0002J\b\u0010\u0016\u001a\u00020\u0017H\u0016R\u000e\u0010\b\u001a\u00020\tX\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\n\u001a\u00020\u000bX\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0003\u001a\u00020\u0004X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0002\u001a\u00020\u0006X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\u0018"}, d2 = {"Lokio/InflaterSource;", "Lokio/Source;", "source", "inflater", "Ljava/util/zip/Inflater;", "(Lokio/Source;Ljava/util/zip/Inflater;)V", "Lokio/BufferedSource;", "(Lokio/BufferedSource;Ljava/util/zip/Inflater;)V", "bufferBytesHeldByInflater", "", "closed", "", "close", "", "read", "", "sink", "Lokio/Buffer;", "byteCount", "readOrInflate", "refill", "releaseBytesAfterInflate", RtspHeaders.Values.TIMEOUT, "Lokio/Timeout;", "okio"}, k = 1, mv = {1, 6, 0}, xi = 48)
public final class InflaterSource implements Source {

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final BufferedSource f10133f;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final Inflater f10134m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public int f10135n;

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

    public InflaterSource(BufferedSource bufferedSource, Inflater inflater) {
        o.f(bufferedSource, "source");
        o.f(inflater, "inflater");
        this.f10133f = bufferedSource;
        this.f10134m = inflater;
    }

    @Override // okio.Source, java.io.Closeable, java.lang.AutoCloseable
    public void close() {
        if (this.f10136o) {
            return;
        }
        this.f10134m.end();
        this.f10136o = true;
        this.f10133f.close();
    }

    @Override // okio.Source
    public long r(Buffer buffer, long j2) throws IOException {
        long j3;
        o.f(buffer, "sink");
        do {
            o.f(buffer, "sink");
            if (!(j2 >= 0)) {
                throw new IllegalArgumentException(a.q("byteCount < 0: ", j2).toString());
            }
            if (!(!this.f10136o)) {
                throw new IllegalStateException("closed".toString());
            }
            if (j2 == 0) {
                j3 = 0;
            } else {
                try {
                    Segment segmentX = buffer.x(1);
                    int iMin = (int) Math.min(j2, 8192 - segmentX.f10152c);
                    if (this.f10134m.needsInput() && !this.f10133f.f()) {
                        Segment segment = this.f10133f.getBuffer().f10117f;
                        o.c(segment);
                        int i2 = segment.f10152c;
                        int i3 = segment.f10151b;
                        int i4 = i2 - i3;
                        this.f10135n = i4;
                        this.f10134m.setInput(segment.a, i3, i4);
                    }
                    int iInflate = this.f10134m.inflate(segmentX.a, segmentX.f10152c, iMin);
                    int i5 = this.f10135n;
                    if (i5 != 0) {
                        int remaining = i5 - this.f10134m.getRemaining();
                        this.f10135n -= remaining;
                        this.f10133f.skip(remaining);
                    }
                    if (iInflate > 0) {
                        segmentX.f10152c += iInflate;
                        j3 = iInflate;
                        buffer.f10118m += j3;
                    } else {
                        if (segmentX.f10151b == segmentX.f10152c) {
                            buffer.f10117f = segmentX.a();
                            SegmentPool.a(segmentX);
                        }
                        j3 = 0;
                    }
                } catch (DataFormatException e2) {
                    throw new IOException(e2);
                }
            }
            if (j3 > 0) {
                return j3;
            }
            if (this.f10134m.finished() || this.f10134m.needsDictionary()) {
                return -1L;
            }
        } while (!this.f10133f.f());
        throw new EOFException("source exhausted prematurely");
    }

    @Override // okio.Source
    public Timeout timeout() {
        return this.f10133f.timeout();
    }
}
