package kr;

import com.fasterxml.jackson.core.json.ByteSourceJsonBootstrapper;
import com.google.android.gms.common.api.Api;
import com.google.firebase.perf.util.Constants;
import java.io.Closeable;
import java.io.EOFException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.ByteChannel;
import java.nio.charset.Charset;

/* loaded from: classes4.dex */
public final class d implements f, e, Cloneable, ByteChannel {

    /* renamed from: p, reason: collision with root package name */
    public v f26638p;

    /* renamed from: q, reason: collision with root package name */
    private long f26639q;

    /* loaded from: classes4.dex */
    public static final class a implements Closeable {

        /* renamed from: p, reason: collision with root package name */
        public d f26640p;

        /* renamed from: q, reason: collision with root package name */
        public boolean f26641q;

        /* renamed from: r, reason: collision with root package name */
        private v f26642r;

        /* renamed from: t, reason: collision with root package name */
        public byte[] f26644t;

        /* renamed from: s, reason: collision with root package name */
        public long f26643s = -1;

        /* renamed from: u, reason: collision with root package name */
        public int f26645u = -1;

        /* renamed from: v, reason: collision with root package name */
        public int f26646v = -1;

        public final v a() {
            return this.f26642r;
        }

        public final int b() {
            long j10 = this.f26643s;
            d dVar = this.f26640p;
            kotlin.jvm.internal.t.d(dVar);
            if (!(j10 != dVar.X())) {
                throw new IllegalStateException("no more bytes".toString());
            }
            long j11 = this.f26643s;
            return d(j11 == -1 ? 0L : j11 + (this.f26646v - this.f26645u));
        }

        public final long c(long j10) {
            d dVar = this.f26640p;
            if (dVar == null) {
                throw new IllegalStateException("not attached to a buffer".toString());
            }
            if (!this.f26641q) {
                throw new IllegalStateException("resizeBuffer() only permitted for read/write buffers".toString());
            }
            long X = dVar.X();
            int i10 = 1;
            if (j10 <= X) {
                if (!(j10 >= 0)) {
                    throw new IllegalArgumentException(("newSize < 0: " + j10).toString());
                }
                long j11 = X - j10;
                while (true) {
                    if (j11 <= 0) {
                        break;
                    }
                    v vVar = dVar.f26638p;
                    kotlin.jvm.internal.t.d(vVar);
                    v vVar2 = vVar.f26691g;
                    kotlin.jvm.internal.t.d(vVar2);
                    int i11 = vVar2.f26687c;
                    long j12 = i11 - vVar2.f26686b;
                    if (j12 > j11) {
                        vVar2.f26687c = i11 - ((int) j11);
                        break;
                    }
                    dVar.f26638p = vVar2.b();
                    w.b(vVar2);
                    j11 -= j12;
                }
                e(null);
                this.f26643s = j10;
                this.f26644t = null;
                this.f26645u = -1;
                this.f26646v = -1;
            } else if (j10 > X) {
                long j13 = j10 - X;
                boolean z10 = true;
                while (j13 > 0) {
                    v g02 = dVar.g0(i10);
                    int min = (int) Math.min(j13, 8192 - g02.f26687c);
                    g02.f26687c += min;
                    j13 -= min;
                    if (z10) {
                        e(g02);
                        this.f26643s = X;
                        this.f26644t = g02.f26685a;
                        int i12 = g02.f26687c;
                        this.f26645u = i12 - min;
                        this.f26646v = i12;
                        z10 = false;
                    }
                    i10 = 1;
                }
            }
            dVar.V(j10);
            return X;
        }

        @Override // java.io.Closeable, java.lang.AutoCloseable
        public void close() {
            if (!(this.f26640p != null)) {
                throw new IllegalStateException("not attached to a buffer".toString());
            }
            this.f26640p = null;
            e(null);
            this.f26643s = -1L;
            this.f26644t = null;
            this.f26645u = -1;
            this.f26646v = -1;
        }

        public final int d(long j10) {
            v vVar;
            d dVar = this.f26640p;
            if (dVar == null) {
                throw new IllegalStateException("not attached to a buffer".toString());
            }
            if (j10 < -1 || j10 > dVar.X()) {
                throw new ArrayIndexOutOfBoundsException("offset=" + j10 + " > size=" + dVar.X());
            }
            if (j10 == -1 || j10 == dVar.X()) {
                e(null);
                this.f26643s = j10;
                this.f26644t = null;
                this.f26645u = -1;
                this.f26646v = -1;
                return -1;
            }
            long X = dVar.X();
            v vVar2 = dVar.f26638p;
            long j11 = 0;
            if (a() != null) {
                long j12 = this.f26643s;
                int i10 = this.f26645u;
                kotlin.jvm.internal.t.d(a());
                long j13 = j12 - (i10 - r9.f26686b);
                if (j13 > j10) {
                    vVar = vVar2;
                    vVar2 = a();
                    X = j13;
                } else {
                    vVar = a();
                    j11 = j13;
                }
            } else {
                vVar = vVar2;
            }
            if (X - j10 > j10 - j11) {
                while (true) {
                    kotlin.jvm.internal.t.d(vVar);
                    int i11 = vVar.f26687c;
                    int i12 = vVar.f26686b;
                    if (j10 < (i11 - i12) + j11) {
                        break;
                    }
                    j11 += i11 - i12;
                    vVar = vVar.f26690f;
                }
            } else {
                while (X > j10) {
                    kotlin.jvm.internal.t.d(vVar2);
                    vVar2 = vVar2.f26691g;
                    kotlin.jvm.internal.t.d(vVar2);
                    X -= vVar2.f26687c - vVar2.f26686b;
                }
                j11 = X;
                vVar = vVar2;
            }
            if (this.f26641q) {
                kotlin.jvm.internal.t.d(vVar);
                if (vVar.f26688d) {
                    v f10 = vVar.f();
                    if (dVar.f26638p == vVar) {
                        dVar.f26638p = f10;
                    }
                    vVar = vVar.c(f10);
                    v vVar3 = vVar.f26691g;
                    kotlin.jvm.internal.t.d(vVar3);
                    vVar3.b();
                }
            }
            e(vVar);
            this.f26643s = j10;
            kotlin.jvm.internal.t.d(vVar);
            this.f26644t = vVar.f26685a;
            int i13 = vVar.f26686b + ((int) (j10 - j11));
            this.f26645u = i13;
            int i14 = vVar.f26687c;
            this.f26646v = i14;
            return i14 - i13;
        }

        public final void e(v vVar) {
            this.f26642r = vVar;
        }
    }

    /* loaded from: classes4.dex */
    public static final class c extends OutputStream {
        c() {
        }

        @Override // java.io.OutputStream, java.io.Closeable, java.lang.AutoCloseable
        public void close() {
        }

        @Override // java.io.OutputStream, java.io.Flushable
        public void flush() {
        }

        public String toString() {
            return d.this + ".outputStream()";
        }

        @Override // java.io.OutputStream
        public void write(int i10) {
            d.this.F(i10);
        }

        @Override // java.io.OutputStream
        public void write(byte[] data, int i10, int i11) {
            kotlin.jvm.internal.t.g(data, "data");
            d.this.d0(data, i10, i11);
        }
    }

    public static /* synthetic */ a A(d dVar, a aVar, int i10, Object obj) {
        if ((i10 & 1) != 0) {
            aVar = kr.b.d();
        }
        return dVar.z(aVar);
    }

    @Override // kr.e
    /* renamed from: A0, reason: merged with bridge method [inline-methods] */
    public d W(String string) {
        kotlin.jvm.internal.t.g(string, "string");
        return f0(string, 0, string.length());
    }

    @Override // kr.f
    public byte[] B() {
        return v0(X());
    }

    @Override // kr.e
    /* renamed from: B0, reason: merged with bridge method [inline-methods] */
    public d f0(String string, int i10, int i11) {
        char charAt;
        kotlin.jvm.internal.t.g(string, "string");
        if (!(i10 >= 0)) {
            throw new IllegalArgumentException(("beginIndex < 0: " + i10).toString());
        }
        if (!(i11 >= i10)) {
            throw new IllegalArgumentException(("endIndex < beginIndex: " + i11 + " < " + i10).toString());
        }
        if (!(i11 <= string.length())) {
            throw new IllegalArgumentException(("endIndex > string.length: " + i11 + " > " + string.length()).toString());
        }
        while (i10 < i11) {
            char charAt2 = string.charAt(i10);
            if (charAt2 < 128) {
                v g02 = g0(1);
                byte[] bArr = g02.f26685a;
                int i12 = g02.f26687c - i10;
                int min = Math.min(i11, 8192 - i12);
                int i13 = i10 + 1;
                bArr[i10 + i12] = (byte) charAt2;
                while (true) {
                    i10 = i13;
                    if (i10 >= min || (charAt = string.charAt(i10)) >= 128) {
                        break;
                    }
                    i13 = i10 + 1;
                    bArr[i10 + i12] = (byte) charAt;
                }
                int i14 = g02.f26687c;
                int i15 = (i12 + i10) - i14;
                g02.f26687c = i14 + i15;
                V(X() + i15);
            } else {
                if (charAt2 < 2048) {
                    v g03 = g0(2);
                    byte[] bArr2 = g03.f26685a;
                    int i16 = g03.f26687c;
                    bArr2[i16] = (byte) ((charAt2 >> 6) | 192);
                    bArr2[i16 + 1] = (byte) ((charAt2 & '?') | 128);
                    g03.f26687c = i16 + 2;
                    V(X() + 2);
                } else if (charAt2 < 55296 || charAt2 > 57343) {
                    v g04 = g0(3);
                    byte[] bArr3 = g04.f26685a;
                    int i17 = g04.f26687c;
                    bArr3[i17] = (byte) ((charAt2 >> '\f') | 224);
                    bArr3[i17 + 1] = (byte) ((63 & (charAt2 >> 6)) | 128);
                    bArr3[i17 + 2] = (byte) ((charAt2 & '?') | 128);
                    g04.f26687c = i17 + 3;
                    V(X() + 3);
                } else {
                    int i18 = i10 + 1;
                    char charAt3 = i18 < i11 ? string.charAt(i18) : (char) 0;
                    if (charAt2 <= 56319) {
                        if (56320 <= charAt3 && charAt3 < 57344) {
                            int i19 = (((charAt2 & 1023) << 10) | (charAt3 & 1023)) + 65536;
                            v g05 = g0(4);
                            byte[] bArr4 = g05.f26685a;
                            int i20 = g05.f26687c;
                            bArr4[i20] = (byte) ((i19 >> 18) | 240);
                            bArr4[i20 + 1] = (byte) (((i19 >> 12) & 63) | 128);
                            bArr4[i20 + 2] = (byte) (((i19 >> 6) & 63) | 128);
                            bArr4[i20 + 3] = (byte) ((i19 & 63) | 128);
                            g05.f26687c = i20 + 4;
                            V(X() + 4);
                            i10 += 2;
                        }
                    }
                    F(63);
                    i10 = i18;
                }
                i10++;
            }
        }
        return this;
    }

    public g C() {
        return q(X());
    }

    public d C0(int i10) {
        if (i10 < 128) {
            F(i10);
        } else if (i10 < 2048) {
            v g02 = g0(2);
            byte[] bArr = g02.f26685a;
            int i11 = g02.f26687c;
            bArr[i11] = (byte) ((i10 >> 6) | 192);
            bArr[i11 + 1] = (byte) ((i10 & 63) | 128);
            g02.f26687c = i11 + 2;
            V(X() + 2);
        } else {
            boolean z10 = false;
            if (55296 <= i10 && i10 < 57344) {
                z10 = true;
            }
            if (z10) {
                F(63);
            } else if (i10 < 65536) {
                v g03 = g0(3);
                byte[] bArr2 = g03.f26685a;
                int i12 = g03.f26687c;
                bArr2[i12] = (byte) ((i10 >> 12) | 224);
                bArr2[i12 + 1] = (byte) (((i10 >> 6) & 63) | 128);
                bArr2[i12 + 2] = (byte) ((i10 & 63) | 128);
                g03.f26687c = i12 + 3;
                V(X() + 3);
            } else {
                if (i10 > 1114111) {
                    throw new IllegalArgumentException("Unexpected code point: 0x" + kr.b.k(i10));
                }
                v g04 = g0(4);
                byte[] bArr3 = g04.f26685a;
                int i13 = g04.f26687c;
                bArr3[i13] = (byte) ((i10 >> 18) | 240);
                bArr3[i13 + 1] = (byte) (((i10 >> 12) & 63) | 128);
                bArr3[i13 + 2] = (byte) (((i10 >> 6) & 63) | 128);
                bArr3[i13 + 3] = (byte) ((i10 & 63) | 128);
                g04.f26687c = i13 + 4;
                V(X() + 4);
            }
        }
        return this;
    }

    @Override // kr.f
    public boolean E() {
        return this.f26639q == 0;
    }

    public int G() {
        return kr.b.h(readInt());
    }

    @Override // kr.f
    public long G0(y sink) {
        kotlin.jvm.internal.t.g(sink, "sink");
        long X = X();
        if (X > 0) {
            sink.U(this, X);
        }
        return X;
    }

    @Override // kr.a0
    public long J0(d sink, long j10) {
        kotlin.jvm.internal.t.g(sink, "sink");
        if (!(j10 >= 0)) {
            throw new IllegalArgumentException(("byteCount < 0: " + j10).toString());
        }
        if (X() == 0) {
            return -1L;
        }
        if (j10 > X()) {
            j10 = X();
        }
        sink.U(this, j10);
        return j10;
    }

    public short K() {
        return kr.b.i(readShort());
    }

    public String L(long j10, Charset charset) {
        kotlin.jvm.internal.t.g(charset, "charset");
        if (!(j10 >= 0 && j10 <= 2147483647L)) {
            throw new IllegalArgumentException(("byteCount: " + j10).toString());
        }
        if (this.f26639q < j10) {
            throw new EOFException();
        }
        if (j10 == 0) {
            return "";
        }
        v vVar = this.f26638p;
        kotlin.jvm.internal.t.d(vVar);
        int i10 = vVar.f26686b;
        if (i10 + j10 > vVar.f26687c) {
            return new String(v0(j10), charset);
        }
        int i11 = (int) j10;
        String str = new String(vVar.f26685a, i10, i11, charset);
        int i12 = vVar.f26686b + i11;
        vVar.f26686b = i12;
        this.f26639q -= j10;
        if (i12 == vVar.f26687c) {
            this.f26638p = vVar.b();
            w.b(vVar);
        }
        return str;
    }

    @Override // kr.f
    public void L0(long j10) {
        if (this.f26639q < j10) {
            throw new EOFException();
        }
    }

    @Override // kr.f
    public int M0(r options) {
        kotlin.jvm.internal.t.g(options, "options");
        int f10 = lr.a.f(this, options, false, 2, null);
        if (f10 == -1) {
            return -1;
        }
        skip(options.m()[f10].size());
        return f10;
    }

    public String N() {
        return L(this.f26639q, kotlin.text.d.f26484b);
    }

    @Override // kr.f
    public String O(long j10) {
        if (!(j10 >= 0)) {
            throw new IllegalArgumentException(("limit < 0: " + j10).toString());
        }
        long j11 = j10 != Long.MAX_VALUE ? j10 + 1 : Long.MAX_VALUE;
        long s10 = s((byte) 10, 0L, j11);
        if (s10 != -1) {
            return lr.a.d(this, s10);
        }
        if (j11 < X() && p(j11 - 1) == 13 && p(j11) == 10) {
            return lr.a.d(this, j11);
        }
        d dVar = new d();
        f(dVar, 0L, Math.min(32, X()));
        throw new EOFException("\\n not found: limit=" + Math.min(X(), j10) + " content=" + dVar.C().x() + (char) 8230);
    }

    @Override // kr.f
    public boolean P(long j10, g bytes) {
        kotlin.jvm.internal.t.g(bytes, "bytes");
        return y(j10, bytes, 0, bytes.size());
    }

    /* JADX WARN: Removed duplicated region for block: B:33:0x0098  */
    /* JADX WARN: Removed duplicated region for block: B:35:0x00a6  */
    /* JADX WARN: Removed duplicated region for block: B:41:0x00aa A[EDGE_INSN: B:41:0x00aa->B:38:0x00aa BREAK  A[LOOP:0: B:4:0x000d->B:40:?], SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:42:0x00a2  */
    @Override // kr.f
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public long P0() {
        int i10;
        int i11;
        if (X() == 0) {
            throw new EOFException();
        }
        int i12 = 0;
        boolean z10 = false;
        long j10 = 0;
        do {
            v vVar = this.f26638p;
            kotlin.jvm.internal.t.d(vVar);
            byte[] bArr = vVar.f26685a;
            int i13 = vVar.f26686b;
            int i14 = vVar.f26687c;
            while (i13 < i14) {
                byte b10 = bArr[i13];
                if (b10 < 48 || b10 > 57) {
                    if (b10 >= 97 && b10 <= 102) {
                        i10 = b10 - 97;
                    } else if (b10 >= 65 && b10 <= 70) {
                        i10 = b10 + ByteSourceJsonBootstrapper.UTF8_BOM_3;
                    } else {
                        if (i12 == 0) {
                            throw new NumberFormatException("Expected leading [0-9a-fA-F] character but was 0x" + kr.b.j(b10));
                        }
                        z10 = true;
                        if (i13 != i14) {
                            this.f26638p = vVar.b();
                            w.b(vVar);
                        } else {
                            vVar.f26686b = i13;
                        }
                        if (!z10) {
                            break;
                        }
                    }
                    i11 = i10 + 10;
                } else {
                    i11 = b10 - 48;
                }
                if (((-1152921504606846976L) & j10) != 0) {
                    throw new NumberFormatException("Number too large: " + new d().h0(j10).F(b10).N());
                }
                j10 = (j10 << 4) | i11;
                i13++;
                i12++;
            }
            if (i13 != i14) {
            }
            if (!z10) {
            }
        } while (this.f26638p != null);
        V(X() - i12);
        return j10;
    }

    @Override // kr.f
    public void R(d sink, long j10) {
        kotlin.jvm.internal.t.g(sink, "sink");
        if (X() >= j10) {
            sink.U(this, j10);
        } else {
            sink.U(this, X());
            throw new EOFException();
        }
    }

    @Override // kr.f
    public InputStream R0() {
        return new b();
    }

    public String S(long j10) {
        return L(j10, kotlin.text.d.f26484b);
    }

    public int T() {
        int i10;
        int i11;
        int i12;
        if (X() == 0) {
            throw new EOFException();
        }
        byte p10 = p(0L);
        boolean z10 = false;
        if ((p10 & 128) == 0) {
            i10 = p10 & Byte.MAX_VALUE;
            i12 = 0;
            i11 = 1;
        } else if ((p10 & 224) == 192) {
            i10 = p10 & 31;
            i11 = 2;
            i12 = 128;
        } else if ((p10 & 240) == 224) {
            i10 = p10 & 15;
            i11 = 3;
            i12 = 2048;
        } else {
            if ((p10 & 248) != 240) {
                skip(1L);
                return 65533;
            }
            i10 = p10 & 7;
            i11 = 4;
            i12 = 65536;
        }
        long j10 = i11;
        if (X() < j10) {
            throw new EOFException("size < " + i11 + ": " + X() + " (to read code point prefixed 0x" + kr.b.j(p10) + ')');
        }
        for (int i13 = 1; i13 < i11; i13++) {
            long j11 = i13;
            byte p11 = p(j11);
            if ((p11 & 192) != 128) {
                skip(j11);
                return 65533;
            }
            i10 = (i10 << 6) | (p11 & 63);
        }
        skip(j10);
        if (i10 > 1114111) {
            return 65533;
        }
        if (55296 <= i10 && i10 < 57344) {
            z10 = true;
        }
        if (!z10 && i10 >= i12) {
            return i10;
        }
        return 65533;
    }

    @Override // kr.y
    public void U(d source, long j10) {
        v vVar;
        kotlin.jvm.internal.t.g(source, "source");
        if (!(source != this)) {
            throw new IllegalArgumentException("source == this".toString());
        }
        kr.b.b(source.X(), 0L, j10);
        while (j10 > 0) {
            v vVar2 = source.f26638p;
            kotlin.jvm.internal.t.d(vVar2);
            int i10 = vVar2.f26687c;
            kotlin.jvm.internal.t.d(source.f26638p);
            if (j10 < i10 - r2.f26686b) {
                v vVar3 = this.f26638p;
                if (vVar3 != null) {
                    kotlin.jvm.internal.t.d(vVar3);
                    vVar = vVar3.f26691g;
                } else {
                    vVar = null;
                }
                if (vVar != null && vVar.f26689e) {
                    if ((vVar.f26687c + j10) - (vVar.f26688d ? 0 : vVar.f26686b) <= 8192) {
                        v vVar4 = source.f26638p;
                        kotlin.jvm.internal.t.d(vVar4);
                        vVar4.g(vVar, (int) j10);
                        source.V(source.X() - j10);
                        V(X() + j10);
                        return;
                    }
                }
                v vVar5 = source.f26638p;
                kotlin.jvm.internal.t.d(vVar5);
                source.f26638p = vVar5.e((int) j10);
            }
            v vVar6 = source.f26638p;
            kotlin.jvm.internal.t.d(vVar6);
            long j11 = vVar6.f26687c - vVar6.f26686b;
            source.f26638p = vVar6.b();
            v vVar7 = this.f26638p;
            if (vVar7 == null) {
                this.f26638p = vVar6;
                vVar6.f26691g = vVar6;
                vVar6.f26690f = vVar6;
            } else {
                kotlin.jvm.internal.t.d(vVar7);
                v vVar8 = vVar7.f26691g;
                kotlin.jvm.internal.t.d(vVar8);
                vVar8.c(vVar6).a();
            }
            source.V(source.X() - j11);
            V(X() + j11);
            j10 -= j11;
        }
    }

    public final void V(long j10) {
        this.f26639q = j10;
    }

    public final long X() {
        return this.f26639q;
    }

    public final g Y() {
        if (X() <= 2147483647L) {
            return a0((int) X());
        }
        throw new IllegalStateException(("size > Int.MAX_VALUE: " + X()).toString());
    }

    @Override // kr.f
    public String Z(Charset charset) {
        kotlin.jvm.internal.t.g(charset, "charset");
        return L(this.f26639q, charset);
    }

    public final void a() {
        skip(X());
    }

    public final g a0(int i10) {
        if (i10 == 0) {
            return g.f26650t;
        }
        kr.b.b(X(), 0L, i10);
        v vVar = this.f26638p;
        int i11 = 0;
        int i12 = 0;
        int i13 = 0;
        while (i12 < i10) {
            kotlin.jvm.internal.t.d(vVar);
            int i14 = vVar.f26687c;
            int i15 = vVar.f26686b;
            if (i14 == i15) {
                throw new AssertionError("s.limit == s.pos");
            }
            i12 += i14 - i15;
            i13++;
            vVar = vVar.f26690f;
        }
        byte[][] bArr = new byte[i13];
        int[] iArr = new int[i13 * 2];
        v vVar2 = this.f26638p;
        int i16 = 0;
        while (i11 < i10) {
            kotlin.jvm.internal.t.d(vVar2);
            bArr[i16] = vVar2.f26685a;
            i11 += vVar2.f26687c - vVar2.f26686b;
            iArr[i16] = Math.min(i11, i10);
            iArr[i16 + i13] = vVar2.f26686b;
            vVar2.f26688d = true;
            i16++;
            vVar2 = vVar2.f26690f;
        }
        return new x(bArr, iArr);
    }

    /* renamed from: b, reason: merged with bridge method [inline-methods] */
    public d clone() {
        return d();
    }

    @Override // kr.f
    public long b0(g targetBytes) {
        kotlin.jvm.internal.t.g(targetBytes, "targetBytes");
        return v(targetBytes, 0L);
    }

    public final long c() {
        long X = X();
        if (X == 0) {
            return 0L;
        }
        v vVar = this.f26638p;
        kotlin.jvm.internal.t.d(vVar);
        v vVar2 = vVar.f26691g;
        kotlin.jvm.internal.t.d(vVar2);
        if (vVar2.f26687c < 8192 && vVar2.f26689e) {
            X -= r2 - vVar2.f26686b;
        }
        return X;
    }

    @Override // kr.a0, java.io.Closeable, java.lang.AutoCloseable
    public void close() {
    }

    public final d d() {
        d dVar = new d();
        if (X() != 0) {
            v vVar = this.f26638p;
            kotlin.jvm.internal.t.d(vVar);
            v d10 = vVar.d();
            dVar.f26638p = d10;
            d10.f26691g = d10;
            d10.f26690f = d10;
            for (v vVar2 = vVar.f26690f; vVar2 != vVar; vVar2 = vVar2.f26690f) {
                v vVar3 = d10.f26691g;
                kotlin.jvm.internal.t.d(vVar3);
                kotlin.jvm.internal.t.d(vVar2);
                vVar3.c(vVar2.d());
            }
            dVar.V(X());
        }
        return dVar;
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof d) {
            d dVar = (d) obj;
            if (X() == dVar.X()) {
                if (X() == 0) {
                    return true;
                }
                v vVar = this.f26638p;
                kotlin.jvm.internal.t.d(vVar);
                v vVar2 = dVar.f26638p;
                kotlin.jvm.internal.t.d(vVar2);
                int i10 = vVar.f26686b;
                int i11 = vVar2.f26686b;
                long j10 = 0;
                while (j10 < X()) {
                    long min = Math.min(vVar.f26687c - i10, vVar2.f26687c - i11);
                    long j11 = 0;
                    while (j11 < min) {
                        int i12 = i10 + 1;
                        int i13 = i11 + 1;
                        if (vVar.f26685a[i10] == vVar2.f26685a[i11]) {
                            j11++;
                            i10 = i12;
                            i11 = i13;
                        }
                    }
                    if (i10 == vVar.f26687c) {
                        vVar = vVar.f26690f;
                        kotlin.jvm.internal.t.d(vVar);
                        i10 = vVar.f26686b;
                    }
                    if (i11 == vVar2.f26687c) {
                        vVar2 = vVar2.f26690f;
                        kotlin.jvm.internal.t.d(vVar2);
                        i11 = vVar2.f26686b;
                    }
                    j10 += min;
                }
                return true;
            }
        }
        return false;
    }

    public final d f(d out, long j10, long j11) {
        kotlin.jvm.internal.t.g(out, "out");
        kr.b.b(X(), j10, j11);
        if (j11 != 0) {
            out.V(out.X() + j11);
            v vVar = this.f26638p;
            while (true) {
                kotlin.jvm.internal.t.d(vVar);
                int i10 = vVar.f26687c;
                int i11 = vVar.f26686b;
                if (j10 < i10 - i11) {
                    break;
                }
                j10 -= i10 - i11;
                vVar = vVar.f26690f;
            }
            while (j11 > 0) {
                kotlin.jvm.internal.t.d(vVar);
                v d10 = vVar.d();
                int i12 = d10.f26686b + ((int) j10);
                d10.f26686b = i12;
                d10.f26687c = Math.min(i12 + ((int) j11), d10.f26687c);
                v vVar2 = out.f26638p;
                if (vVar2 == null) {
                    d10.f26691g = d10;
                    d10.f26690f = d10;
                    out.f26638p = d10;
                } else {
                    kotlin.jvm.internal.t.d(vVar2);
                    v vVar3 = vVar2.f26691g;
                    kotlin.jvm.internal.t.d(vVar3);
                    vVar3.c(d10);
                }
                j11 -= d10.f26687c - d10.f26686b;
                vVar = vVar.f26690f;
                j10 = 0;
            }
        }
        return this;
    }

    @Override // kr.e, kr.y, java.io.Flushable
    public void flush() {
    }

    public final v g0(int i10) {
        if (!(i10 >= 1 && i10 <= 8192)) {
            throw new IllegalArgumentException("unexpected capacity".toString());
        }
        v vVar = this.f26638p;
        if (vVar == null) {
            v c10 = w.c();
            this.f26638p = c10;
            c10.f26691g = c10;
            c10.f26690f = c10;
            return c10;
        }
        kotlin.jvm.internal.t.d(vVar);
        v vVar2 = vVar.f26691g;
        kotlin.jvm.internal.t.d(vVar2);
        if (vVar2.f26687c + i10 > 8192 || !vVar2.f26689e) {
            vVar2 = vVar2.c(w.c());
        }
        return vVar2;
    }

    @Override // kr.e
    /* renamed from: h, reason: merged with bridge method [inline-methods] */
    public d i() {
        return this;
    }

    public int hashCode() {
        v vVar = this.f26638p;
        if (vVar == null) {
            return 0;
        }
        int i10 = 1;
        do {
            int i11 = vVar.f26687c;
            for (int i12 = vVar.f26686b; i12 < i11; i12++) {
                i10 = (i10 * 31) + vVar.f26685a[i12];
            }
            vVar = vVar.f26690f;
            kotlin.jvm.internal.t.d(vVar);
        } while (vVar != this.f26638p);
        return i10;
    }

    @Override // java.nio.channels.Channel
    public boolean isOpen() {
        return true;
    }

    @Override // kr.e
    /* renamed from: j, reason: merged with bridge method [inline-methods] */
    public d M() {
        return this;
    }

    @Override // kr.e
    /* renamed from: j0, reason: merged with bridge method [inline-methods] */
    public d i0(g byteString) {
        kotlin.jvm.internal.t.g(byteString, "byteString");
        byteString.J(this, 0, byteString.size());
        return this;
    }

    @Override // kr.f, kr.e
    public d k() {
        return this;
    }

    @Override // kr.e
    /* renamed from: k0, reason: merged with bridge method [inline-methods] */
    public d z0(byte[] source) {
        kotlin.jvm.internal.t.g(source, "source");
        return d0(source, 0, source.length);
    }

    @Override // kr.a0
    public b0 l() {
        return b0.f26621e;
    }

    @Override // kr.f
    public long l0(g bytes) {
        kotlin.jvm.internal.t.g(bytes, "bytes");
        return t(bytes, 0L);
    }

    @Override // kr.f
    public boolean m0(long j10) {
        return this.f26639q >= j10;
    }

    @Override // kr.e
    /* renamed from: n0, reason: merged with bridge method [inline-methods] */
    public d d0(byte[] source, int i10, int i11) {
        kotlin.jvm.internal.t.g(source, "source");
        long j10 = i11;
        kr.b.b(source.length, i10, j10);
        int i12 = i11 + i10;
        while (i10 < i12) {
            v g02 = g0(1);
            int min = Math.min(i12 - i10, 8192 - g02.f26687c);
            int i13 = i10 + min;
            sm.o.g(source, g02.f26685a, g02.f26687c, i10, i13);
            g02.f26687c += min;
            i10 = i13;
        }
        V(X() + j10);
        return this;
    }

    public long o0(a0 source) {
        kotlin.jvm.internal.t.g(source, "source");
        long j10 = 0;
        while (true) {
            long J0 = source.J0(this, 8192L);
            if (J0 == -1) {
                return j10;
            }
            j10 += J0;
        }
    }

    public final byte p(long j10) {
        kr.b.b(X(), j10, 1L);
        v vVar = this.f26638p;
        if (vVar == null) {
            kotlin.jvm.internal.t.d(null);
            throw null;
        }
        if (X() - j10 < j10) {
            long X = X();
            while (X > j10) {
                vVar = vVar.f26691g;
                kotlin.jvm.internal.t.d(vVar);
                X -= vVar.f26687c - vVar.f26686b;
            }
            kotlin.jvm.internal.t.d(vVar);
            return vVar.f26685a[(int) ((vVar.f26686b + j10) - X)];
        }
        long j11 = 0;
        while (true) {
            long j12 = (vVar.f26687c - vVar.f26686b) + j11;
            if (j12 > j10) {
                kotlin.jvm.internal.t.d(vVar);
                return vVar.f26685a[(int) ((vVar.f26686b + j10) - j11)];
            }
            vVar = vVar.f26690f;
            kotlin.jvm.internal.t.d(vVar);
            j11 = j12;
        }
    }

    @Override // kr.e
    /* renamed from: p0, reason: merged with bridge method [inline-methods] */
    public d F(int i10) {
        v g02 = g0(1);
        byte[] bArr = g02.f26685a;
        int i11 = g02.f26687c;
        g02.f26687c = i11 + 1;
        bArr[i11] = (byte) i10;
        V(X() + 1);
        return this;
    }

    @Override // kr.f
    public g q(long j10) {
        if (!(j10 >= 0 && j10 <= 2147483647L)) {
            throw new IllegalArgumentException(("byteCount: " + j10).toString());
        }
        if (X() < j10) {
            throw new EOFException();
        }
        if (j10 < 4096) {
            return new g(v0(j10));
        }
        g a02 = a0((int) j10);
        skip(j10);
        return a02;
    }

    @Override // kr.e
    /* renamed from: q0, reason: merged with bridge method [inline-methods] */
    public d h0(long j10) {
        if (j10 == 0) {
            return F(48);
        }
        long j11 = (j10 >>> 1) | j10;
        long j12 = j11 | (j11 >>> 2);
        long j13 = j12 | (j12 >>> 4);
        long j14 = j13 | (j13 >>> 8);
        long j15 = j14 | (j14 >>> 16);
        long j16 = j15 | (j15 >>> 32);
        long j17 = j16 - ((j16 >>> 1) & 6148914691236517205L);
        long j18 = ((j17 >>> 2) & 3689348814741910323L) + (j17 & 3689348814741910323L);
        long j19 = ((j18 >>> 4) + j18) & 1085102592571150095L;
        long j20 = j19 + (j19 >>> 8);
        long j21 = j20 + (j20 >>> 16);
        int i10 = (int) ((((j21 & 63) + ((j21 >>> 32) & 63)) + 3) / 4);
        v g02 = g0(i10);
        byte[] bArr = g02.f26685a;
        int i11 = g02.f26687c;
        for (int i12 = (i11 + i10) - 1; i12 >= i11; i12--) {
            bArr[i12] = lr.a.b()[(int) (15 & j10)];
            j10 >>>= 4;
        }
        g02.f26687c += i10;
        V(X() + i10);
        return this;
    }

    @Override // kr.f
    public String r0() {
        return O(Long.MAX_VALUE);
    }

    @Override // java.nio.channels.ReadableByteChannel
    public int read(ByteBuffer sink) {
        kotlin.jvm.internal.t.g(sink, "sink");
        v vVar = this.f26638p;
        if (vVar == null) {
            return -1;
        }
        int min = Math.min(sink.remaining(), vVar.f26687c - vVar.f26686b);
        sink.put(vVar.f26685a, vVar.f26686b, min);
        int i10 = vVar.f26686b + min;
        vVar.f26686b = i10;
        this.f26639q -= min;
        if (i10 == vVar.f26687c) {
            this.f26638p = vVar.b();
            w.b(vVar);
        }
        return min;
    }

    @Override // kr.f
    public byte readByte() {
        if (X() == 0) {
            throw new EOFException();
        }
        v vVar = this.f26638p;
        kotlin.jvm.internal.t.d(vVar);
        int i10 = vVar.f26686b;
        int i11 = vVar.f26687c;
        int i12 = i10 + 1;
        byte b10 = vVar.f26685a[i10];
        V(X() - 1);
        if (i12 == i11) {
            this.f26638p = vVar.b();
            w.b(vVar);
        } else {
            vVar.f26686b = i12;
        }
        return b10;
    }

    @Override // kr.f
    public void readFully(byte[] sink) {
        kotlin.jvm.internal.t.g(sink, "sink");
        int i10 = 0;
        while (i10 < sink.length) {
            int read = read(sink, i10, sink.length - i10);
            if (read == -1) {
                throw new EOFException();
            }
            i10 += read;
        }
    }

    @Override // kr.f
    public int readInt() {
        if (X() < 4) {
            throw new EOFException();
        }
        v vVar = this.f26638p;
        kotlin.jvm.internal.t.d(vVar);
        int i10 = vVar.f26686b;
        int i11 = vVar.f26687c;
        if (i11 - i10 < 4) {
            return (readByte() & 255) | ((readByte() & 255) << 24) | ((readByte() & 255) << 16) | ((readByte() & 255) << 8);
        }
        byte[] bArr = vVar.f26685a;
        int i12 = i10 + 1;
        int i13 = i12 + 1;
        int i14 = ((bArr[i10] & 255) << 24) | ((bArr[i12] & 255) << 16);
        int i15 = i13 + 1;
        int i16 = i14 | ((bArr[i13] & 255) << 8);
        int i17 = i15 + 1;
        int i18 = i16 | (bArr[i15] & 255);
        V(X() - 4);
        if (i17 == i11) {
            this.f26638p = vVar.b();
            w.b(vVar);
        } else {
            vVar.f26686b = i17;
        }
        return i18;
    }

    @Override // kr.f
    public long readLong() {
        if (X() < 8) {
            throw new EOFException();
        }
        v vVar = this.f26638p;
        kotlin.jvm.internal.t.d(vVar);
        int i10 = vVar.f26686b;
        int i11 = vVar.f26687c;
        if (i11 - i10 < 8) {
            return ((readInt() & 4294967295L) << 32) | (4294967295L & readInt());
        }
        byte[] bArr = vVar.f26685a;
        long j10 = (bArr[i10] & 255) << 56;
        int i12 = i10 + 1 + 1 + 1;
        long j11 = j10 | ((bArr[r7] & 255) << 48) | ((bArr[r1] & 255) << 40);
        long j12 = j11 | ((bArr[i12] & 255) << 32) | ((bArr[r1] & 255) << 24);
        long j13 = j12 | ((bArr[r8] & 255) << 16);
        long j14 = j13 | ((bArr[r1] & 255) << 8);
        int i13 = i12 + 1 + 1 + 1 + 1 + 1;
        long j15 = j14 | (bArr[r8] & 255);
        V(X() - 8);
        if (i13 == i11) {
            this.f26638p = vVar.b();
            w.b(vVar);
        } else {
            vVar.f26686b = i13;
        }
        return j15;
    }

    @Override // kr.f
    public short readShort() {
        if (X() < 2) {
            throw new EOFException();
        }
        v vVar = this.f26638p;
        kotlin.jvm.internal.t.d(vVar);
        int i10 = vVar.f26686b;
        int i11 = vVar.f26687c;
        if (i11 - i10 < 2) {
            return (short) ((readByte() & 255) | ((readByte() & 255) << 8));
        }
        byte[] bArr = vVar.f26685a;
        int i12 = i10 + 1;
        int i13 = i12 + 1;
        int i14 = ((bArr[i10] & 255) << 8) | (bArr[i12] & 255);
        V(X() - 2);
        if (i13 == i11) {
            this.f26638p = vVar.b();
            w.b(vVar);
        } else {
            vVar.f26686b = i13;
        }
        return (short) i14;
    }

    public long s(byte b10, long j10, long j11) {
        v vVar;
        int i10;
        long j12 = 0;
        boolean z10 = false;
        if (0 <= j10 && j10 <= j11) {
            z10 = true;
        }
        if (!z10) {
            throw new IllegalArgumentException(("size=" + X() + " fromIndex=" + j10 + " toIndex=" + j11).toString());
        }
        if (j11 > X()) {
            j11 = X();
        }
        if (j10 == j11 || (vVar = this.f26638p) == null) {
            return -1L;
        }
        if (X() - j10 < j10) {
            j12 = X();
            while (j12 > j10) {
                vVar = vVar.f26691g;
                kotlin.jvm.internal.t.d(vVar);
                j12 -= vVar.f26687c - vVar.f26686b;
            }
            while (j12 < j11) {
                byte[] bArr = vVar.f26685a;
                int min = (int) Math.min(vVar.f26687c, (vVar.f26686b + j11) - j12);
                i10 = (int) ((vVar.f26686b + j10) - j12);
                while (i10 < min) {
                    if (bArr[i10] != b10) {
                        i10++;
                    }
                }
                j12 += vVar.f26687c - vVar.f26686b;
                vVar = vVar.f26690f;
                kotlin.jvm.internal.t.d(vVar);
                j10 = j12;
            }
            return -1L;
        }
        while (true) {
            long j13 = (vVar.f26687c - vVar.f26686b) + j12;
            if (j13 > j10) {
                break;
            }
            vVar = vVar.f26690f;
            kotlin.jvm.internal.t.d(vVar);
            j12 = j13;
        }
        while (j12 < j11) {
            byte[] bArr2 = vVar.f26685a;
            int min2 = (int) Math.min(vVar.f26687c, (vVar.f26686b + j11) - j12);
            i10 = (int) ((vVar.f26686b + j10) - j12);
            while (i10 < min2) {
                if (bArr2[i10] != b10) {
                    i10++;
                }
            }
            j12 += vVar.f26687c - vVar.f26686b;
            vVar = vVar.f26690f;
            kotlin.jvm.internal.t.d(vVar);
            j10 = j12;
        }
        return -1L;
        return (i10 - vVar.f26686b) + j12;
    }

    @Override // kr.f
    public void skip(long j10) {
        while (j10 > 0) {
            v vVar = this.f26638p;
            if (vVar == null) {
                throw new EOFException();
            }
            int min = (int) Math.min(j10, vVar.f26687c - vVar.f26686b);
            long j11 = min;
            V(X() - j11);
            j10 -= j11;
            int i10 = vVar.f26686b + min;
            vVar.f26686b = i10;
            if (i10 == vVar.f26687c) {
                this.f26638p = vVar.b();
                w.b(vVar);
            }
        }
    }

    public long t(g bytes, long j10) {
        long j11 = j10;
        kotlin.jvm.internal.t.g(bytes, "bytes");
        if (!(bytes.size() > 0)) {
            throw new IllegalArgumentException("bytes is empty".toString());
        }
        long j12 = 0;
        if (!(j11 >= 0)) {
            throw new IllegalArgumentException(("fromIndex < 0: " + j11).toString());
        }
        v vVar = this.f26638p;
        if (vVar != null) {
            if (X() - j11 < j11) {
                long X = X();
                while (X > j11) {
                    vVar = vVar.f26691g;
                    kotlin.jvm.internal.t.d(vVar);
                    X -= vVar.f26687c - vVar.f26686b;
                }
                byte[] y10 = bytes.y();
                byte b10 = y10[0];
                int size = bytes.size();
                long X2 = (X() - size) + 1;
                while (X < X2) {
                    byte[] bArr = vVar.f26685a;
                    int min = (int) Math.min(vVar.f26687c, (vVar.f26686b + X2) - X);
                    for (int i10 = (int) ((vVar.f26686b + j11) - X); i10 < min; i10++) {
                        if (bArr[i10] == b10 && lr.a.c(vVar, i10 + 1, y10, 1, size)) {
                            return (i10 - vVar.f26686b) + X;
                        }
                    }
                    X += vVar.f26687c - vVar.f26686b;
                    vVar = vVar.f26690f;
                    kotlin.jvm.internal.t.d(vVar);
                    j11 = X;
                }
            } else {
                while (true) {
                    long j13 = (vVar.f26687c - vVar.f26686b) + j12;
                    if (j13 > j11) {
                        break;
                    }
                    vVar = vVar.f26690f;
                    kotlin.jvm.internal.t.d(vVar);
                    j12 = j13;
                }
                byte[] y11 = bytes.y();
                byte b11 = y11[0];
                int size2 = bytes.size();
                long X3 = (X() - size2) + 1;
                while (j12 < X3) {
                    byte[] bArr2 = vVar.f26685a;
                    long j14 = j12;
                    int min2 = (int) Math.min(vVar.f26687c, (vVar.f26686b + X3) - j12);
                    for (int i11 = (int) ((vVar.f26686b + j11) - j14); i11 < min2; i11++) {
                        if (bArr2[i11] == b11 && lr.a.c(vVar, i11 + 1, y11, 1, size2)) {
                            return (i11 - vVar.f26686b) + j14;
                        }
                    }
                    j12 = j14 + (vVar.f26687c - vVar.f26686b);
                    vVar = vVar.f26690f;
                    kotlin.jvm.internal.t.d(vVar);
                    j11 = j12;
                }
            }
        }
        return -1L;
    }

    @Override // kr.e
    /* renamed from: t0, reason: merged with bridge method [inline-methods] */
    public d x(int i10) {
        v g02 = g0(4);
        byte[] bArr = g02.f26685a;
        int i11 = g02.f26687c;
        int i12 = i11 + 1;
        bArr[i11] = (byte) ((i10 >>> 24) & Constants.MAX_HOST_LENGTH);
        int i13 = i12 + 1;
        bArr[i12] = (byte) ((i10 >>> 16) & Constants.MAX_HOST_LENGTH);
        int i14 = i13 + 1;
        bArr[i13] = (byte) ((i10 >>> 8) & Constants.MAX_HOST_LENGTH);
        bArr[i14] = (byte) (i10 & Constants.MAX_HOST_LENGTH);
        g02.f26687c = i14 + 1;
        V(X() + 4);
        return this;
    }

    public String toString() {
        return Y().toString();
    }

    public d u0(long j10) {
        v g02 = g0(8);
        byte[] bArr = g02.f26685a;
        int i10 = g02.f26687c;
        int i11 = i10 + 1;
        bArr[i10] = (byte) ((j10 >>> 56) & 255);
        int i12 = i11 + 1;
        bArr[i11] = (byte) ((j10 >>> 48) & 255);
        int i13 = i12 + 1;
        bArr[i12] = (byte) ((j10 >>> 40) & 255);
        int i14 = i13 + 1;
        bArr[i13] = (byte) ((j10 >>> 32) & 255);
        int i15 = i14 + 1;
        bArr[i14] = (byte) ((j10 >>> 24) & 255);
        int i16 = i15 + 1;
        bArr[i15] = (byte) ((j10 >>> 16) & 255);
        int i17 = i16 + 1;
        bArr[i16] = (byte) ((j10 >>> 8) & 255);
        bArr[i17] = (byte) (j10 & 255);
        g02.f26687c = i17 + 1;
        V(X() + 8);
        return this;
    }

    public long v(g targetBytes, long j10) {
        int i10;
        int i11;
        kotlin.jvm.internal.t.g(targetBytes, "targetBytes");
        long j11 = 0;
        if (!(j10 >= 0)) {
            throw new IllegalArgumentException(("fromIndex < 0: " + j10).toString());
        }
        v vVar = this.f26638p;
        if (vVar == null) {
            return -1L;
        }
        if (X() - j10 < j10) {
            j11 = X();
            while (j11 > j10) {
                vVar = vVar.f26691g;
                kotlin.jvm.internal.t.d(vVar);
                j11 -= vVar.f26687c - vVar.f26686b;
            }
            if (targetBytes.size() == 2) {
                byte s10 = targetBytes.s(0);
                byte s11 = targetBytes.s(1);
                while (j11 < X()) {
                    byte[] bArr = vVar.f26685a;
                    i10 = (int) ((vVar.f26686b + j10) - j11);
                    int i12 = vVar.f26687c;
                    while (i10 < i12) {
                        byte b10 = bArr[i10];
                        if (b10 != s10 && b10 != s11) {
                            i10++;
                        }
                        i11 = vVar.f26686b;
                    }
                    j11 += vVar.f26687c - vVar.f26686b;
                    vVar = vVar.f26690f;
                    kotlin.jvm.internal.t.d(vVar);
                    j10 = j11;
                }
                return -1L;
            }
            byte[] y10 = targetBytes.y();
            while (j11 < X()) {
                byte[] bArr2 = vVar.f26685a;
                i10 = (int) ((vVar.f26686b + j10) - j11);
                int i13 = vVar.f26687c;
                while (i10 < i13) {
                    byte b11 = bArr2[i10];
                    for (byte b12 : y10) {
                        if (b11 == b12) {
                            i11 = vVar.f26686b;
                        }
                    }
                    i10++;
                }
                j11 += vVar.f26687c - vVar.f26686b;
                vVar = vVar.f26690f;
                kotlin.jvm.internal.t.d(vVar);
                j10 = j11;
            }
            return -1L;
        }
        while (true) {
            long j12 = (vVar.f26687c - vVar.f26686b) + j11;
            if (j12 > j10) {
                break;
            }
            vVar = vVar.f26690f;
            kotlin.jvm.internal.t.d(vVar);
            j11 = j12;
        }
        if (targetBytes.size() == 2) {
            byte s12 = targetBytes.s(0);
            byte s13 = targetBytes.s(1);
            while (j11 < X()) {
                byte[] bArr3 = vVar.f26685a;
                i10 = (int) ((vVar.f26686b + j10) - j11);
                int i14 = vVar.f26687c;
                while (i10 < i14) {
                    byte b13 = bArr3[i10];
                    if (b13 != s12 && b13 != s13) {
                        i10++;
                    }
                    i11 = vVar.f26686b;
                }
                j11 += vVar.f26687c - vVar.f26686b;
                vVar = vVar.f26690f;
                kotlin.jvm.internal.t.d(vVar);
                j10 = j11;
            }
            return -1L;
        }
        byte[] y11 = targetBytes.y();
        while (j11 < X()) {
            byte[] bArr4 = vVar.f26685a;
            i10 = (int) ((vVar.f26686b + j10) - j11);
            int i15 = vVar.f26687c;
            while (i10 < i15) {
                byte b14 = bArr4[i10];
                for (byte b15 : y11) {
                    if (b14 == b15) {
                        i11 = vVar.f26686b;
                    }
                }
                i10++;
            }
            j11 += vVar.f26687c - vVar.f26686b;
            vVar = vVar.f26690f;
            kotlin.jvm.internal.t.d(vVar);
            j10 = j11;
        }
        return -1L;
        return (i10 - i11) + j11;
    }

    @Override // kr.f
    public byte[] v0(long j10) {
        if (!(j10 >= 0 && j10 <= 2147483647L)) {
            throw new IllegalArgumentException(("byteCount: " + j10).toString());
        }
        if (X() < j10) {
            throw new EOFException();
        }
        byte[] bArr = new byte[(int) j10];
        readFully(bArr);
        return bArr;
    }

    public OutputStream w() {
        return new c();
    }

    @Override // kr.e
    /* renamed from: w0, reason: merged with bridge method [inline-methods] */
    public d u(int i10) {
        v g02 = g0(2);
        byte[] bArr = g02.f26685a;
        int i11 = g02.f26687c;
        int i12 = i11 + 1;
        bArr[i11] = (byte) ((i10 >>> 8) & Constants.MAX_HOST_LENGTH);
        bArr[i12] = (byte) (i10 & Constants.MAX_HOST_LENGTH);
        g02.f26687c = i12 + 1;
        V(X() + 2);
        return this;
    }

    @Override // java.nio.channels.WritableByteChannel
    public int write(ByteBuffer source) {
        kotlin.jvm.internal.t.g(source, "source");
        int remaining = source.remaining();
        int i10 = remaining;
        while (i10 > 0) {
            v g02 = g0(1);
            int min = Math.min(i10, 8192 - g02.f26687c);
            source.get(g02.f26685a, g02.f26687c, min);
            i10 -= min;
            g02.f26687c += min;
        }
        this.f26639q += remaining;
        return remaining;
    }

    public d x0(String string, int i10, int i11, Charset charset) {
        kotlin.jvm.internal.t.g(string, "string");
        kotlin.jvm.internal.t.g(charset, "charset");
        if (!(i10 >= 0)) {
            throw new IllegalArgumentException(("beginIndex < 0: " + i10).toString());
        }
        if (!(i11 >= i10)) {
            throw new IllegalArgumentException(("endIndex < beginIndex: " + i11 + " < " + i10).toString());
        }
        if (!(i11 <= string.length())) {
            throw new IllegalArgumentException(("endIndex > string.length: " + i11 + " > " + string.length()).toString());
        }
        if (kotlin.jvm.internal.t.b(charset, kotlin.text.d.f26484b)) {
            return f0(string, i10, i11);
        }
        String substring = string.substring(i10, i11);
        kotlin.jvm.internal.t.f(substring, "substring(...)");
        byte[] bytes = substring.getBytes(charset);
        kotlin.jvm.internal.t.f(bytes, "getBytes(...)");
        return d0(bytes, 0, bytes.length);
    }

    public boolean y(long j10, g bytes, int i10, int i11) {
        kotlin.jvm.internal.t.g(bytes, "bytes");
        if (j10 < 0 || i10 < 0 || i11 < 0 || X() - j10 < i11 || bytes.size() - i10 < i11) {
            return false;
        }
        for (int i12 = 0; i12 < i11; i12++) {
            if (p(i12 + j10) != bytes.s(i10 + i12)) {
                return false;
            }
        }
        return true;
    }

    public d y0(String string, Charset charset) {
        kotlin.jvm.internal.t.g(string, "string");
        kotlin.jvm.internal.t.g(charset, "charset");
        return x0(string, 0, string.length(), charset);
    }

    public final a z(a unsafeCursor) {
        kotlin.jvm.internal.t.g(unsafeCursor, "unsafeCursor");
        return lr.a.a(this, unsafeCursor);
    }

    /* loaded from: classes4.dex */
    public static final class b extends InputStream {
        b() {
        }

        @Override // java.io.InputStream
        public int available() {
            return (int) Math.min(d.this.X(), Api.BaseClientBuilder.API_PRIORITY_OTHER);
        }

        @Override // java.io.InputStream, java.io.Closeable, java.lang.AutoCloseable
        public void close() {
        }

        @Override // java.io.InputStream
        public int read() {
            if (d.this.X() > 0) {
                return d.this.readByte() & 255;
            }
            return -1;
        }

        public String toString() {
            return d.this + ".inputStream()";
        }

        @Override // java.io.InputStream
        public int read(byte[] sink, int i10, int i11) {
            kotlin.jvm.internal.t.g(sink, "sink");
            return d.this.read(sink, i10, i11);
        }
    }

    public int read(byte[] sink, int i10, int i11) {
        kotlin.jvm.internal.t.g(sink, "sink");
        kr.b.b(sink.length, i10, i11);
        v vVar = this.f26638p;
        if (vVar == null) {
            return -1;
        }
        int min = Math.min(i11, vVar.f26687c - vVar.f26686b);
        byte[] bArr = vVar.f26685a;
        int i12 = vVar.f26686b;
        sm.o.g(bArr, sink, i10, i12, i12 + min);
        vVar.f26686b += min;
        V(X() - min);
        if (vVar.f26686b == vVar.f26687c) {
            this.f26638p = vVar.b();
            w.b(vVar);
        }
        return min;
    }
}
