package x7;

import d5.AbstractC0844a;
import java.io.EOFException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.ByteChannel;
import java.nio.charset.Charset;

/* JADX INFO: renamed from: x7.g, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C1731g implements InterfaceC1733i, InterfaceC1732h, Cloneable, ByteChannel, AutoCloseable {

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public C f18764q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public long f18765r;

    public final byte A(long j8) {
        s7.d.g(this.f18765r, j8, 1L);
        C c3 = this.f18764q;
        if (c3 == null) {
            P6.g.b(null);
            throw null;
        }
        long j9 = this.f18765r;
        if (j9 - j8 < j8) {
            while (j9 > j8) {
                c3 = c3.f18733g;
                P6.g.b(c3);
                j9 -= (long) (c3.f18729c - c3.f18728b);
            }
            return c3.f18727a[(int) ((((long) c3.f18728b) + j8) - j9)];
        }
        long j10 = 0;
        while (true) {
            int i = c3.f18729c;
            int i5 = c3.f18728b;
            long j11 = ((long) (i - i5)) + j10;
            if (j11 > j8) {
                return c3.f18727a[(int) ((((long) i5) + j8) - j10)];
            }
            c3 = c3.f18732f;
            P6.g.b(c3);
            j10 = j11;
        }
    }

    public final void A0(int i) {
        if (i < 128) {
            u0(i);
            return;
        }
        if (i < 2048) {
            C cQ0 = q0(2);
            int i5 = cQ0.f18729c;
            byte[] bArr = cQ0.f18727a;
            bArr[i5] = (byte) ((i >> 6) | 192);
            bArr[i5 + 1] = (byte) ((i & 63) | 128);
            cQ0.f18729c = i5 + 2;
            this.f18765r += 2;
            return;
        }
        if (55296 <= i && i < 57344) {
            u0(63);
            return;
        }
        if (i < 65536) {
            C cQ02 = q0(3);
            int i8 = cQ02.f18729c;
            byte[] bArr2 = cQ02.f18727a;
            bArr2[i8] = (byte) ((i >> 12) | 224);
            bArr2[i8 + 1] = (byte) (((i >> 6) & 63) | 128);
            bArr2[i8 + 2] = (byte) ((i & 63) | 128);
            cQ02.f18729c = i8 + 3;
            this.f18765r += 3;
            return;
        }
        if (i > 1114111) {
            throw new IllegalArgumentException("Unexpected code point: 0x".concat(s7.d.E(i)));
        }
        C cQ03 = q0(4);
        int i9 = cQ03.f18729c;
        byte[] bArr3 = cQ03.f18727a;
        bArr3[i9] = (byte) ((i >> 18) | 240);
        bArr3[i9 + 1] = (byte) (((i >> 12) & 63) | 128);
        bArr3[i9 + 2] = (byte) (((i >> 6) & 63) | 128);
        bArr3[i9 + 3] = (byte) ((i & 63) | 128);
        cQ03.f18729c = i9 + 4;
        this.f18765r += 4;
    }

    @Override // x7.InterfaceC1733i
    public final boolean C(long j8) {
        return this.f18765r >= j8;
    }

    @Override // x7.InterfaceC1733i
    public final long F(C1734j c1734j) {
        P6.g.e(c1734j, "bytes");
        return H(c1734j, 0L);
    }

    public final long H(C1734j c1734j, long j8) {
        P6.g.e(c1734j, "bytes");
        byte[] bArr = c1734j.f18767q;
        if (bArr.length <= 0) {
            throw new IllegalArgumentException("bytes is empty");
        }
        long j9 = 0;
        if (j8 < 0) {
            throw new IllegalArgumentException(AbstractC0844a.i(j8, "fromIndex < 0: ").toString());
        }
        C c3 = this.f18764q;
        if (c3 == null) {
            return -1L;
        }
        long j10 = this.f18765r;
        if (j10 - j8 < j8) {
            while (j10 > j8) {
                c3 = c3.f18733g;
                P6.g.b(c3);
                j10 -= (long) (c3.f18729c - c3.f18728b);
            }
            byte b8 = bArr[0];
            int length = bArr.length;
            long j11 = (this.f18765r - ((long) length)) + 1;
            while (j10 < j11) {
                int iMin = (int) Math.min(c3.f18729c, (((long) c3.f18728b) + j11) - j10);
                for (int i = (int) ((((long) c3.f18728b) + j8) - j10); i < iMin; i++) {
                    if (c3.f18727a[i] == b8 && y7.a.a(c3, i + 1, bArr, length)) {
                        return ((long) (i - c3.f18728b)) + j10;
                    }
                }
                j10 += (long) (c3.f18729c - c3.f18728b);
                c3 = c3.f18732f;
                P6.g.b(c3);
                j8 = j10;
            }
            return -1L;
        }
        while (true) {
            long j12 = ((long) (c3.f18729c - c3.f18728b)) + j9;
            if (j12 > j8) {
                break;
            }
            c3 = c3.f18732f;
            P6.g.b(c3);
            j9 = j12;
        }
        byte b9 = bArr[0];
        int length2 = bArr.length;
        long j13 = (this.f18765r - ((long) length2)) + 1;
        while (j9 < j13) {
            int iMin2 = (int) Math.min(c3.f18729c, (((long) c3.f18728b) + j13) - j9);
            for (int i5 = (int) ((((long) c3.f18728b) + j8) - j9); i5 < iMin2; i5++) {
                if (c3.f18727a[i5] == b9 && y7.a.a(c3, i5 + 1, bArr, length2)) {
                    return ((long) (i5 - c3.f18728b)) + j9;
                }
            }
            j9 += (long) (c3.f18729c - c3.f18728b);
            c3 = c3.f18732f;
            P6.g.b(c3);
            j8 = j9;
        }
        return -1L;
    }

    @Override // x7.InterfaceC1733i
    public final boolean I(C1734j c1734j) {
        P6.g.e(c1734j, "bytes");
        byte[] bArr = c1734j.f18767q;
        int length = bArr.length;
        if (length >= 0 && this.f18765r >= length && bArr.length >= length) {
            for (int i = 0; i < length; i++) {
                if (A(i) == bArr[i]) {
                }
            }
            return true;
        }
        return false;
    }

    public final long K(C1734j c1734j, long j8) {
        P6.g.e(c1734j, "targetBytes");
        long j9 = 0;
        if (j8 < 0) {
            throw new IllegalArgumentException(AbstractC0844a.i(j8, "fromIndex < 0: ").toString());
        }
        C c3 = this.f18764q;
        if (c3 == null) {
            return -1L;
        }
        long j10 = this.f18765r;
        long j11 = j10 - j8;
        byte[] bArr = c1734j.f18767q;
        if (j11 < j8) {
            while (j10 > j8) {
                c3 = c3.f18733g;
                P6.g.b(c3);
                j10 -= (long) (c3.f18729c - c3.f18728b);
            }
            if (bArr.length == 2) {
                byte b8 = bArr[0];
                byte b9 = bArr[1];
                while (j10 < this.f18765r) {
                    int i = c3.f18729c;
                    for (int i5 = (int) ((((long) c3.f18728b) + j8) - j10); i5 < i; i5++) {
                        byte b10 = c3.f18727a[i5];
                        if (b10 == b8 || b10 == b9) {
                            return ((long) (i5 - c3.f18728b)) + j10;
                        }
                    }
                    j10 += (long) (c3.f18729c - c3.f18728b);
                    c3 = c3.f18732f;
                    P6.g.b(c3);
                    j8 = j10;
                }
                return -1L;
            }
            while (j10 < this.f18765r) {
                int i8 = c3.f18729c;
                for (int i9 = (int) ((((long) c3.f18728b) + j8) - j10); i9 < i8; i9++) {
                    byte b11 = c3.f18727a[i9];
                    for (byte b12 : bArr) {
                        if (b11 == b12) {
                            return ((long) (i9 - c3.f18728b)) + j10;
                        }
                    }
                }
                j10 += (long) (c3.f18729c - c3.f18728b);
                c3 = c3.f18732f;
                P6.g.b(c3);
                j8 = j10;
            }
            return -1L;
        }
        while (true) {
            long j12 = ((long) (c3.f18729c - c3.f18728b)) + j9;
            if (j12 > j8) {
                break;
            }
            c3 = c3.f18732f;
            P6.g.b(c3);
            j9 = j12;
        }
        if (bArr.length == 2) {
            byte b13 = bArr[0];
            byte b14 = bArr[1];
            while (j9 < this.f18765r) {
                int i10 = c3.f18729c;
                for (int i11 = (int) ((((long) c3.f18728b) + j8) - j9); i11 < i10; i11++) {
                    byte b15 = c3.f18727a[i11];
                    if (b15 == b13 || b15 == b14) {
                        return ((long) (i11 - c3.f18728b)) + j9;
                    }
                }
                j9 += (long) (c3.f18729c - c3.f18728b);
                c3 = c3.f18732f;
                P6.g.b(c3);
                j8 = j9;
            }
            return -1L;
        }
        while (j9 < this.f18765r) {
            int i12 = c3.f18729c;
            for (int i13 = (int) ((((long) c3.f18728b) + j8) - j9); i13 < i12; i13++) {
                byte b16 = c3.f18727a[i13];
                for (byte b17 : bArr) {
                    if (b16 == b17) {
                        return ((long) (i13 - c3.f18728b)) + j9;
                    }
                }
            }
            j9 += (long) (c3.f18729c - c3.f18728b);
            c3 = c3.f18732f;
            P6.g.b(c3);
            j8 = j9;
        }
        return -1L;
    }

    @Override // x7.InterfaceC1733i
    public final long L(InterfaceC1732h interfaceC1732h) {
        long j8 = this.f18765r;
        if (j8 > 0) {
            interfaceC1732h.X(this, j8);
        }
        return j8;
    }

    @Override // x7.H
    public final long M(C1731g c1731g, long j8) {
        P6.g.e(c1731g, "sink");
        if (j8 < 0) {
            throw new IllegalArgumentException(AbstractC0844a.i(j8, "byteCount < 0: ").toString());
        }
        long j9 = this.f18765r;
        if (j9 == 0) {
            return -1L;
        }
        if (j8 > j9) {
            j8 = j9;
        }
        c1731g.X(this, j8);
        return j8;
    }

    public final int O(byte[] bArr, int i, int i5) {
        s7.d.g(bArr.length, i, i5);
        C c3 = this.f18764q;
        if (c3 == null) {
            return -1;
        }
        int iMin = Math.min(i5, c3.f18729c - c3.f18728b);
        int i8 = c3.f18728b;
        B6.j.F(i, i8, i8 + iMin, c3.f18727a, bArr);
        int i9 = c3.f18728b + iMin;
        c3.f18728b = i9;
        this.f18765r -= (long) iMin;
        if (i9 == c3.f18729c) {
            this.f18764q = c3.a();
            D.a(c3);
        }
        return iMin;
    }

    public final byte Q() throws EOFException {
        if (this.f18765r == 0) {
            throw new EOFException();
        }
        C c3 = this.f18764q;
        P6.g.b(c3);
        int i = c3.f18728b;
        int i5 = c3.f18729c;
        int i8 = i + 1;
        byte b8 = c3.f18727a[i];
        this.f18765r--;
        if (i8 != i5) {
            c3.f18728b = i8;
            return b8;
        }
        this.f18764q = c3.a();
        D.a(c3);
        return b8;
    }

    @Override // x7.InterfaceC1732h
    public final /* bridge */ /* synthetic */ InterfaceC1732h S(int i, byte[] bArr) {
        s0(bArr, 0, i);
        return this;
    }

    @Override // x7.InterfaceC1733i
    public final byte[] U() {
        return V(this.f18765r);
    }

    public final byte[] V(long j8) throws EOFException {
        if (j8 < 0 || j8 > 2147483647L) {
            throw new IllegalArgumentException(AbstractC0844a.i(j8, "byteCount: ").toString());
        }
        if (this.f18765r < j8) {
            throw new EOFException();
        }
        int i = (int) j8;
        byte[] bArr = new byte[i];
        int i5 = 0;
        while (i5 < i) {
            int iO = O(bArr, i5, i - i5);
            if (iO == -1) {
                throw new EOFException();
            }
            i5 += iO;
        }
        return bArr;
    }

    @Override // x7.F
    public final void X(C1731g c1731g, long j8) {
        C cB;
        P6.g.e(c1731g, "source");
        if (c1731g == this) {
            throw new IllegalArgumentException("source == this");
        }
        s7.d.g(c1731g.f18765r, 0L, j8);
        while (j8 > 0) {
            C c3 = c1731g.f18764q;
            P6.g.b(c3);
            int i = c3.f18729c;
            C c8 = c1731g.f18764q;
            P6.g.b(c8);
            long j9 = i - c8.f18728b;
            int i5 = 0;
            if (j8 < j9) {
                C c9 = this.f18764q;
                C c10 = c9 != null ? c9.f18733g : null;
                if (c10 != null && c10.f18731e) {
                    if ((((long) c10.f18729c) + j8) - ((long) (c10.f18730d ? 0 : c10.f18728b)) <= 8192) {
                        C c11 = c1731g.f18764q;
                        P6.g.b(c11);
                        c11.d(c10, (int) j8);
                        c1731g.f18765r -= j8;
                        this.f18765r += j8;
                        return;
                    }
                }
                C c12 = c1731g.f18764q;
                P6.g.b(c12);
                int i8 = (int) j8;
                if (i8 <= 0 || i8 > c12.f18729c - c12.f18728b) {
                    throw new IllegalArgumentException("byteCount out of range");
                }
                if (i8 >= 1024) {
                    cB = c12.c();
                } else {
                    cB = D.b();
                    int i9 = c12.f18728b;
                    B6.j.F(0, i9, i9 + i8, c12.f18727a, cB.f18727a);
                }
                cB.f18729c = cB.f18728b + i8;
                c12.f18728b += i8;
                C c13 = c12.f18733g;
                P6.g.b(c13);
                c13.b(cB);
                c1731g.f18764q = cB;
            }
            C c14 = c1731g.f18764q;
            P6.g.b(c14);
            long j10 = c14.f18729c - c14.f18728b;
            c1731g.f18764q = c14.a();
            C c15 = this.f18764q;
            if (c15 == null) {
                this.f18764q = c14;
                c14.f18733g = c14;
                c14.f18732f = c14;
            } else {
                C c16 = c15.f18733g;
                P6.g.b(c16);
                c16.b(c14);
                C c17 = c14.f18733g;
                if (c17 == c14) {
                    throw new IllegalStateException("cannot compact");
                }
                P6.g.b(c17);
                if (c17.f18731e) {
                    int i10 = c14.f18729c - c14.f18728b;
                    C c18 = c14.f18733g;
                    P6.g.b(c18);
                    int i11 = 8192 - c18.f18729c;
                    C c19 = c14.f18733g;
                    P6.g.b(c19);
                    if (!c19.f18730d) {
                        C c20 = c14.f18733g;
                        P6.g.b(c20);
                        i5 = c20.f18728b;
                    }
                    if (i10 <= i11 + i5) {
                        C c21 = c14.f18733g;
                        P6.g.b(c21);
                        c14.d(c21, i10);
                        c14.a();
                        D.a(c14);
                    }
                }
            }
            c1731g.f18765r -= j10;
            this.f18765r += j10;
            j8 -= j10;
        }
    }

    @Override // x7.InterfaceC1732h
    public final /* bridge */ /* synthetic */ InterfaceC1732h Y(String str) {
        z0(str);
        return this;
    }

    @Override // x7.InterfaceC1732h
    public final /* bridge */ /* synthetic */ InterfaceC1732h a0(long j8) {
        v0(j8);
        return this;
    }

    public final Object clone() {
        C1731g c1731g = new C1731g();
        if (this.f18765r == 0) {
            return c1731g;
        }
        C c3 = this.f18764q;
        P6.g.b(c3);
        C c8 = c3.c();
        c1731g.f18764q = c8;
        c8.f18733g = c8;
        c8.f18732f = c8;
        for (C c9 = c3.f18732f; c9 != c3; c9 = c9.f18732f) {
            C c10 = c8.f18733g;
            P6.g.b(c10);
            P6.g.b(c9);
            c10.b(c9.c());
        }
        c1731g.f18765r = this.f18765r;
        return c1731g;
    }

    @Override // x7.InterfaceC1732h
    public final /* bridge */ /* synthetic */ InterfaceC1732h d0(int i) {
        u0(i);
        return this;
    }

    public final boolean equals(Object obj) {
        boolean z8 = true;
        if (this == obj) {
            return true;
        }
        boolean z9 = false;
        if (!(obj instanceof C1731g)) {
            return false;
        }
        long j8 = this.f18765r;
        C1731g c1731g = (C1731g) obj;
        if (j8 != c1731g.f18765r) {
            return false;
        }
        if (j8 == 0) {
            return true;
        }
        C c3 = this.f18764q;
        P6.g.b(c3);
        C c8 = c1731g.f18764q;
        P6.g.b(c8);
        int i = c3.f18728b;
        int i5 = c8.f18728b;
        long j9 = 0;
        while (j9 < this.f18765r) {
            long jMin = Math.min(c3.f18729c - i, c8.f18729c - i5);
            long j10 = 0;
            while (j10 < jMin) {
                int i8 = i + 1;
                boolean z10 = z8;
                byte b8 = c3.f18727a[i];
                int i9 = i5 + 1;
                boolean z11 = z9;
                if (b8 != c8.f18727a[i5]) {
                    return z11;
                }
                j10++;
                i5 = i9;
                i = i8;
                z8 = z10;
                z9 = z11;
            }
            boolean z12 = z8;
            boolean z13 = z9;
            if (i == c3.f18729c) {
                C c9 = c3.f18732f;
                P6.g.b(c9);
                i = c9.f18728b;
                c3 = c9;
            }
            if (i5 == c8.f18729c) {
                c8 = c8.f18732f;
                P6.g.b(c8);
                i5 = c8.f18728b;
            }
            j9 += jMin;
            z8 = z12;
            z9 = z13;
        }
        return z8;
    }

    @Override // x7.H
    public final J f() {
        return J.f18740d;
    }

    public final C1734j f0(long j8) throws EOFException {
        if (j8 < 0 || j8 > 2147483647L) {
            throw new IllegalArgumentException(AbstractC0844a.i(j8, "byteCount: ").toString());
        }
        if (this.f18765r < j8) {
            throw new EOFException();
        }
        if (j8 < 4096) {
            return new C1734j(V(j8));
        }
        C1734j c1734jP0 = p0((int) j8);
        y(j8);
        return c1734jP0;
    }

    @Override // x7.InterfaceC1732h
    public final InterfaceC1732h h(byte[] bArr) {
        P6.g.e(bArr, "source");
        s0(bArr, 0, bArr.length);
        return this;
    }

    public final int hashCode() {
        C c3 = this.f18764q;
        if (c3 == null) {
            return 0;
        }
        int i = 1;
        do {
            int i5 = c3.f18729c;
            for (int i8 = c3.f18728b; i8 < i5; i8++) {
                i = (i * 31) + c3.f18727a[i8];
            }
            c3 = c3.f18732f;
            P6.g.b(c3);
        } while (c3 != this.f18764q);
        return i;
    }

    @Override // x7.InterfaceC1733i
    public final long i(C1734j c1734j) {
        P6.g.e(c1734j, "targetBytes");
        return K(c1734j, 0L);
    }

    @Override // x7.InterfaceC1733i
    public final InputStream i0() {
        return new C1730f(this, 0);
    }

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

    /* JADX WARN: Removed duplicated region for block: B:32:0x0092  */
    /* JADX WARN: Removed duplicated region for block: B:33:0x009c  */
    /* JADX WARN: Removed duplicated region for block: B:35:0x00a0  */
    /* JADX WARN: Removed duplicated region for block: B:43:0x00a4 A[EDGE_INSN: B:43:0x00a4->B:37:0x00a4 BREAK  A[LOOP:0: B:5:0x0012->B:45:?], SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final long j0() throws EOFException {
        int i;
        if (this.f18765r == 0) {
            throw new EOFException();
        }
        int i5 = 0;
        boolean z8 = false;
        long j8 = 0;
        do {
            C c3 = this.f18764q;
            P6.g.b(c3);
            int i8 = c3.f18728b;
            int i9 = c3.f18729c;
            while (i8 < i9) {
                byte b8 = c3.f18727a[i8];
                if (b8 >= 48 && b8 <= 57) {
                    i = b8 - 48;
                } else if (b8 >= 97 && b8 <= 102) {
                    i = b8 - 87;
                } else if (b8 >= 65 && b8 <= 70) {
                    i = b8 - 55;
                } else {
                    if (i5 == 0) {
                        char[] cArr = y7.b.f19040a;
                        throw new NumberFormatException("Expected leading [0-9a-fA-F] character but was 0x".concat(new String(new char[]{cArr[(b8 >> 4) & 15], cArr[b8 & 15]})));
                    }
                    z8 = true;
                    if (i8 != i9) {
                        this.f18764q = c3.a();
                        D.a(c3);
                    } else {
                        c3.f18728b = i8;
                    }
                    if (!z8) {
                        break;
                    }
                }
                if ((j8 & (-1152921504606846976L)) != 0) {
                    C1731g c1731g = new C1731g();
                    c1731g.w0(j8);
                    c1731g.u0(b8);
                    throw new NumberFormatException("Number too large: ".concat(c1731g.o0()));
                }
                j8 = (j8 << 4) | ((long) i);
                i8++;
                i5++;
            }
            if (i8 != i9) {
            }
            if (!z8) {
            }
        } while (this.f18764q != null);
        this.f18765r -= (long) i5;
        return j8;
    }

    public final int k0() throws EOFException {
        if (this.f18765r < 4) {
            throw new EOFException();
        }
        C c3 = this.f18764q;
        P6.g.b(c3);
        int i = c3.f18728b;
        int i5 = c3.f18729c;
        if (i5 - i < 4) {
            return ((Q() & 255) << 24) | ((Q() & 255) << 16) | ((Q() & 255) << 8) | (Q() & 255);
        }
        byte[] bArr = c3.f18727a;
        int i8 = i + 3;
        int i9 = ((bArr[i + 1] & 255) << 16) | ((bArr[i] & 255) << 24) | ((bArr[i + 2] & 255) << 8);
        int i10 = i + 4;
        int i11 = i9 | (bArr[i8] & 255);
        this.f18765r -= 4;
        if (i10 != i5) {
            c3.f18728b = i10;
            return i11;
        }
        this.f18764q = c3.a();
        D.a(c3);
        return i11;
    }

    public final short l0() throws EOFException {
        if (this.f18765r < 2) {
            throw new EOFException();
        }
        C c3 = this.f18764q;
        P6.g.b(c3);
        int i = c3.f18728b;
        int i5 = c3.f18729c;
        if (i5 - i < 2) {
            return (short) (((Q() & 255) << 8) | (Q() & 255));
        }
        int i8 = i + 1;
        byte[] bArr = c3.f18727a;
        int i9 = (bArr[i] & 255) << 8;
        int i10 = i + 2;
        int i11 = (bArr[i8] & 255) | i9;
        this.f18765r -= 2;
        if (i10 == i5) {
            this.f18764q = c3.a();
            D.a(c3);
        } else {
            c3.f18728b = i10;
        }
        return (short) i11;
    }

    public final void m() throws EOFException {
        y(this.f18765r);
    }

    public final short m0() throws EOFException {
        short sL0 = l0();
        return (short) (((sL0 & 255) << 8) | ((65280 & sL0) >>> 8));
    }

    public final long n() {
        long j8 = this.f18765r;
        if (j8 == 0) {
            return 0L;
        }
        C c3 = this.f18764q;
        P6.g.b(c3);
        C c8 = c3.f18733g;
        P6.g.b(c8);
        int i = c8.f18729c;
        return (i >= 8192 || !c8.f18731e) ? j8 : j8 - ((long) (i - c8.f18728b));
    }

    public final String n0(long j8, Charset charset) throws EOFException {
        P6.g.e(charset, "charset");
        if (j8 < 0 || j8 > 2147483647L) {
            throw new IllegalArgumentException(AbstractC0844a.i(j8, "byteCount: ").toString());
        }
        if (this.f18765r < j8) {
            throw new EOFException();
        }
        if (j8 == 0) {
            return "";
        }
        C c3 = this.f18764q;
        P6.g.b(c3);
        int i = c3.f18728b;
        if (((long) i) + j8 > c3.f18729c) {
            return new String(V(j8), charset);
        }
        int i5 = (int) j8;
        String str = new String(c3.f18727a, i, i5, charset);
        int i8 = c3.f18728b + i5;
        c3.f18728b = i8;
        this.f18765r -= j8;
        if (i8 == c3.f18729c) {
            this.f18764q = c3.a();
            D.a(c3);
        }
        return str;
    }

    public final String o0() {
        return n0(this.f18765r, X6.a.f7235a);
    }

    public final C1734j p0(int i) {
        if (i == 0) {
            return C1734j.f18766t;
        }
        s7.d.g(this.f18765r, 0L, i);
        C c3 = this.f18764q;
        int i5 = 0;
        int i8 = 0;
        int i9 = 0;
        while (i8 < i) {
            P6.g.b(c3);
            int i10 = c3.f18729c;
            int i11 = c3.f18728b;
            if (i10 == i11) {
                throw new AssertionError("s.limit == s.pos");
            }
            i8 += i10 - i11;
            i9++;
            c3 = c3.f18732f;
        }
        byte[][] bArr = new byte[i9][];
        int[] iArr = new int[i9 * 2];
        C c8 = this.f18764q;
        int i12 = 0;
        while (i5 < i) {
            P6.g.b(c8);
            bArr[i12] = c8.f18727a;
            i5 += c8.f18729c - c8.f18728b;
            iArr[i12] = Math.min(i5, i);
            iArr[i12 + i9] = c8.f18728b;
            c8.f18730d = true;
            i12++;
            c8 = c8.f18732f;
        }
        return new E(bArr, iArr);
    }

    public final C q0(int i) {
        if (i < 1 || i > 8192) {
            throw new IllegalArgumentException("unexpected capacity");
        }
        C c3 = this.f18764q;
        if (c3 == null) {
            C cB = D.b();
            this.f18764q = cB;
            cB.f18733g = cB;
            cB.f18732f = cB;
            return cB;
        }
        C c8 = c3.f18733g;
        P6.g.b(c8);
        if (c8.f18729c + i <= 8192 && c8.f18731e) {
            return c8;
        }
        C cB2 = D.b();
        c8.b(cB2);
        return cB2;
    }

    public final void r(C1731g c1731g, long j8, long j9) {
        P6.g.e(c1731g, "out");
        long j10 = j8;
        s7.d.g(this.f18765r, j10, j9);
        if (j9 == 0) {
            return;
        }
        c1731g.f18765r += j9;
        C c3 = this.f18764q;
        while (true) {
            P6.g.b(c3);
            long j11 = c3.f18729c - c3.f18728b;
            if (j10 < j11) {
                break;
            }
            j10 -= j11;
            c3 = c3.f18732f;
        }
        C c8 = c3;
        long j12 = j9;
        while (j12 > 0) {
            P6.g.b(c8);
            C c9 = c8.c();
            int i = c9.f18728b + ((int) j10);
            c9.f18728b = i;
            c9.f18729c = Math.min(i + ((int) j12), c9.f18729c);
            C c10 = c1731g.f18764q;
            if (c10 == null) {
                c9.f18733g = c9;
                c9.f18732f = c9;
                c1731g.f18764q = c9;
            } else {
                C c11 = c10.f18733g;
                P6.g.b(c11);
                c11.b(c9);
            }
            j12 -= (long) (c9.f18729c - c9.f18728b);
            c8 = c8.f18732f;
            j10 = 0;
        }
    }

    public final void r0(C1734j c1734j) {
        P6.g.e(c1734j, "byteString");
        c1734j.q(this, c1734j.c());
    }

    @Override // java.nio.channels.ReadableByteChannel
    public final int read(ByteBuffer byteBuffer) {
        P6.g.e(byteBuffer, "sink");
        C c3 = this.f18764q;
        if (c3 == null) {
            return -1;
        }
        int iMin = Math.min(byteBuffer.remaining(), c3.f18729c - c3.f18728b);
        byteBuffer.put(c3.f18727a, c3.f18728b, iMin);
        int i = c3.f18728b + iMin;
        c3.f18728b = i;
        this.f18765r -= (long) iMin;
        if (i == c3.f18729c) {
            this.f18764q = c3.a();
            D.a(c3);
        }
        return iMin;
    }

    public final void s0(byte[] bArr, int i, int i5) {
        P6.g.e(bArr, "source");
        long j8 = i5;
        s7.d.g(bArr.length, i, j8);
        int i8 = i5 + i;
        while (i < i8) {
            C cQ0 = q0(1);
            int iMin = Math.min(i8 - i, 8192 - cQ0.f18729c);
            int i9 = i + iMin;
            B6.j.F(cQ0.f18729c, i, i9, bArr, cQ0.f18727a);
            cQ0.f18729c += iMin;
            i = i9;
        }
        this.f18765r += j8;
    }

    @Override // x7.InterfaceC1733i
    public final int t(w wVar) throws EOFException {
        P6.g.e(wVar, "options");
        int iC = y7.a.c(this, wVar, false);
        if (iC == -1) {
            return -1;
        }
        y(wVar.f18795q[iC].c());
        return iC;
    }

    public final void t0(H h8) {
        P6.g.e(h8, "source");
        while (h8.M(this, 8192L) != -1) {
        }
    }

    public final String toString() {
        long j8 = this.f18765r;
        if (j8 <= 2147483647L) {
            return p0((int) j8).toString();
        }
        throw new IllegalStateException(("size > Int.MAX_VALUE: " + this.f18765r).toString());
    }

    public final boolean u() {
        return this.f18765r == 0;
    }

    public final void u0(int i) {
        C cQ0 = q0(1);
        int i5 = cQ0.f18729c;
        cQ0.f18729c = i5 + 1;
        cQ0.f18727a[i5] = (byte) i;
        this.f18765r++;
    }

    public final void v0(long j8) {
        boolean z8;
        byte[] bArr;
        if (j8 == 0) {
            u0(48);
            return;
        }
        int i = 1;
        if (j8 < 0) {
            j8 = -j8;
            if (j8 < 0) {
                z0("-9223372036854775808");
                return;
            }
            z8 = true;
        } else {
            z8 = false;
        }
        if (j8 >= 100000000) {
            i = j8 < 1000000000000L ? j8 < 10000000000L ? j8 < 1000000000 ? 9 : 10 : j8 < 100000000000L ? 11 : 12 : j8 < 1000000000000000L ? j8 < 10000000000000L ? 13 : j8 < 100000000000000L ? 14 : 15 : j8 < 100000000000000000L ? j8 < 10000000000000000L ? 16 : 17 : j8 < 1000000000000000000L ? 18 : 19;
        } else if (j8 >= 10000) {
            i = j8 < 1000000 ? j8 < 100000 ? 5 : 6 : j8 < 10000000 ? 7 : 8;
        } else if (j8 >= 100) {
            i = j8 < 1000 ? 3 : 4;
        } else if (j8 >= 10) {
            i = 2;
        }
        if (z8) {
            i++;
        }
        C cQ0 = q0(i);
        int i5 = cQ0.f18729c + i;
        while (true) {
            bArr = cQ0.f18727a;
            if (j8 == 0) {
                break;
            }
            long j9 = 10;
            i5--;
            bArr[i5] = y7.a.f19039a[(int) (j8 % j9)];
            j8 /= j9;
        }
        if (z8) {
            bArr[i5 - 1] = 45;
        }
        cQ0.f18729c += i;
        this.f18765r += (long) i;
    }

    public final void w0(long j8) {
        if (j8 == 0) {
            u0(48);
            return;
        }
        long j9 = (j8 >>> 1) | j8;
        long j10 = j9 | (j9 >>> 2);
        long j11 = j10 | (j10 >>> 4);
        long j12 = j11 | (j11 >>> 8);
        long j13 = j12 | (j12 >>> 16);
        long j14 = j13 | (j13 >>> 32);
        long j15 = j14 - ((j14 >>> 1) & 6148914691236517205L);
        long j16 = ((j15 >>> 2) & 3689348814741910323L) + (j15 & 3689348814741910323L);
        long j17 = ((j16 >>> 4) + j16) & 1085102592571150095L;
        long j18 = j17 + (j17 >>> 8);
        long j19 = j18 + (j18 >>> 16);
        int i = (int) ((((j19 & 63) + ((j19 >>> 32) & 63)) + ((long) 3)) / ((long) 4));
        C cQ0 = q0(i);
        int i5 = cQ0.f18729c;
        for (int i8 = (i5 + i) - 1; i8 >= i5; i8--) {
            cQ0.f18727a[i8] = y7.a.f19039a[(int) (15 & j8)];
            j8 >>>= 4;
        }
        cQ0.f18729c += i;
        this.f18765r += (long) i;
    }

    @Override // java.nio.channels.WritableByteChannel
    public final int write(ByteBuffer byteBuffer) {
        P6.g.e(byteBuffer, "source");
        int iRemaining = byteBuffer.remaining();
        int i = iRemaining;
        while (i > 0) {
            C cQ0 = q0(1);
            int iMin = Math.min(i, 8192 - cQ0.f18729c);
            byteBuffer.get(cQ0.f18727a, cQ0.f18729c, iMin);
            i -= iMin;
            cQ0.f18729c += iMin;
        }
        this.f18765r += (long) iRemaining;
        return iRemaining;
    }

    @Override // x7.InterfaceC1732h
    public final /* bridge */ /* synthetic */ InterfaceC1732h x(C1734j c1734j) {
        r0(c1734j);
        return this;
    }

    public final void x0(int i) {
        C cQ0 = q0(4);
        int i5 = cQ0.f18729c;
        byte[] bArr = cQ0.f18727a;
        bArr[i5] = (byte) ((i >>> 24) & 255);
        bArr[i5 + 1] = (byte) ((i >>> 16) & 255);
        bArr[i5 + 2] = (byte) ((i >>> 8) & 255);
        bArr[i5 + 3] = (byte) (i & 255);
        cQ0.f18729c = i5 + 4;
        this.f18765r += 4;
    }

    @Override // x7.InterfaceC1733i
    public final void y(long j8) throws EOFException {
        while (j8 > 0) {
            C c3 = this.f18764q;
            if (c3 == null) {
                throw new EOFException();
            }
            int iMin = (int) Math.min(j8, c3.f18729c - c3.f18728b);
            long j9 = iMin;
            this.f18765r -= j9;
            j8 -= j9;
            int i = c3.f18728b + iMin;
            c3.f18728b = i;
            if (i == c3.f18729c) {
                this.f18764q = c3.a();
                D.a(c3);
            }
        }
    }

    public final void y0(int i, int i5, String str) {
        char cCharAt;
        P6.g.e(str, "string");
        if (i < 0) {
            throw new IllegalArgumentException(AbstractC0844a.j("beginIndex < 0: ", i).toString());
        }
        if (i5 < i) {
            throw new IllegalArgumentException(I1.a.o("endIndex < beginIndex: ", i5, i, " < ").toString());
        }
        if (i5 > str.length()) {
            StringBuilder sbO = AbstractC0844a.o(i5, "endIndex > string.length: ", " > ");
            sbO.append(str.length());
            throw new IllegalArgumentException(sbO.toString().toString());
        }
        while (i < i5) {
            char cCharAt2 = str.charAt(i);
            if (cCharAt2 < 128) {
                C cQ0 = q0(1);
                int i8 = cQ0.f18729c - i;
                int iMin = Math.min(i5, 8192 - i8);
                int i9 = i + 1;
                byte[] bArr = cQ0.f18727a;
                bArr[i + i8] = (byte) cCharAt2;
                while (true) {
                    i = i9;
                    if (i >= iMin || (cCharAt = str.charAt(i)) >= 128) {
                        break;
                    }
                    i9 = i + 1;
                    bArr[i + i8] = (byte) cCharAt;
                }
                int i10 = cQ0.f18729c;
                int i11 = (i8 + i) - i10;
                cQ0.f18729c = i10 + i11;
                this.f18765r += (long) i11;
            } else {
                if (cCharAt2 < 2048) {
                    C cQ02 = q0(2);
                    int i12 = cQ02.f18729c;
                    byte[] bArr2 = cQ02.f18727a;
                    bArr2[i12] = (byte) ((cCharAt2 >> 6) | 192);
                    bArr2[i12 + 1] = (byte) ((cCharAt2 & '?') | 128);
                    cQ02.f18729c = i12 + 2;
                    this.f18765r += 2;
                } else if (cCharAt2 < 55296 || cCharAt2 > 57343) {
                    C cQ03 = q0(3);
                    int i13 = cQ03.f18729c;
                    byte[] bArr3 = cQ03.f18727a;
                    bArr3[i13] = (byte) ((cCharAt2 >> '\f') | 224);
                    bArr3[i13 + 1] = (byte) ((63 & (cCharAt2 >> 6)) | 128);
                    bArr3[i13 + 2] = (byte) ((cCharAt2 & '?') | 128);
                    cQ03.f18729c = i13 + 3;
                    this.f18765r += 3;
                } else {
                    int i14 = i + 1;
                    char cCharAt3 = i14 < i5 ? str.charAt(i14) : (char) 0;
                    if (cCharAt2 > 56319 || 56320 > cCharAt3 || cCharAt3 >= 57344) {
                        u0(63);
                        i = i14;
                    } else {
                        int i15 = (((cCharAt2 & 1023) << 10) | (cCharAt3 & 1023)) + 65536;
                        C cQ04 = q0(4);
                        int i16 = cQ04.f18729c;
                        byte[] bArr4 = cQ04.f18727a;
                        bArr4[i16] = (byte) ((i15 >> 18) | 240);
                        bArr4[i16 + 1] = (byte) (((i15 >> 12) & 63) | 128);
                        bArr4[i16 + 2] = (byte) (((i15 >> 6) & 63) | 128);
                        bArr4[i16 + 3] = (byte) ((i15 & 63) | 128);
                        cQ04.f18729c = i16 + 4;
                        this.f18765r += 4;
                        i += 2;
                    }
                }
                i++;
            }
        }
    }

    public final void z0(String str) {
        P6.g.e(str, "string");
        y0(0, str.length(), str);
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.Channel, x7.F
    public final void close() {
    }

    @Override // x7.InterfaceC1733i
    public final C1731g d() {
        return this;
    }

    @Override // x7.F, java.io.Flushable
    public final void flush() {
    }
}
