package j;

import com.cvte.vman.instance.InvokeCmd;

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

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

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

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public w f4653f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public w f4654g;

    public w() {
        this.a = new byte[InvokeCmd.CMD_TOUCH_CTRL_START];
        this.f4652e = true;
        this.f4651d = false;
    }

    public final w a() {
        w wVar = this.f4653f;
        if (wVar == this) {
            wVar = null;
        }
        w wVar2 = this.f4654g;
        g.h0.c.l.c(wVar2);
        wVar2.f4653f = this.f4653f;
        w wVar3 = this.f4653f;
        g.h0.c.l.c(wVar3);
        wVar3.f4654g = this.f4654g;
        this.f4653f = null;
        this.f4654g = null;
        return wVar;
    }

    public final w b(w wVar) {
        g.h0.c.l.f(wVar, "segment");
        wVar.f4654g = this;
        wVar.f4653f = this.f4653f;
        w wVar2 = this.f4653f;
        g.h0.c.l.c(wVar2);
        wVar2.f4654g = wVar;
        this.f4653f = wVar;
        return wVar;
    }

    public final w c() {
        this.f4651d = true;
        return new w(this.a, this.f4649b, this.f4650c, true, false);
    }

    public final void d(w wVar, int i2) {
        g.h0.c.l.f(wVar, "sink");
        if (!wVar.f4652e) {
            throw new IllegalStateException("only owner can write".toString());
        }
        int i3 = wVar.f4650c;
        int i4 = i3 + i2;
        if (i4 > 8192) {
            if (wVar.f4651d) {
                throw new IllegalArgumentException();
            }
            int i5 = wVar.f4649b;
            if (i4 - i5 > 8192) {
                throw new IllegalArgumentException();
            }
            byte[] bArr = wVar.a;
            g.c0.g.f(bArr, bArr, 0, i5, i3, 2);
            wVar.f4650c -= wVar.f4649b;
            wVar.f4649b = 0;
        }
        byte[] bArr2 = this.a;
        byte[] bArr3 = wVar.a;
        int i6 = wVar.f4650c;
        int i7 = this.f4649b;
        g.c0.g.d(bArr2, bArr3, i6, i7, i7 + i2);
        wVar.f4650c += i2;
        this.f4649b += i2;
    }

    public w(byte[] bArr, int i2, int i3, boolean z, boolean z2) {
        g.h0.c.l.f(bArr, "data");
        this.a = bArr;
        this.f4649b = i2;
        this.f4650c = i3;
        this.f4651d = z;
        this.f4652e = z2;
    }
}
