package defpackage;

import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.TimeZone;

/* renamed from: ᵩʨᵣˊ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C3784 implements InterfaceC3280 {

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public final C0963 f14127 = new C0963();

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public final boolean f14128;

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public final /* synthetic */ C4498 f14129;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public boolean f14130;

    public C3784(C4498 c4498, boolean z) {
        this.f14129 = c4498;
        this.f14128 = z;
    }

    @Override // defpackage.InterfaceC3280, java.io.Closeable, java.lang.AutoCloseable
    public final void close() throws IOException {
        C4498 c4498 = this.f14129;
        TimeZone timeZone = AbstractC4061.f15224;
        synchronized (c4498) {
            if (this.f14130) {
                return;
            }
            boolean z = c4498.m9579() == 0;
            C4498 c44982 = this.f14129;
            if (!c44982.f16759.f14128) {
                if (this.f14127.f4314 > 0) {
                    while (this.f14127.f4314 > 0) {
                        m8440(true);
                    }
                } else if (z) {
                    c44982.f16762.m9716(c44982.f16765, true, null, 0L);
                }
            }
            C4498 c44983 = this.f14129;
            synchronized (c44983) {
                this.f14130 = true;
                c44983.notifyAll();
            }
            this.f14129.f16762.flush();
            this.f14129.m9584();
        }
    }

    @Override // defpackage.InterfaceC3280, java.io.Flushable
    public final void flush() throws IOException {
        C4498 c4498 = this.f14129;
        TimeZone timeZone = AbstractC4061.f15224;
        synchronized (c4498) {
            c4498.m9581();
        }
        while (this.f14127.f4314 > 0) {
            m8440(false);
            this.f14129.f16762.flush();
        }
    }

    @Override // defpackage.InterfaceC3280
    /* renamed from: ᐧﾞ */
    public final void mo2377(C0963 c0963, long j) throws IOException {
        TimeZone timeZone = AbstractC4061.f15224;
        C0963 c09632 = this.f14127;
        c09632.mo2377(c0963, j);
        while (c09632.f4314 >= 16384) {
            m8440(false);
        }
    }

    @Override // defpackage.InterfaceC3280
    /* renamed from: ᵝᵵᵺ */
    public final C3948 mo2378() {
        return this.f14129.f16766;
    }

    /* JADX WARN: Finally extract failed */
    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final void m8440(boolean z) throws IOException {
        long jMin;
        boolean z2;
        C4498 c4498 = this.f14129;
        synchronized (c4498) {
            c4498.f16766.m9835();
            while (c4498.f16768 >= c4498.f16763 && !this.f14128 && !this.f14130 && c4498.m9579() == 0) {
                try {
                    try {
                        c4498.wait();
                    } catch (InterruptedException unused) {
                        Thread.currentThread().interrupt();
                        throw new InterruptedIOException();
                    }
                } catch (Throwable th) {
                    c4498.f16766.m2864();
                    throw th;
                }
            }
            c4498.f16766.m2864();
            c4498.m9581();
            jMin = Math.min(c4498.f16763 - c4498.f16768, this.f14127.f4314);
            c4498.f16768 += jMin;
            z2 = z && jMin == this.f14127.f4314;
        }
        this.f14129.f16766.m9835();
        try {
            C4498 c44982 = this.f14129;
            c44982.f16762.m9716(c44982.f16765, z2, this.f14127, jMin);
        } finally {
            this.f14129.f16766.m2864();
        }
    }
}
