package defpackage;

import java.io.IOException;
import java.net.ProtocolException;

/* renamed from: ᵚˏᵙ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C2664 implements InterfaceC3280 {

    /* renamed from: ˀᵗᵝᵭ, reason: contains not printable characters */
    public boolean f10339;

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public final /* synthetic */ C4699 f10340;

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public boolean f10341;

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public final long f10342;

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public long f10343;

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

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public boolean f10345;

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

    public C2664(C4699 c4699, InterfaceC3280 interfaceC3280, long j, boolean z) {
        this.f10340 = c4699;
        this.f10344 = interfaceC3280;
        this.f10342 = j;
        this.f10346 = z;
        this.f10341 = z;
    }

    @Override // defpackage.InterfaceC3280, java.io.Closeable, java.lang.AutoCloseable
    public final void close() throws IOException {
        if (this.f10339) {
            return;
        }
        this.f10339 = true;
        long j = this.f10342;
        if (j != -1 && this.f10343 != j) {
            throw new ProtocolException("unexpected end of stream");
        }
        try {
            m6660();
            m6659(null);
        } catch (IOException e) {
            throw m6659(e);
        }
    }

    @Override // defpackage.InterfaceC3280, java.io.Flushable
    public final void flush() throws IOException {
        try {
            m6658();
        } catch (IOException e) {
            throw m6659(e);
        }
    }

    public final String toString() {
        return C2664.class.getSimpleName() + '(' + this.f10344 + ')';
    }

    /* renamed from: ˌʾˀ, reason: contains not printable characters */
    public final void m6658() {
        this.f10344.flush();
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final IOException m6659(IOException iOException) {
        if (this.f10345) {
            return iOException;
        }
        this.f10345 = true;
        return C4699.m9878(this.f10340, this.f10346, iOException, 4);
    }

    @Override // defpackage.InterfaceC3280
    /* renamed from: ᐧﾞ */
    public final void mo2377(C0963 c0963, long j) throws IOException {
        if (this.f10339) {
            ᵹˉᵞ.ᵳٴᵶ("closed");
            return;
        }
        long j2 = this.f10342;
        if (j2 != -1 && this.f10343 + j > j2) {
            StringBuilder sbM4110 = AbstractC1327.m4110(j2, "expected ", " bytes but received ");
            sbM4110.append(this.f10343 + j);
            throw new ProtocolException(sbM4110.toString());
        }
        try {
            if (this.f10341) {
                this.f10341 = false;
            }
            this.f10344.mo2377(c0963, j);
            this.f10343 += j;
        } catch (IOException e) {
            throw m6659(e);
        }
    }

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

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final void m6660() {
        this.f10344.close();
    }
}
