package okhttp3.internal.ws;

import androidx.core.location.LocationRequestCompat;
import java.io.Closeable;
import java.io.IOException;
import java.util.zip.Inflater;
import kotlin.jvm.internal.l;
import okio.C0688f;
import okio.E;
import okio.o;

/* JADX INFO: loaded from: classes2.dex */
public final class MessageInflater implements Closeable {
    private final C0688f deflatedBytes;
    private final Inflater inflater;
    private final o inflaterSource;
    private final boolean noContextTakeover;

    public MessageInflater(boolean z2) {
        this.noContextTakeover = z2;
        C0688f c0688f = new C0688f();
        this.deflatedBytes = c0688f;
        Inflater inflater = new Inflater(true);
        this.inflater = inflater;
        this.inflaterSource = new o((E) c0688f, inflater);
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable
    public void close() throws IOException {
        this.inflaterSource.close();
    }

    public final void inflate(C0688f buffer) throws IOException {
        l.e(buffer, "buffer");
        if (!(this.deflatedBytes.G() == 0)) {
            throw new IllegalArgumentException("Failed requirement.");
        }
        if (this.noContextTakeover) {
            this.inflater.reset();
        }
        this.deflatedBytes.writeAll(buffer);
        this.deflatedBytes.writeInt(65535);
        long bytesRead = this.inflater.getBytesRead() + this.deflatedBytes.G();
        do {
            this.inflaterSource.a(buffer, LocationRequestCompat.PASSIVE_INTERVAL);
        } while (this.inflater.getBytesRead() < bytesRead);
    }
}
