package o;

import java.io.InterruptedIOException;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class OF implements R80 {
    public final boolean l;
    public final C0732af m = new C0732af();
    public boolean n;

    /* renamed from: o, reason: collision with root package name */
    public final /* synthetic */ RF f266o;

    public OF(RF rf, boolean z) {
        this.f266o = rf;
        this.l = z;
    }

    @Override // o.R80
    public final Cf0 a() {
        return this.f266o.l;
    }

    /* JADX WARN: Finally extract failed */
    public final void b(boolean z) {
        long jMin;
        boolean z2;
        RF rf = this.f266o;
        synchronized (rf) {
            rf.l.h();
            while (rf.e >= rf.f && !this.l && !this.n) {
                try {
                    synchronized (rf) {
                        int i = rf.m;
                        if (i != 0) {
                            break;
                        }
                        try {
                            rf.wait();
                        } catch (InterruptedException unused) {
                            Thread.currentThread().interrupt();
                            throw new InterruptedIOException();
                        }
                    }
                } catch (Throwable th) {
                    rf.l.k();
                    throw th;
                }
            }
            rf.l.k();
            rf.b();
            jMin = Math.min(rf.f - rf.e, this.m.m);
            rf.e += jMin;
            z2 = z && jMin == this.m.m;
        }
        this.f266o.l.h();
        try {
            RF rf2 = this.f266o;
            rf2.b.j(rf2.a, z2, this.m, jMin);
        } finally {
            this.f266o.l.k();
        }
    }

    @Override // o.R80, java.io.Closeable, java.lang.AutoCloseable
    public final void close() {
        boolean z;
        RF rf = this.f266o;
        byte[] bArr = AbstractC2264qi0.a;
        synchronized (rf) {
            if (this.n) {
                return;
            }
            synchronized (rf) {
                z = rf.m == 0;
            }
            RF rf2 = this.f266o;
            if (!rf2.j.l) {
                if (this.m.m > 0) {
                    while (this.m.m > 0) {
                        b(true);
                    }
                } else if (z) {
                    rf2.b.j(rf2.a, true, null, 0L);
                }
            }
            synchronized (this.f266o) {
                this.n = true;
            }
            this.f266o.b.flush();
            this.f266o.a();
        }
    }

    @Override // o.R80
    public final void e(long j, C0732af c0732af) {
        byte[] bArr = AbstractC2264qi0.a;
        C0732af c0732af2 = this.m;
        c0732af2.e(j, c0732af);
        while (c0732af2.m >= 16384) {
            b(false);
        }
    }

    @Override // o.R80, java.io.Flushable
    public final void flush() {
        RF rf = this.f266o;
        byte[] bArr = AbstractC2264qi0.a;
        synchronized (rf) {
            rf.b();
        }
        while (this.m.m > 0) {
            b(false);
            this.f266o.b.flush();
        }
    }
}
