package f;

import com.cvte.vman.instance.InvokeCmd;
import javax.annotation.Nullable;

/* JADX INFO: compiled from: Segment.java */
/* JADX INFO: loaded from: classes.dex */
final class p {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    final byte[] f3108a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    int f3109b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    int f3110c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    boolean f3111d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    boolean f3112e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    p f3113f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    p f3114g;

    p() {
        this.f3108a = new byte[InvokeCmd.CMD_TOUCH_CTRL_START];
        this.f3112e = true;
        this.f3111d = false;
    }

    public void a() {
        p pVar = this.f3114g;
        if (pVar == this) {
            throw new IllegalStateException();
        }
        if (pVar.f3112e) {
            int i = this.f3110c - this.f3109b;
            if (i > (8192 - pVar.f3110c) + (pVar.f3111d ? 0 : pVar.f3109b)) {
                return;
            }
            e(pVar, i);
            b();
            q.a(this);
        }
    }

    @Nullable
    public p b() {
        p pVar = this.f3113f;
        p pVar2 = pVar != this ? pVar : null;
        p pVar3 = this.f3114g;
        pVar3.f3113f = pVar;
        this.f3113f.f3114g = pVar3;
        this.f3113f = null;
        this.f3114g = null;
        return pVar2;
    }

    public p c(p pVar) {
        pVar.f3114g = this;
        pVar.f3113f = this.f3113f;
        this.f3113f.f3114g = pVar;
        this.f3113f = pVar;
        return pVar;
    }

    public p d(int i) {
        p pVarB;
        if (i <= 0 || i > this.f3110c - this.f3109b) {
            throw new IllegalArgumentException();
        }
        if (i >= 1024) {
            pVarB = new p(this);
        } else {
            pVarB = q.b();
            System.arraycopy(this.f3108a, this.f3109b, pVarB.f3108a, 0, i);
        }
        pVarB.f3110c = pVarB.f3109b + i;
        this.f3109b += i;
        this.f3114g.c(pVarB);
        return pVarB;
    }

    public void e(p pVar, int i) {
        if (!pVar.f3112e) {
            throw new IllegalArgumentException();
        }
        int i2 = pVar.f3110c;
        if (i2 + i > 8192) {
            if (pVar.f3111d) {
                throw new IllegalArgumentException();
            }
            int i3 = pVar.f3109b;
            if ((i2 + i) - i3 > 8192) {
                throw new IllegalArgumentException();
            }
            byte[] bArr = pVar.f3108a;
            System.arraycopy(bArr, i3, bArr, 0, i2 - i3);
            pVar.f3110c -= pVar.f3109b;
            pVar.f3109b = 0;
        }
        System.arraycopy(this.f3108a, this.f3109b, pVar.f3108a, pVar.f3110c, i);
        pVar.f3110c += i;
        this.f3109b += i;
    }

    p(p pVar) {
        this(pVar.f3108a, pVar.f3109b, pVar.f3110c);
        pVar.f3111d = true;
    }

    p(byte[] bArr, int i, int i2) {
        this.f3108a = bArr;
        this.f3109b = i;
        this.f3110c = i2;
        this.f3112e = false;
        this.f3111d = true;
    }
}
