package com.google.android.gms.internal.ads;

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

/* JADX INFO: loaded from: classes2.dex */
public final class it1 extends FilterInputStream {

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

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

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

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public it1(InputStream inputStream, long j10, int i10) {
        super(inputStream);
        this.f12631a = i10;
        if (i10 == 1) {
            super(inputStream);
            this.f12632b = j10;
            return;
        }
        this.f12633c = -1L;
        inputStream.getClass();
        ih1.e0("limit must be non-negative", j10 >= 0);
        this.f12632b = j10;
    }

    private final synchronized void e() {
        if (!((FilterInputStream) this).in.markSupported()) {
            throw new IOException("Mark not supported");
        }
        if (this.f12633c == -1) {
            throw new IOException("Mark not set");
        }
        ((FilterInputStream) this).in.reset();
        this.f12632b = this.f12633c;
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public final int available() {
        switch (this.f12631a) {
            case 0:
                return (int) Math.min(((FilterInputStream) this).in.available(), this.f12632b);
            default:
                return super.available();
        }
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public final synchronized void mark(int i10) {
        switch (this.f12631a) {
            case 0:
                synchronized (this) {
                    ((FilterInputStream) this).in.mark(i10);
                    this.f12633c = this.f12632b;
                }
                return;
            default:
                super.mark(i10);
                return;
        }
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public final int read() throws IOException {
        switch (this.f12631a) {
            case 0:
                if (this.f12632b == 0) {
                    return -1;
                }
                int i10 = ((FilterInputStream) this).in.read();
                if (i10 != -1) {
                    this.f12632b--;
                }
                return i10;
            default:
                int i11 = super.read();
                if (i11 != -1) {
                    this.f12633c++;
                }
                return i11;
        }
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public final synchronized void reset() {
        switch (this.f12631a) {
            case 0:
                e();
                return;
            default:
                super.reset();
                return;
        }
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public final long skip(long j10) throws IOException {
        switch (this.f12631a) {
            case 0:
                long jSkip = ((FilterInputStream) this).in.skip(Math.min(j10, this.f12632b));
                this.f12632b -= jSkip;
                return jSkip;
            default:
                return super.skip(j10);
        }
    }

    @Override // java.io.FilterInputStream, java.io.InputStream
    public final int read(byte[] bArr, int i10, int i11) throws IOException {
        switch (this.f12631a) {
            case 0:
                long j10 = this.f12632b;
                if (j10 == 0) {
                    return -1;
                }
                int i12 = ((FilterInputStream) this).in.read(bArr, i10, (int) Math.min(i11, j10));
                if (i12 != -1) {
                    this.f12632b -= (long) i12;
                }
                return i12;
            default:
                int i13 = super.read(bArr, i10, i11);
                if (i13 != -1) {
                    this.f12633c += (long) i13;
                }
                return i13;
        }
    }
}
