package okio;

/* JADX INFO: compiled from: r8-map-id-ae6aab8d9a1033945587ffdd1bc6222159522c1d66e66a2c4cecb065134dd0a6 */
/* JADX INFO: loaded from: E:\ios\vf_dex\classes3.dex */
@kotlin.Metadata(d1 = {"\u0000`\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0002\b\u0004\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010\b\n\u0002\b\u0007\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u0005\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\u0018\u00002\u00020\u0001B\u000f\u0012\u0006\u0010\u0002\u001a\u00020\u0001¢\u0006\u0004\b\u0003\u0010\u0004J\u000f\u0010\u0006\u001a\u00020\u0005H\u0002¢\u0006\u0004\b\u0006\u0010\u0007J\u000f\u0010\b\u001a\u00020\u0005H\u0002¢\u0006\u0004\b\b\u0010\u0007J'\u0010\u000e\u001a\u00020\u00052\u0006\u0010\n\u001a\u00020\t2\u0006\u0010\f\u001a\u00020\u000b2\u0006\u0010\r\u001a\u00020\u000bH\u0002¢\u0006\u0004\b\u000e\u0010\u000fJ'\u0010\u0015\u001a\u00020\u00052\u0006\u0010\u0011\u001a\u00020\u00102\u0006\u0010\u0013\u001a\u00020\u00122\u0006\u0010\u0014\u001a\u00020\u0012H\u0002¢\u0006\u0004\b\u0015\u0010\u0016J\u001f\u0010\u0018\u001a\u00020\u000b2\u0006\u0010\u0017\u001a\u00020\t2\u0006\u0010\r\u001a\u00020\u000bH\u0016¢\u0006\u0004\b\u0018\u0010\u0019J\u000f\u0010\u001b\u001a\u00020\u001aH\u0016¢\u0006\u0004\b\u001b\u0010\u001cJ\u000f\u0010\u001d\u001a\u00020\u0005H\u0016¢\u0006\u0004\b\u001d\u0010\u0007R\u0016\u0010 \u001a\u00020\u001e8\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b\u0015\u0010\u001fR\u0014\u0010\u0002\u001a\u00020!8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\"\u0010#R\u0014\u0010'\u001a\u00020$8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b%\u0010&R\u0014\u0010*\u001a\u00020(8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0006\u0010)R\u0014\u0010-\u001a\u00020+8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\b\u0010,¨\u0006."}, d2 = {"Lokio/GzipSource;", "Lokio/Source;", "source", "<init>", "(Lokio/Source;)V", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "d", "()V", "e", "Lokio/Buffer;", "buffer", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "offset", "byteCount", "i", "(Lokio/Buffer;JJ)V", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "name", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "expected", "actual", "a", "(Ljava/lang/String;II)V", "sink", "read", "(Lokio/Buffer;J)J", "Lokio/Timeout;", "timeout", "()Lokio/Timeout;", "close", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "B", "section", "Lokio/RealBufferedSource;", "b", "Lokio/RealBufferedSource;", "Ljava/util/zip/Inflater;", "c", "Ljava/util/zip/Inflater;", "inflater", "Lokio/InflaterSource;", "Lokio/InflaterSource;", "inflaterSource", "Ljava/util/zip/CRC32;", "Ljava/util/zip/CRC32;", "crc", "okio"}, k = 1, mv = {1, 9, 0}, xi = 48)
@kotlin.jvm.internal.SourceDebugExtension
public final class GzipSource implements okio.Source {

    /* JADX INFO: renamed from: a, reason: from kotlin metadata */
    private byte section;

    /* JADX INFO: renamed from: b, reason: from kotlin metadata */
    private final okio.buffer source;

    /* JADX INFO: renamed from: c, reason: from kotlin metadata */
    private final java.util.zip.Inflater inflater;

    /* JADX INFO: renamed from: d, reason: from kotlin metadata */
    private final okio.InflaterSource inflaterSource;

    /* JADX INFO: renamed from: e, reason: from kotlin metadata */
    private final java.util.zip.CRC32 crc;

    public GzipSource(okio.Source source) {
        kotlin.jvm.internal.Intrinsics.l(source, "source");
        okio.buffer bufferVar = new okio.buffer(source);
        this.source = bufferVar;
        java.util.zip.Inflater inflater = new java.util.zip.Inflater(true);
        this.inflater = inflater;
        this.inflaterSource = new okio.InflaterSource((okio.BufferedSource) bufferVar, inflater);
        this.crc = new java.util.zip.CRC32();
    }

    private final void a(java.lang.String name, int expected, int actual) throws java.io.IOException {
        if (actual == expected) {
            return;
        }
        java.lang.String str = java.lang.String.format("%s: actual 0x%08x != expected 0x%08x", java.util.Arrays.copyOf(new java.lang.Object[]{name, java.lang.Integer.valueOf(actual), java.lang.Integer.valueOf(expected)}, 3));
        kotlin.jvm.internal.Intrinsics.k(str, "format(...)");
        throw new java.io.IOException(str);
    }

    private final void d() throws java.io.IOException {
        this.source.b2(10L);
        byte bU = this.source.bufferField.u(3L);
        boolean z = ((bU >> 1) & 1) == 1;
        if (z) {
            i(this.source.bufferField, 0L, 10L);
        }
        a("ID1ID2", 8075, this.source.readShort());
        this.source.skip(8L);
        if (((bU >> 2) & 1) == 1) {
            this.source.b2(2L);
            if (z) {
                i(this.source.bufferField, 0L, 2L);
            }
            long jJ0 = this.source.bufferField.j0() & 65535;
            this.source.b2(jJ0);
            if (z) {
                i(this.source.bufferField, 0L, jJ0);
            }
            this.source.skip(jJ0);
        }
        if (((bU >> 3) & 1) == 1) {
            long jA = this.source.a((byte) 0);
            if (jA == -1) {
                throw new java.io.EOFException();
            }
            if (z) {
                i(this.source.bufferField, 0L, jA + 1);
            }
            this.source.skip(jA + 1);
        }
        if (((bU >> 4) & 1) == 1) {
            long jA2 = this.source.a((byte) 0);
            if (jA2 == -1) {
                throw new java.io.EOFException();
            }
            if (z) {
                i(this.source.bufferField, 0L, jA2 + 1);
            }
            this.source.skip(jA2 + 1);
        }
        if (z) {
            a("FHCRC", this.source.j0(), (short) this.crc.getValue());
            this.crc.reset();
        }
    }

    private final void e() throws java.io.IOException {
        a("CRC", this.source.E2(), (int) this.crc.getValue());
        a("ISIZE", this.source.E2(), (int) this.inflater.getBytesWritten());
    }

    private final void i(okio.Buffer buffer, long offset, long byteCount) {
        okio.Segment segment = buffer.head;
        kotlin.jvm.internal.Intrinsics.i(segment);
        while (true) {
            int i = segment.limit;
            int i2 = segment.pos;
            if (offset < i - i2) {
                break;
            }
            offset -= (long) (i - i2);
            segment = segment.next;
            kotlin.jvm.internal.Intrinsics.i(segment);
        }
        while (byteCount > 0) {
            int i5 = (int) (((long) segment.pos) + offset);
            int iMin = (int) java.lang.Math.min(segment.limit - i5, byteCount);
            this.crc.update(segment.data, i5, iMin);
            byteCount -= (long) iMin;
            segment = segment.next;
            kotlin.jvm.internal.Intrinsics.i(segment);
            offset = 0;
        }
    }

    @Override // okio.Source, java.io.Closeable, java.lang.AutoCloseable
    public void close() {
        this.inflaterSource.close();
    }

    @Override // okio.Source
    public long read(okio.Buffer sink, long byteCount) throws java.io.IOException {
        okio.GzipSource gzipSource;
        kotlin.jvm.internal.Intrinsics.l(sink, "sink");
        if (byteCount < 0) {
            throw new java.lang.IllegalArgumentException(("byteCount < 0: " + byteCount).toString());
        }
        if (byteCount == 0) {
            return 0L;
        }
        if (this.section == 0) {
            d();
            this.section = (byte) 1;
        }
        if (this.section == 1) {
            long size = sink.getSize();
            long j = this.inflaterSource.read(sink, byteCount);
            if (j != -1) {
                i(sink, size, j);
                return j;
            }
            gzipSource = this;
            gzipSource.section = (byte) 2;
        } else {
            gzipSource = this;
        }
        if (gzipSource.section == 2) {
            gzipSource.e();
            gzipSource.section = (byte) 3;
            if (!gzipSource.source.m2()) {
                throw new java.io.IOException("gzip finished without exhausting source");
            }
        }
        return -1L;
    }

    @Override // okio.Source
    /* JADX INFO: renamed from: timeout */
    public okio.Timeout getTimeout() {
        return this.source.getTimeout();
    }
}
