package okio;

/* JADX INFO: compiled from: r8-map-id-ae6aab8d9a1033945587ffdd1bc6222159522c1d66e66a2c4cecb065134dd0a6 */
/* JADX INFO: loaded from: E:\ios\vf_dex\classes3.dex */
@kotlin.Metadata(d1 = {"\u0000D\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0002\b\u0004\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0010\b\n\u0002\b\u0006\u0018\u00002\u00020\u0001B\u0019\b\u0000\u0012\u0006\u0010\u0003\u001a\u00020\u0002\u0012\u0006\u0010\u0005\u001a\u00020\u0004¢\u0006\u0004\b\u0006\u0010\u0007B\u0019\b\u0016\u0012\u0006\u0010\u0003\u001a\u00020\u0001\u0012\u0006\u0010\u0005\u001a\u00020\u0004¢\u0006\u0004\b\u0006\u0010\bJ\u000f\u0010\n\u001a\u00020\tH\u0002¢\u0006\u0004\b\n\u0010\u000bJ\u001f\u0010\u0010\u001a\u00020\u000e2\u0006\u0010\r\u001a\u00020\f2\u0006\u0010\u000f\u001a\u00020\u000eH\u0016¢\u0006\u0004\b\u0010\u0010\u0011J\u001d\u0010\u0012\u001a\u00020\u000e2\u0006\u0010\r\u001a\u00020\f2\u0006\u0010\u000f\u001a\u00020\u000e¢\u0006\u0004\b\u0012\u0010\u0011J\r\u0010\u0014\u001a\u00020\u0013¢\u0006\u0004\b\u0014\u0010\u0015J\u000f\u0010\u0017\u001a\u00020\u0016H\u0016¢\u0006\u0004\b\u0017\u0010\u0018J\u000f\u0010\u0019\u001a\u00020\tH\u0016¢\u0006\u0004\b\u0019\u0010\u000bR\u0014\u0010\u0003\u001a\u00020\u00028\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0012\u0010\u001aR\u0014\u0010\u0005\u001a\u00020\u00048\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u001b\u0010\u001cR\u0016\u0010 \u001a\u00020\u001d8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b\u001e\u0010\u001fR\u0016\u0010\"\u001a\u00020\u00138\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b\u0014\u0010!¨\u0006#"}, d2 = {"Lokio/InflaterSource;", "Lokio/Source;", "Lokio/BufferedSource;", "source", "Ljava/util/zip/Inflater;", "inflater", "<init>", "(Lokio/BufferedSource;Ljava/util/zip/Inflater;)V", "(Lokio/Source;Ljava/util/zip/Inflater;)V", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "e", "()V", "Lokio/Buffer;", "sink", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "byteCount", "read", "(Lokio/Buffer;J)J", "a", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "d", "()Z", "Lokio/Timeout;", "timeout", "()Lokio/Timeout;", "close", "Lokio/BufferedSource;", "b", "Ljava/util/zip/Inflater;", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "c", "I", "bufferBytesHeldByInflater", "Z", "closed", "okio"}, k = 1, mv = {1, 9, 0}, xi = 48)
@kotlin.jvm.internal.SourceDebugExtension
public final class InflaterSource implements okio.Source {

    /* JADX INFO: renamed from: a, reason: from kotlin metadata */
    private final okio.BufferedSource source;

    /* JADX INFO: renamed from: b, reason: from kotlin metadata */
    private final java.util.zip.Inflater inflater;

    /* JADX INFO: renamed from: c, reason: from kotlin metadata */
    private int bufferBytesHeldByInflater;

    /* JADX INFO: renamed from: d, reason: from kotlin metadata */
    private boolean closed;

    public InflaterSource(okio.BufferedSource bufferedSource, java.util.zip.Inflater inflater) {
        kotlin.jvm.internal.Intrinsics.l(bufferedSource, "source");
        kotlin.jvm.internal.Intrinsics.l(inflater, "inflater");
        this.source = bufferedSource;
        this.inflater = inflater;
    }

    private final void e() {
        int i = this.bufferBytesHeldByInflater;
        if (i == 0) {
            return;
        }
        int remaining = i - this.inflater.getRemaining();
        this.bufferBytesHeldByInflater -= remaining;
        this.source.skip(remaining);
    }

    public final long a(okio.Buffer sink, long byteCount) throws java.io.IOException {
        kotlin.jvm.internal.Intrinsics.l(sink, "sink");
        if (byteCount < 0) {
            throw new java.lang.IllegalArgumentException(("byteCount < 0: " + byteCount).toString());
        }
        if (this.closed) {
            throw new java.lang.IllegalStateException("closed");
        }
        if (byteCount == 0) {
            return 0L;
        }
        try {
            okio.Segment segmentZ0 = sink.z0(1);
            int iMin = (int) java.lang.Math.min(byteCount, 8192 - segmentZ0.limit);
            d();
            int iInflate = this.inflater.inflate(segmentZ0.data, segmentZ0.limit, iMin);
            e();
            if (iInflate > 0) {
                segmentZ0.limit += iInflate;
                long j = iInflate;
                sink.n0(sink.getSize() + j);
                return j;
            }
            if (segmentZ0.pos == segmentZ0.limit) {
                sink.head = segmentZ0.b();
                okio.SegmentPool.b(segmentZ0);
            }
            return 0L;
        } catch (java.util.zip.DataFormatException e) {
            throw new java.io.IOException(e);
        }
    }

    @Override // okio.Source, java.io.Closeable, java.lang.AutoCloseable
    public void close() {
        if (this.closed) {
            return;
        }
        this.inflater.end();
        this.closed = true;
        this.source.close();
    }

    public final boolean d() {
        if (!this.inflater.needsInput()) {
            return false;
        }
        if (this.source.m2()) {
            return true;
        }
        okio.Segment segment = this.source.g().head;
        kotlin.jvm.internal.Intrinsics.i(segment);
        int i = segment.limit;
        int i2 = segment.pos;
        int i5 = i - i2;
        this.bufferBytesHeldByInflater = i5;
        this.inflater.setInput(segment.data, i2, i5);
        return false;
    }

    @Override // okio.Source
    public long read(okio.Buffer sink, long byteCount) throws java.io.IOException {
        kotlin.jvm.internal.Intrinsics.l(sink, "sink");
        do {
            long jA = a(sink, byteCount);
            if (jA > 0) {
                return jA;
            }
            if (this.inflater.finished() || this.inflater.needsDictionary()) {
                return -1L;
            }
        } while (!this.source.m2());
        throw new java.io.EOFException("source exhausted prematurely");
    }

    @Override // okio.Source
    /* JADX INFO: renamed from: timeout */
    public okio.Timeout getTimeout() {
        return this.source.getTimeout();
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public InflaterSource(okio.Source source, java.util.zip.Inflater inflater) {
        this(okio.Okio.d(source), inflater);
        kotlin.jvm.internal.Intrinsics.l(source, "source");
        kotlin.jvm.internal.Intrinsics.l(inflater, "inflater");
    }
}
