package h;

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

/* JADX INFO: compiled from: Segment.java */
/* JADX INFO: loaded from: classes.dex */
final class o {
    final byte[] a;

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

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

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

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

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

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

    o() {
        this.a = new byte[InvokeCmd.CMD_TOUCH_CTRL_START];
        this.f4208e = true;
        this.f4207d = false;
    }

    public void a() {
        o oVar = this.f4210g;
        if (oVar == this) {
            throw new IllegalStateException();
        }
        if (oVar.f4208e) {
            int i2 = this.f4206c - this.f4205b;
            if (i2 > (8192 - oVar.f4206c) + (oVar.f4207d ? 0 : oVar.f4205b)) {
                return;
            }
            e(this.f4210g, i2);
            b();
            p.a(this);
        }
    }

    @Nullable
    public o b() {
        o oVar = this.f4209f;
        if (oVar == this) {
            oVar = null;
        }
        o oVar2 = this.f4210g;
        oVar2.f4209f = this.f4209f;
        this.f4209f.f4210g = oVar2;
        this.f4209f = null;
        this.f4210g = null;
        return oVar;
    }

    public o c(o oVar) {
        oVar.f4210g = this;
        oVar.f4209f = this.f4209f;
        this.f4209f.f4210g = oVar;
        this.f4209f = oVar;
        return oVar;
    }

    public o d(int i2) {
        o oVarB;
        if (i2 <= 0 || i2 > this.f4206c - this.f4205b) {
            throw new IllegalArgumentException();
        }
        if (i2 >= 1024) {
            oVarB = new o(this);
        } else {
            oVarB = p.b();
            System.arraycopy(this.a, this.f4205b, oVarB.a, 0, i2);
        }
        oVarB.f4206c = oVarB.f4205b + i2;
        this.f4205b += i2;
        this.f4210g.c(oVarB);
        return oVarB;
    }

    public void e(o oVar, int i2) {
        if (!oVar.f4208e) {
            throw new IllegalArgumentException();
        }
        int i3 = oVar.f4206c;
        if (i3 + i2 > 8192) {
            if (oVar.f4207d) {
                throw new IllegalArgumentException();
            }
            int i4 = oVar.f4205b;
            if ((i3 + i2) - i4 > 8192) {
                throw new IllegalArgumentException();
            }
            byte[] bArr = oVar.a;
            System.arraycopy(bArr, i4, bArr, 0, i3 - i4);
            oVar.f4206c -= oVar.f4205b;
            oVar.f4205b = 0;
        }
        System.arraycopy(this.a, this.f4205b, oVar.a, oVar.f4206c, i2);
        oVar.f4206c += i2;
        this.f4205b += i2;
    }

    o(o oVar) {
        this(oVar.a, oVar.f4205b, oVar.f4206c);
        oVar.f4207d = true;
    }

    o(byte[] bArr, int i2, int i3) {
        this.a = bArr;
        this.f4205b = i2;
        this.f4206c = i3;
        this.f4208e = false;
        this.f4207d = true;
    }
}
