package m4;

import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import k4.AbstractC2400m;

/* JADX INFO: renamed from: m4.b1, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes3.dex */
public final class C2493b1 extends FilterInputStream {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final int f20950a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final g2 f20951b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public long f20952c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public long f20953d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public long f20954e;

    public C2493b1(InputStream inputStream, int i6, g2 g2Var) {
        super(inputStream);
        this.f20954e = -1L;
        this.f20950a = i6;
        this.f20951b = g2Var;
    }

    public final void a() {
        long j4 = this.f20953d;
        long j6 = this.f20952c;
        if (j4 > j6) {
            long j7 = j4 - j6;
            for (AbstractC2400m abstractC2400m : this.f20951b.f21042a) {
                abstractC2400m.f(j7);
            }
            this.f20952c = this.f20953d;
        }
    }

    public final void b() {
        long j4 = this.f20953d;
        int i6 = this.f20950a;
        if (j4 <= i6) {
            return;
        }
        throw new k4.t0(k4.r0.f19944k.g("Decompressed gRPC message exceeds maximum size " + i6));
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public final synchronized void mark(int i6) {
        ((FilterInputStream) this).in.mark(i6);
        this.f20954e = this.f20953d;
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public final int read() throws IOException {
        int i6 = ((FilterInputStream) this).in.read();
        if (i6 != -1) {
            this.f20953d++;
        }
        b();
        a();
        return i6;
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public final synchronized void reset() {
        if (!((FilterInputStream) this).in.markSupported()) {
            throw new IOException("Mark not supported");
        }
        if (this.f20954e == -1) {
            throw new IOException("Mark not set");
        }
        ((FilterInputStream) this).in.reset();
        this.f20953d = this.f20954e;
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public final long skip(long j4) throws IOException {
        long jSkip = ((FilterInputStream) this).in.skip(j4);
        this.f20953d += jSkip;
        b();
        a();
        return jSkip;
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public final int read(byte[] bArr, int i6, int i7) throws IOException {
        int i8 = ((FilterInputStream) this).in.read(bArr, i6, i7);
        if (i8 != -1) {
            this.f20953d += (long) i8;
        }
        b();
        a();
        return i8;
    }
}
