package o;

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

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class LZ extends InputStream {
    public int l;
    public int m;
    public final /* synthetic */ NZ n;

    public LZ(NZ nz, KZ kz) {
        this.n = nz;
        this.l = nz.w(kz.b + 4);
        this.m = kz.c;
    }

    @Override // java.io.InputStream
    public final int read(byte[] bArr, int i, int i2) throws IOException {
        if (bArr == null) {
            throw new NullPointerException("buffer");
        }
        if ((i | i2) < 0 || i2 > bArr.length - i) {
            throw new ArrayIndexOutOfBoundsException();
        }
        int i3 = this.m;
        if (i3 <= 0) {
            return -1;
        }
        if (i2 > i3) {
            i2 = i3;
        }
        int i4 = this.l;
        NZ nz = this.n;
        nz.m(bArr, i4, i, i2);
        this.l = nz.w(this.l + i2);
        this.m -= i2;
        return i2;
    }

    @Override // java.io.InputStream
    public final int read() throws IOException {
        if (this.m == 0) {
            return -1;
        }
        NZ nz = this.n;
        nz.l.seek(this.l);
        int i = nz.l.read();
        this.l = nz.w(this.l + 1);
        this.m--;
        return i;
    }
}
