package okhttp3.internal.ws;

import g.h0.c.l;
import j.b0;
import j.d;
import j.o;
import java.io.Closeable;
import java.io.IOException;
import java.util.zip.Inflater;
import okhttp3.internal.http2.Settings;

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

    public MessageInflater(boolean z) {
        this.noContextTakeover = z;
        d dVar = new d();
        this.deflatedBytes = dVar;
        Inflater inflater = new Inflater(true);
        this.inflater = inflater;
        this.inflaterSource = new o((b0) dVar, inflater);
    }

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

    public final void inflate(d dVar) throws IOException {
        l.f(dVar, "buffer");
        if (!(this.deflatedBytes.f4601e == 0)) {
            throw new IllegalArgumentException("Failed requirement.".toString());
        }
        if (this.noContextTakeover) {
            this.inflater.reset();
        }
        this.deflatedBytes.writeAll(dVar);
        this.deflatedBytes.J(Settings.DEFAULT_INITIAL_WINDOW_SIZE);
        long bytesRead = this.inflater.getBytesRead() + this.deflatedBytes.f4601e;
        do {
            this.inflaterSource.a(dVar, Long.MAX_VALUE);
        } while (this.inflater.getBytesRead() < bytesRead);
    }
}
