package v;

import java.io.EOFException;
import java.util.Arrays;

/* JADX INFO: renamed from: v.b, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0726b implements f {

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private static final byte[] f6564g = new byte[4096];

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private final a0.f f6565a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final long f6566b;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private byte[] f6568d = new byte[8192];

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

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

    public C0726b(a0.f fVar, long j2, long j3) {
        this.f6565a = fVar;
        this.f6567c = j2;
        this.f6566b = j3;
    }

    private void l(int i2) {
        if (i2 != -1) {
            this.f6567c += (long) i2;
        }
    }

    private void m(int i2) {
        int i3 = this.f6569e + i2;
        byte[] bArr = this.f6568d;
        if (i3 > bArr.length) {
            this.f6568d = Arrays.copyOf(bArr, Math.max(bArr.length * 2, i3));
        }
    }

    private int n(byte[] bArr, int i2, int i3, int i4, boolean z2) throws InterruptedException, EOFException {
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        int i5 = this.f6565a.read(bArr, i2 + i4, i3 - i4);
        if (i5 != -1) {
            return i4 + i5;
        }
        if (i4 == 0 && z2) {
            return -1;
        }
        throw new EOFException();
    }

    private int o(byte[] bArr, int i2, int i3) {
        int i4 = this.f6570f;
        if (i4 == 0) {
            return 0;
        }
        int iMin = Math.min(i4, i3);
        System.arraycopy(this.f6568d, 0, bArr, i2, iMin);
        r(iMin);
        return iMin;
    }

    private int p(int i2) {
        int iMin = Math.min(this.f6570f, i2);
        r(iMin);
        return iMin;
    }

    private void r(int i2) {
        int i3 = this.f6570f - i2;
        this.f6570f = i3;
        this.f6569e = 0;
        byte[] bArr = this.f6568d;
        System.arraycopy(bArr, i2, bArr, 0, i3);
    }

    @Override // v.f
    public boolean a(byte[] bArr, int i2, int i3, boolean z2) throws InterruptedException, EOFException {
        int iO = o(bArr, i2, i3);
        while (iO < i3 && iO != -1) {
            iO = n(bArr, i2, i3, iO, z2);
        }
        l(iO);
        return iO != -1;
    }

    @Override // v.f
    public boolean b(byte[] bArr, int i2, int i3, boolean z2) {
        if (!k(i3, z2)) {
            return false;
        }
        System.arraycopy(this.f6568d, this.f6569e - i3, bArr, i2, i3);
        return true;
    }

    @Override // v.f
    public long c() {
        return this.f6567c + ((long) this.f6569e);
    }

    @Override // v.f
    public void d(int i2) throws InterruptedException, EOFException {
        k(i2, false);
    }

    @Override // v.f
    public int e(int i2) throws InterruptedException, EOFException {
        int iP = p(i2);
        if (iP == 0) {
            byte[] bArr = f6564g;
            iP = n(bArr, 0, Math.min(i2, bArr.length), 0, true);
        }
        l(iP);
        return iP;
    }

    @Override // v.f
    public long f() {
        return this.f6566b;
    }

    @Override // v.f
    public void g() {
        this.f6569e = 0;
    }

    @Override // v.f
    public void h(int i2) throws InterruptedException, EOFException {
        q(i2, false);
    }

    @Override // v.f
    public void i(byte[] bArr, int i2, int i3) {
        b(bArr, i2, i3, false);
    }

    @Override // v.f
    public long j() {
        return this.f6567c;
    }

    public boolean k(int i2, boolean z2) throws InterruptedException, EOFException {
        m(i2);
        int iMin = Math.min(this.f6570f - this.f6569e, i2);
        while (iMin < i2) {
            iMin = n(this.f6568d, this.f6569e, i2, iMin, z2);
            if (iMin == -1) {
                return false;
            }
        }
        int i3 = this.f6569e + i2;
        this.f6569e = i3;
        this.f6570f = Math.max(this.f6570f, i3);
        return true;
    }

    public boolean q(int i2, boolean z2) throws InterruptedException, EOFException {
        int iP = p(i2);
        while (iP < i2 && iP != -1) {
            byte[] bArr = f6564g;
            iP = n(bArr, -iP, Math.min(i2, bArr.length + iP), iP, z2);
        }
        l(iP);
        return iP != -1;
    }

    @Override // v.f
    public int read(byte[] bArr, int i2, int i3) throws InterruptedException, EOFException {
        int iO = o(bArr, i2, i3);
        if (iO == 0) {
            iO = n(bArr, i2, i3, 0, true);
        }
        l(iO);
        return iO;
    }

    @Override // v.f
    public void readFully(byte[] bArr, int i2, int i3) throws InterruptedException, EOFException {
        a(bArr, i2, i3, false);
    }
}
