package o;

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

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.Vw, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C0567Vw extends LB {
    public final long m;
    public long n;

    /* renamed from: o, reason: collision with root package name */
    public boolean f388o;
    public boolean p;
    public boolean q;
    public final /* synthetic */ C2398s4 r;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public C0567Vw(C2398s4 c2398s4, T90 t90, long j) {
        super(t90);
        this.r = c2398s4;
        this.m = j;
        this.f388o = true;
        if (j == 0) {
            b(null);
        }
    }

    @Override // o.T90
    public final long C(long j, C0732af c0732af) throws IOException {
        if (this.q) {
            throw new IllegalStateException("closed");
        }
        try {
            long jC = this.l.C(j, c0732af);
            if (this.f388o) {
                this.f388o = false;
            }
            if (jC == -1) {
                b(null);
                return -1L;
            }
            long j2 = this.n + jC;
            long j3 = this.m;
            if (j3 == -1 || j2 <= j3) {
                this.n = j2;
                if (j2 == j3) {
                    b(null);
                }
                return jC;
            }
            throw new ProtocolException("expected " + j3 + " bytes but received " + j2);
        } catch (IOException e) {
            throw b(e);
        }
    }

    public final IOException b(IOException iOException) {
        if (this.p) {
            return iOException;
        }
        this.p = true;
        if (iOException == null && this.f388o) {
            this.f388o = false;
        }
        return this.r.c(true, false, iOException);
    }

    @Override // o.LB, java.io.Closeable, java.lang.AutoCloseable
    public final void close() throws IOException {
        if (this.q) {
            return;
        }
        this.q = true;
        try {
            super.close();
            b(null);
        } catch (IOException e) {
            throw b(e);
        }
    }
}
