/*
 * Decompiled with CFR 0.152.
 */
import java.io.InputStream;

public final class ks
extends InputStream {
    private int a;
    private byte[] b;
    private int c;
    private int d;
    private InputStream e;

    public final int read(byte[] byArray, int n, int n2) {
        if (this.a()) {
            n2 = Math.min(n2, this.d - this.c);
            System.arraycopy(this.b, this.c, byArray, n, n2);
            this.c += n2;
            this.a -= n2;
            return n2;
        }
        return -1;
    }

    public final int read() {
        if (this.a()) {
            --this.a;
            return this.b[this.c++] & 0xFF;
        }
        return -1;
    }

    private boolean a() {
        block2: {
            block4: {
                block3: {
                    if (this.a <= 0) break block2;
                    if (this.c < this.d) break block3;
                    this.d = this.e.read(this.b, 0, Math.min(this.a, this.b.length));
                    if (this.d <= 0) break block4;
                    this.c = 0;
                }
                return true;
            }
            this.a = 0;
        }
        return false;
    }

    public ks(InputStream inputStream, int n) {
        this.e = inputStream;
        this.a = n;
        this.b = new byte[Math.min(n, 4096)];
    }

    public final int available() {
        return this.d - this.c;
    }
}

