package g2;

import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;

/* JADX INFO: compiled from: IndefiniteLengthInputStream.java */
/* JADX INFO: loaded from: classes.dex */
class t1 extends w1 {

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private int f4746g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private int f4747h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private boolean f4748i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private boolean f4749j;

    t1(InputStream inputStream, int i3) throws IOException {
        super(inputStream, i3);
        this.f4748i = false;
        this.f4749j = true;
        this.f4746g = inputStream.read();
        int i4 = inputStream.read();
        this.f4747h = i4;
        if (i4 < 0) {
            throw new EOFException();
        }
        c();
    }

    private boolean c() {
        if (!this.f4748i && this.f4749j && this.f4746g == 0 && this.f4747h == 0) {
            this.f4748i = true;
            b(true);
        }
        return this.f4748i;
    }

    void d(boolean z2) {
        this.f4749j = z2;
        c();
    }

    @Override // java.io.InputStream
    public int read(byte[] bArr, int i3, int i4) throws IOException {
        if (this.f4749j || i4 < 3) {
            return super.read(bArr, i3, i4);
        }
        if (this.f4748i) {
            return -1;
        }
        int i5 = this.f4762e.read(bArr, i3 + 2, i4 - 2);
        if (i5 < 0) {
            throw new EOFException();
        }
        bArr[i3] = (byte) this.f4746g;
        bArr[i3 + 1] = (byte) this.f4747h;
        this.f4746g = this.f4762e.read();
        int i6 = this.f4762e.read();
        this.f4747h = i6;
        if (i6 >= 0) {
            return i5 + 2;
        }
        throw new EOFException();
    }

    @Override // java.io.InputStream
    public int read() throws IOException {
        if (c()) {
            return -1;
        }
        int i3 = this.f4762e.read();
        if (i3 >= 0) {
            int i4 = this.f4746g;
            this.f4746g = this.f4747h;
            this.f4747h = i3;
            return i4;
        }
        throw new EOFException();
    }
}
