package okio;

import kotlin.Metadata;
import kotlin.collections.j;
import kotlin.jvm.internal.o;

/* JADX INFO: renamed from: z.s, reason: from Kotlin metadata */
/* JADX INFO: loaded from: classes2.dex */
@Metadata(d1 = {"\u0000*\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\u0012\n\u0000\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0002\b\u0005\n\u0002\u0010\u0002\n\u0002\b\u000b\b\u0000\u0018\u0000 \u00192\u00020\u0001:\u0001\u0019B\u0007\b\u0016¢\u0006\u0002\u0010\u0002B/\b\u0016\u0012\u0006\u0010\u0003\u001a\u00020\u0004\u0012\u0006\u0010\u0005\u001a\u00020\u0006\u0012\u0006\u0010\u0007\u001a\u00020\u0006\u0012\u0006\u0010\b\u001a\u00020\t\u0012\u0006\u0010\n\u001a\u00020\t¢\u0006\u0002\u0010\u000bJ\u0006\u0010\u000e\u001a\u00020\u000fJ\b\u0010\u0010\u001a\u0004\u0018\u00010\u0000J\u000e\u0010\u0011\u001a\u00020\u00002\u0006\u0010\u0012\u001a\u00020\u0000J\u0006\u0010\u0013\u001a\u00020\u0000J\u000e\u0010\u0014\u001a\u00020\u00002\u0006\u0010\u0015\u001a\u00020\u0006J\u0006\u0010\u0016\u001a\u00020\u0000J\u0016\u0010\u0017\u001a\u00020\u000f2\u0006\u0010\u0018\u001a\u00020\u00002\u0006\u0010\u0015\u001a\u00020\u0006R\u0010\u0010\u0003\u001a\u00020\u00048\u0006X\u0087\u0004¢\u0006\u0002\n\u0000R\u0012\u0010\u0007\u001a\u00020\u00068\u0006@\u0006X\u0087\u000e¢\u0006\u0002\n\u0000R\u0014\u0010\f\u001a\u0004\u0018\u00010\u00008\u0006@\u0006X\u0087\u000e¢\u0006\u0002\n\u0000R\u0012\u0010\n\u001a\u00020\t8\u0006@\u0006X\u0087\u000e¢\u0006\u0002\n\u0000R\u0012\u0010\u0005\u001a\u00020\u00068\u0006@\u0006X\u0087\u000e¢\u0006\u0002\n\u0000R\u0014\u0010\r\u001a\u0004\u0018\u00010\u00008\u0006@\u0006X\u0087\u000e¢\u0006\u0002\n\u0000R\u0012\u0010\b\u001a\u00020\t8\u0006@\u0006X\u0087\u000e¢\u0006\u0002\n\u0000¨\u0006\u001a"}, d2 = {"Lokio/Segment;", "", "()V", "data", "", "pos", "", "limit", "shared", "", "owner", "([BIIZZ)V", "next", "prev", "compact", "", "pop", "push", "segment", "sharedCopy", "split", "byteCount", "unsharedCopy", "writeTo", "sink", "Companion", "okio"}, k = 1, mv = {1, 6, 0}, xi = 48)
public final class Segment {
    public final byte[] a;

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

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

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

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

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

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

    public Segment() {
        this.a = new byte[8192];
        this.f10154e = true;
        this.f10153d = false;
    }

    public Segment(byte[] bArr, int i2, int i3, boolean z2, boolean z3) {
        o.f(bArr, "data");
        this.a = bArr;
        this.f10151b = i2;
        this.f10152c = i3;
        this.f10153d = z2;
        this.f10154e = z3;
    }

    public final Segment a() {
        Segment segment = this.f10155f;
        if (segment == this) {
            segment = null;
        }
        Segment segment2 = this.f10156g;
        o.c(segment2);
        segment2.f10155f = this.f10155f;
        Segment segment3 = this.f10155f;
        o.c(segment3);
        segment3.f10156g = this.f10156g;
        this.f10155f = null;
        this.f10156g = null;
        return segment;
    }

    public final Segment b(Segment segment) {
        o.f(segment, "segment");
        segment.f10156g = this;
        segment.f10155f = this.f10155f;
        Segment segment2 = this.f10155f;
        o.c(segment2);
        segment2.f10156g = segment;
        this.f10155f = segment;
        return segment;
    }

    public final Segment c() {
        this.f10153d = true;
        return new Segment(this.a, this.f10151b, this.f10152c, true, false);
    }

    public final void d(Segment segment, int i2) {
        o.f(segment, "sink");
        if (!segment.f10154e) {
            throw new IllegalStateException("only owner can write".toString());
        }
        int i3 = segment.f10152c;
        int i4 = i3 + i2;
        if (i4 > 8192) {
            if (segment.f10153d) {
                throw new IllegalArgumentException();
            }
            int i5 = segment.f10151b;
            if (i4 - i5 > 8192) {
                throw new IllegalArgumentException();
            }
            byte[] bArr = segment.a;
            j.i(bArr, bArr, 0, i5, i3, 2);
            segment.f10152c -= segment.f10151b;
            segment.f10151b = 0;
        }
        byte[] bArr2 = this.a;
        byte[] bArr3 = segment.a;
        int i6 = segment.f10152c;
        int i7 = this.f10151b;
        j.g(bArr2, bArr3, i6, i7, i7 + i2);
        segment.f10152c += i2;
        this.f10151b += i2;
    }
}
