package h;

import com.seewo.libmcuservice.constant.IMcuConstants;
import com.seewo.libmcuservice.constant.ITVStateConstants;
import com.seewo.vcommons.constants.SeewoBoardKeys;
import com.seewo.vcommons.mstar.MKeyEvent;
import java.io.EOFException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.ByteChannel;
import java.nio.charset.Charset;
import java.util.Objects;
import javax.annotation.Nullable;

/* JADX INFO: loaded from: classes.dex */
public final class f implements h, g, Cloneable, ByteChannel {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final byte[] f6541b = {SeewoBoardKeys.TOUCH_KEY_BOARD_RIGHT_SQUARE_BRACKET, SeewoBoardKeys.TOUCH_KEY_BOARD_RIGHT_SLASH, 50, SeewoBoardKeys.TOUCH_KEY_BOARD_SEMICOLON, SeewoBoardKeys.TOUCH_KEY_BOARD_SINGLE_QUOTE_MARK, SeewoBoardKeys.TOUCH_KEY_BOARD_GRAVE_ACCENT, SeewoBoardKeys.TOUCH_KEY_BOARD_COMMA, 55, SeewoBoardKeys.TOUCH_KEY_BOARD_LEFT_SLASH, SeewoBoardKeys.TOUCH_KEY_BOARD_CAPS_LOCK, 97, 98, 99, 100, 101, 102};

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    @Nullable
    public t f6542c;

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

    public class a extends InputStream {
        public a() {
        }

        @Override // java.io.InputStream
        public int available() {
            return (int) Math.min(f.this.f6543d, 2147483647L);
        }

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

        @Override // java.io.InputStream
        public int read() {
            f fVar = f.this;
            if (fVar.f6543d > 0) {
                return fVar.J() & IMcuConstants.DEFAULT_VALUE;
            }
            return -1;
        }

        @Override // java.io.InputStream
        public int read(byte[] bArr, int i2, int i3) {
            return f.this.P(bArr, i2, i3);
        }

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

    @Override // h.h
    public void A(long j2) throws EOFException {
        if (this.f6543d < j2) {
            throw new EOFException();
        }
    }

    @Override // h.g
    public /* bridge */ /* synthetic */ g C(String str) {
        e0(str);
        return this;
    }

    @Override // h.h
    public long F(byte b2) {
        return O(b2, 0L, Long.MAX_VALUE);
    }

    @Override // h.h
    public boolean G(long j2, i iVar) {
        int iK = iVar.k();
        if (j2 < 0 || iK < 0 || this.f6543d - j2 < iK || iVar.k() - 0 < iK) {
            return false;
        }
        for (int i2 = 0; i2 < iK; i2++) {
            if (N(((long) i2) + j2) != iVar.f(0 + i2)) {
                return false;
            }
        }
        return true;
    }

    /* JADX WARN: Removed duplicated region for block: B:33:0x0089  */
    /* JADX WARN: Removed duplicated region for block: B:34:0x0093  */
    /* JADX WARN: Removed duplicated region for block: B:36:0x0097  */
    /* JADX WARN: Removed duplicated region for block: B:44:0x009b A[EDGE_INSN: B:44:0x009b->B:38:0x009b BREAK  A[LOOP:0: B:5:0x000b->B:46:?], SYNTHETIC] */
    @Override // h.h
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public long H() {
        /*
            r14 = this;
            long r0 = r14.f6543d
            r2 = 0
            int r0 = (r0 > r2 ? 1 : (r0 == r2 ? 0 : -1))
            if (r0 == 0) goto La2
            r0 = 0
            r1 = r0
            r4 = r2
        Lb:
            h.t r6 = r14.f6542c
            byte[] r7 = r6.f6574a
            int r8 = r6.f6575b
            int r9 = r6.f6576c
        L13:
            if (r8 >= r9) goto L87
            r10 = r7[r8]
            r11 = 48
            if (r10 < r11) goto L22
            r11 = 57
            if (r10 > r11) goto L22
            int r11 = r10 + (-48)
            goto L39
        L22:
            r11 = 97
            if (r10 < r11) goto L2d
            r11 = 102(0x66, float:1.43E-43)
            if (r10 > r11) goto L2d
            int r11 = r10 + (-97)
            goto L37
        L2d:
            r11 = 65
            if (r10 < r11) goto L6c
            r11 = 70
            if (r10 > r11) goto L6c
            int r11 = r10 + (-65)
        L37:
            int r11 = r11 + 10
        L39:
            r12 = -1152921504606846976(0xf000000000000000, double:-3.105036184601418E231)
            long r12 = r12 & r4
            int r12 = (r12 > r2 ? 1 : (r12 == r2 ? 0 : -1))
            if (r12 != 0) goto L49
            r10 = 4
            long r4 = r4 << r10
            long r10 = (long) r11
            long r4 = r4 | r10
            int r8 = r8 + 1
            int r0 = r0 + 1
            goto L13
        L49:
            h.f r0 = new h.f
            r0.<init>()
            h.f r0 = r0.j(r4)
            r0.Z(r10)
            java.lang.NumberFormatException r1 = new java.lang.NumberFormatException
            java.lang.String r2 = "Number too large: "
            java.lang.StringBuilder r2 = a.b.c.a.a.C(r2)
            java.lang.String r0 = r0.T()
            r2.append(r0)
            java.lang.String r0 = r2.toString()
            r1.<init>(r0)
            throw r1
        L6c:
            if (r0 == 0) goto L70
            r1 = 1
            goto L87
        L70:
            java.lang.NumberFormatException r0 = new java.lang.NumberFormatException
            java.lang.String r1 = "Expected leading [0-9a-fA-F] character but was 0x"
            java.lang.StringBuilder r1 = a.b.c.a.a.C(r1)
            java.lang.String r2 = java.lang.Integer.toHexString(r10)
            r1.append(r2)
            java.lang.String r1 = r1.toString()
            r0.<init>(r1)
            throw r0
        L87:
            if (r8 != r9) goto L93
            h.t r7 = r6.a()
            r14.f6542c = r7
            h.u.a(r6)
            goto L95
        L93:
            r6.f6575b = r8
        L95:
            if (r1 != 0) goto L9b
            h.t r6 = r14.f6542c
            if (r6 != 0) goto Lb
        L9b:
            long r1 = r14.f6543d
            long r6 = (long) r0
            long r1 = r1 - r6
            r14.f6543d = r1
            return r4
        La2:
            java.lang.IllegalStateException r0 = new java.lang.IllegalStateException
            java.lang.String r1 = "size == 0"
            r0.<init>(r1)
            throw r0
        */
        throw new UnsupportedOperationException("Method not decompiled: h.f.H():long");
    }

    @Override // h.h
    public InputStream I() {
        return new a();
    }

    @Override // h.h
    public byte J() {
        long j2 = this.f6543d;
        if (j2 == 0) {
            throw new IllegalStateException("size == 0");
        }
        t tVar = this.f6542c;
        int i2 = tVar.f6575b;
        int i3 = tVar.f6576c;
        int i4 = i2 + 1;
        byte b2 = tVar.f6574a[i2];
        this.f6543d = j2 - 1;
        if (i4 == i3) {
            this.f6542c = tVar.a();
            u.a(tVar);
        } else {
            tVar.f6575b = i4;
        }
        return b2;
    }

    public final void K() {
        try {
            l(this.f6543d);
        } catch (EOFException e2) {
            throw new AssertionError(e2);
        }
    }

    public final long L() {
        long j2 = this.f6543d;
        if (j2 == 0) {
            return 0L;
        }
        t tVar = this.f6542c.f6580g;
        int i2 = tVar.f6576c;
        return (i2 >= 8192 || !tVar.f6578e) ? j2 : j2 - ((long) (i2 - tVar.f6575b));
    }

    public final f M(f fVar, long j2, long j3) {
        if (fVar == null) {
            throw new IllegalArgumentException("out == null");
        }
        z.b(this.f6543d, j2, j3);
        if (j3 == 0) {
            return this;
        }
        fVar.f6543d += j3;
        t tVar = this.f6542c;
        while (true) {
            int i2 = tVar.f6576c;
            int i3 = tVar.f6575b;
            if (j2 < i2 - i3) {
                break;
            }
            j2 -= (long) (i2 - i3);
            tVar = tVar.f6579f;
        }
        while (j3 > 0) {
            t tVarC = tVar.c();
            int i4 = (int) (((long) tVarC.f6575b) + j2);
            tVarC.f6575b = i4;
            tVarC.f6576c = Math.min(i4 + ((int) j3), tVarC.f6576c);
            t tVar2 = fVar.f6542c;
            if (tVar2 == null) {
                tVarC.f6580g = tVarC;
                tVarC.f6579f = tVarC;
                fVar.f6542c = tVarC;
            } else {
                tVar2.f6580g.b(tVarC);
            }
            j3 -= (long) (tVarC.f6576c - tVarC.f6575b);
            tVar = tVar.f6579f;
            j2 = 0;
        }
        return this;
    }

    public final byte N(long j2) {
        int i2;
        z.b(this.f6543d, j2, 1L);
        long j3 = this.f6543d;
        if (j3 - j2 <= j2) {
            long j4 = j2 - j3;
            t tVar = this.f6542c;
            do {
                tVar = tVar.f6580g;
                int i3 = tVar.f6576c;
                i2 = tVar.f6575b;
                j4 += (long) (i3 - i2);
            } while (j4 < 0);
            return tVar.f6574a[i2 + ((int) j4)];
        }
        t tVar2 = this.f6542c;
        while (true) {
            int i4 = tVar2.f6576c;
            int i5 = tVar2.f6575b;
            long j5 = i4 - i5;
            if (j2 < j5) {
                return tVar2.f6574a[i5 + ((int) j2)];
            }
            j2 -= j5;
            tVar2 = tVar2.f6579f;
        }
    }

    public long O(byte b2, long j2, long j3) {
        t tVar;
        long j4 = 0;
        if (j2 < 0 || j3 < j2) {
            throw new IllegalArgumentException(String.format("size=%s fromIndex=%s toIndex=%s", Long.valueOf(this.f6543d), Long.valueOf(j2), Long.valueOf(j3)));
        }
        long j5 = this.f6543d;
        long j6 = j3 > j5 ? j5 : j3;
        if (j2 == j6 || (tVar = this.f6542c) == null) {
            return -1L;
        }
        if (j5 - j2 < j2) {
            while (j5 > j2) {
                tVar = tVar.f6580g;
                j5 -= (long) (tVar.f6576c - tVar.f6575b);
            }
        } else {
            while (true) {
                long j7 = ((long) (tVar.f6576c - tVar.f6575b)) + j4;
                if (j7 >= j2) {
                    break;
                }
                tVar = tVar.f6579f;
                j4 = j7;
            }
            j5 = j4;
        }
        long j8 = j2;
        while (j5 < j6) {
            byte[] bArr = tVar.f6574a;
            int iMin = (int) Math.min(tVar.f6576c, (((long) tVar.f6575b) + j6) - j5);
            for (int i2 = (int) ((((long) tVar.f6575b) + j8) - j5); i2 < iMin; i2++) {
                if (bArr[i2] == b2) {
                    return ((long) (i2 - tVar.f6575b)) + j5;
                }
            }
            j5 += (long) (tVar.f6576c - tVar.f6575b);
            tVar = tVar.f6579f;
            j8 = j5;
        }
        return -1L;
    }

    public int P(byte[] bArr, int i2, int i3) {
        z.b(bArr.length, i2, i3);
        t tVar = this.f6542c;
        if (tVar == null) {
            return -1;
        }
        int iMin = Math.min(i3, tVar.f6576c - tVar.f6575b);
        System.arraycopy(tVar.f6574a, tVar.f6575b, bArr, i2, iMin);
        int i4 = tVar.f6575b + iMin;
        tVar.f6575b = i4;
        this.f6543d -= (long) iMin;
        if (i4 == tVar.f6576c) {
            this.f6542c = tVar.a();
            u.a(tVar);
        }
        return iMin;
    }

    public i Q() {
        try {
            return new i(s(this.f6543d));
        } catch (EOFException e2) {
            throw new AssertionError(e2);
        }
    }

    public void R(byte[] bArr) throws EOFException {
        int i2 = 0;
        while (i2 < bArr.length) {
            int iP = P(bArr, i2, bArr.length - i2);
            if (iP == -1) {
                throw new EOFException();
            }
            i2 += iP;
        }
    }

    public String S(long j2, Charset charset) {
        z.b(this.f6543d, 0L, j2);
        if (charset == null) {
            throw new IllegalArgumentException("charset == null");
        }
        if (j2 > 2147483647L) {
            throw new IllegalArgumentException("byteCount > Integer.MAX_VALUE: " + j2);
        }
        if (j2 == 0) {
            return "";
        }
        t tVar = this.f6542c;
        if (((long) tVar.f6575b) + j2 > tVar.f6576c) {
            return new String(s(j2), charset);
        }
        String str = new String(tVar.f6574a, tVar.f6575b, (int) j2, charset);
        int i2 = (int) (((long) tVar.f6575b) + j2);
        tVar.f6575b = i2;
        this.f6543d -= j2;
        if (i2 == tVar.f6576c) {
            this.f6542c = tVar.a();
            u.a(tVar);
        }
        return str;
    }

    public String T() {
        try {
            return S(this.f6543d, z.f6589a);
        } catch (EOFException e2) {
            throw new AssertionError(e2);
        }
    }

    public String U(long j2) throws EOFException {
        if (j2 > 0) {
            long j3 = j2 - 1;
            if (N(j3) == 13) {
                String strS = S(j3, z.f6589a);
                l(2L);
                return strS;
            }
        }
        String strS2 = S(j2, z.f6589a);
        l(1L);
        return strS2;
    }

    public t V(int i2) {
        if (i2 < 1 || i2 > 8192) {
            throw new IllegalArgumentException();
        }
        t tVar = this.f6542c;
        if (tVar == null) {
            t tVarB = u.b();
            this.f6542c = tVarB;
            tVarB.f6580g = tVarB;
            tVarB.f6579f = tVarB;
            return tVarB;
        }
        t tVar2 = tVar.f6580g;
        if (tVar2.f6576c + i2 <= 8192 && tVar2.f6578e) {
            return tVar2;
        }
        t tVarB2 = u.b();
        tVar2.b(tVarB2);
        return tVarB2;
    }

    public f W(i iVar) {
        if (iVar == null) {
            throw new IllegalArgumentException("byteString == null");
        }
        iVar.p(this);
        return this;
    }

    public f X(byte[] bArr) {
        if (bArr == null) {
            throw new IllegalArgumentException("source == null");
        }
        Y(bArr, 0, bArr.length);
        return this;
    }

    public f Y(byte[] bArr, int i2, int i3) {
        if (bArr == null) {
            throw new IllegalArgumentException("source == null");
        }
        long j2 = i3;
        z.b(bArr.length, i2, j2);
        int i4 = i3 + i2;
        while (i2 < i4) {
            t tVarV = V(1);
            int iMin = Math.min(i4 - i2, 8192 - tVarV.f6576c);
            System.arraycopy(bArr, i2, tVarV.f6574a, tVarV.f6576c, iMin);
            i2 += iMin;
            tVarV.f6576c += iMin;
        }
        this.f6543d += j2;
        return this;
    }

    public f Z(int i2) {
        t tVarV = V(1);
        byte[] bArr = tVarV.f6574a;
        int i3 = tVarV.f6576c;
        tVarV.f6576c = i3 + 1;
        bArr[i3] = (byte) i2;
        this.f6543d++;
        return this;
    }

    @Override // h.g
    /* JADX INFO: renamed from: a0, reason: merged with bridge method [inline-methods] */
    public f D(long j2) {
        if (j2 == 0) {
            Z(48);
            return this;
        }
        boolean z = false;
        int i2 = 1;
        if (j2 < 0) {
            j2 = -j2;
            if (j2 < 0) {
                e0("-9223372036854775808");
                return this;
            }
            z = true;
        }
        if (j2 >= 100000000) {
            i2 = j2 < 1000000000000L ? j2 < 10000000000L ? j2 < 1000000000 ? 9 : 10 : j2 < 100000000000L ? 11 : 12 : j2 < 1000000000000000L ? j2 < 10000000000000L ? 13 : j2 < 100000000000000L ? 14 : 15 : j2 < 100000000000000000L ? j2 < 10000000000000000L ? 16 : 17 : j2 < 1000000000000000000L ? 18 : 19;
        } else if (j2 >= 10000) {
            i2 = j2 < 1000000 ? j2 < 100000 ? 5 : 6 : j2 < 10000000 ? 7 : 8;
        } else if (j2 >= 100) {
            i2 = j2 < 1000 ? 3 : 4;
        } else if (j2 >= 10) {
            i2 = 2;
        }
        if (z) {
            i2++;
        }
        t tVarV = V(i2);
        byte[] bArr = tVarV.f6574a;
        int i3 = tVarV.f6576c + i2;
        while (j2 != 0) {
            i3--;
            bArr[i3] = f6541b[(int) (j2 % 10)];
            j2 /= 10;
        }
        if (z) {
            bArr[i3 - 1] = SeewoBoardKeys.TOUCH_KEY_BOARD_MINUS;
        }
        tVarV.f6576c += i2;
        this.f6543d += (long) i2;
        return this;
    }

    @Override // h.h, h.g
    public f b() {
        return this;
    }

    @Override // h.g
    /* JADX INFO: renamed from: b0, reason: merged with bridge method [inline-methods] */
    public f j(long j2) {
        if (j2 == 0) {
            Z(48);
            return this;
        }
        int iNumberOfTrailingZeros = (Long.numberOfTrailingZeros(Long.highestOneBit(j2)) / 4) + 1;
        t tVarV = V(iNumberOfTrailingZeros);
        byte[] bArr = tVarV.f6574a;
        int i2 = tVarV.f6576c;
        for (int i3 = (i2 + iNumberOfTrailingZeros) - 1; i3 >= i2; i3--) {
            bArr[i3] = f6541b[(int) (15 & j2)];
            j2 >>>= 4;
        }
        tVarV.f6576c += iNumberOfTrailingZeros;
        this.f6543d += (long) iNumberOfTrailingZeros;
        return this;
    }

    @Override // h.h
    public int c() {
        long j2 = this.f6543d;
        if (j2 < 4) {
            StringBuilder sbC = a.b.c.a.a.C("size < 4: ");
            sbC.append(this.f6543d);
            throw new IllegalStateException(sbC.toString());
        }
        t tVar = this.f6542c;
        int i2 = tVar.f6575b;
        int i3 = tVar.f6576c;
        if (i3 - i2 < 4) {
            return ((J() & IMcuConstants.DEFAULT_VALUE) << 24) | ((J() & IMcuConstants.DEFAULT_VALUE) << 16) | ((J() & IMcuConstants.DEFAULT_VALUE) << 8) | (J() & IMcuConstants.DEFAULT_VALUE);
        }
        byte[] bArr = tVar.f6574a;
        int i4 = i2 + 1;
        int i5 = i4 + 1;
        int i6 = ((bArr[i2] & IMcuConstants.DEFAULT_VALUE) << 24) | ((bArr[i4] & IMcuConstants.DEFAULT_VALUE) << 16);
        int i7 = i5 + 1;
        int i8 = i6 | ((bArr[i5] & IMcuConstants.DEFAULT_VALUE) << 8);
        int i9 = i7 + 1;
        int i10 = i8 | (bArr[i7] & IMcuConstants.DEFAULT_VALUE);
        this.f6543d = j2 - 4;
        if (i9 == i3) {
            this.f6542c = tVar.a();
            u.a(tVar);
        } else {
            tVar.f6575b = i9;
        }
        return i10;
    }

    public f c0(int i2) {
        t tVarV = V(4);
        byte[] bArr = tVarV.f6574a;
        int i3 = tVarV.f6576c;
        int i4 = i3 + 1;
        bArr[i3] = (byte) ((i2 >>> 24) & MKeyEvent.KEYCODE_SLEEP);
        int i5 = i4 + 1;
        bArr[i4] = (byte) ((i2 >>> 16) & MKeyEvent.KEYCODE_SLEEP);
        int i6 = i5 + 1;
        bArr[i5] = (byte) ((i2 >>> 8) & MKeyEvent.KEYCODE_SLEEP);
        bArr[i6] = (byte) (i2 & MKeyEvent.KEYCODE_SLEEP);
        tVarV.f6576c = i6 + 1;
        this.f6543d += 4;
        return this;
    }

    public Object clone() {
        f fVar = new f();
        if (this.f6543d != 0) {
            t tVarC = this.f6542c.c();
            fVar.f6542c = tVarC;
            tVarC.f6580g = tVarC;
            tVarC.f6579f = tVarC;
            t tVar = this.f6542c;
            while (true) {
                tVar = tVar.f6579f;
                if (tVar == this.f6542c) {
                    break;
                }
                fVar.f6542c.f6580g.b(tVar.c());
            }
            fVar.f6543d = this.f6543d;
        }
        return fVar;
    }

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

    @Override // h.g
    public /* bridge */ /* synthetic */ g d(int i2) {
        c0(i2);
        return this;
    }

    public f d0(int i2) {
        t tVarV = V(2);
        byte[] bArr = tVarV.f6574a;
        int i3 = tVarV.f6576c;
        int i4 = i3 + 1;
        bArr[i3] = (byte) ((i2 >>> 8) & MKeyEvent.KEYCODE_SLEEP);
        bArr[i4] = (byte) (i2 & MKeyEvent.KEYCODE_SLEEP);
        tVarV.f6576c = i4 + 1;
        this.f6543d += 2;
        return this;
    }

    @Override // h.x
    public y e() {
        return y.f6585a;
    }

    public f e0(String str) {
        f0(str, 0, str.length());
        return this;
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof f)) {
            return false;
        }
        f fVar = (f) obj;
        long j2 = this.f6543d;
        if (j2 != fVar.f6543d) {
            return false;
        }
        long j3 = 0;
        if (j2 == 0) {
            return true;
        }
        t tVar = this.f6542c;
        t tVar2 = fVar.f6542c;
        int i2 = tVar.f6575b;
        int i3 = tVar2.f6575b;
        while (j3 < this.f6543d) {
            long jMin = Math.min(tVar.f6576c - i2, tVar2.f6576c - i3);
            int i4 = 0;
            while (i4 < jMin) {
                int i5 = i2 + 1;
                int i6 = i3 + 1;
                if (tVar.f6574a[i2] != tVar2.f6574a[i3]) {
                    return false;
                }
                i4++;
                i2 = i5;
                i3 = i6;
            }
            if (i2 == tVar.f6576c) {
                tVar = tVar.f6579f;
                i2 = tVar.f6575b;
            }
            if (i3 == tVar2.f6576c) {
                tVar2 = tVar2.f6579f;
                i3 = tVar2.f6575b;
            }
            j3 += jMin;
        }
        return true;
    }

    @Override // h.g
    public /* bridge */ /* synthetic */ g f(byte[] bArr) {
        X(bArr);
        return this;
    }

    public f f0(String str, int i2, int i3) {
        char cCharAt;
        int i4;
        if (i2 < 0) {
            throw new IllegalArgumentException(a.b.c.a.a.o("beginIndex < 0: ", i2));
        }
        if (i3 < i2) {
            throw new IllegalArgumentException("endIndex < beginIndex: " + i3 + " < " + i2);
        }
        if (i3 > str.length()) {
            StringBuilder sbD = a.b.c.a.a.D("endIndex > string.length: ", i3, " > ");
            sbD.append(str.length());
            throw new IllegalArgumentException(sbD.toString());
        }
        while (i2 < i3) {
            char cCharAt2 = str.charAt(i2);
            if (cCharAt2 < 128) {
                t tVarV = V(1);
                byte[] bArr = tVarV.f6574a;
                int i5 = tVarV.f6576c - i2;
                int iMin = Math.min(i3, 8192 - i5);
                int i6 = i2 + 1;
                bArr[i2 + i5] = (byte) cCharAt2;
                while (true) {
                    i2 = i6;
                    if (i2 >= iMin || (cCharAt = str.charAt(i2)) >= 128) {
                        break;
                    }
                    i6 = i2 + 1;
                    bArr[i2 + i5] = (byte) cCharAt;
                }
                int i7 = tVarV.f6576c;
                int i8 = (i5 + i2) - i7;
                tVarV.f6576c = i7 + i8;
                this.f6543d += (long) i8;
            } else {
                if (cCharAt2 < 2048) {
                    i4 = (cCharAt2 >> 6) | ITVStateConstants.ACTION_OUT_SETTING_AUTO_UPDATES;
                } else if (cCharAt2 < 55296 || cCharAt2 > 57343) {
                    Z((cCharAt2 >> '\f') | 224);
                    i4 = ((cCharAt2 >> 6) & 63) | 128;
                } else {
                    int i9 = i2 + 1;
                    char cCharAt3 = i9 < i3 ? str.charAt(i9) : (char) 0;
                    if (cCharAt2 > 56319 || cCharAt3 < 56320 || cCharAt3 > 57343) {
                        Z(63);
                        i2 = i9;
                    } else {
                        int i10 = (((cCharAt2 & 10239) << 10) | (9215 & cCharAt3)) + 65536;
                        Z((i10 >> 18) | 240);
                        Z(((i10 >> 12) & 63) | 128);
                        Z(((i10 >> 6) & 63) | 128);
                        Z((i10 & 63) | 128);
                        i2 += 2;
                    }
                }
                Z(i4);
                Z((cCharAt2 & '?') | 128);
                i2++;
            }
        }
        return this;
    }

    @Override // h.g, h.w, java.io.Flushable
    public void flush() {
    }

    @Override // h.g
    public /* bridge */ /* synthetic */ g g(byte[] bArr, int i2, int i3) {
        Y(bArr, i2, i3);
        return this;
    }

    public f g0(int i2) {
        int i3;
        int i4;
        if (i2 >= 128) {
            if (i2 < 2048) {
                i4 = (i2 >> 6) | ITVStateConstants.ACTION_OUT_SETTING_AUTO_UPDATES;
            } else {
                if (i2 < 65536) {
                    if (i2 < 55296 || i2 > 57343) {
                        i3 = (i2 >> 12) | 224;
                    } else {
                        Z(63);
                    }
                } else {
                    if (i2 > 1114111) {
                        StringBuilder sbC = a.b.c.a.a.C("Unexpected code point: ");
                        sbC.append(Integer.toHexString(i2));
                        throw new IllegalArgumentException(sbC.toString());
                    }
                    Z((i2 >> 18) | 240);
                    i3 = ((i2 >> 12) & 63) | 128;
                }
                Z(i3);
                i4 = ((i2 >> 6) & 63) | 128;
            }
            Z(i4);
            i2 = (i2 & 63) | 128;
            Z(i2);
        } else {
            Z(i2);
        }
        return this;
    }

    @Override // h.w
    public void h(f fVar, long j2) {
        t tVarB;
        if (fVar == null) {
            throw new IllegalArgumentException("source == null");
        }
        if (fVar == this) {
            throw new IllegalArgumentException("source == this");
        }
        z.b(fVar.f6543d, 0L, j2);
        while (j2 > 0) {
            t tVar = fVar.f6542c;
            if (j2 < tVar.f6576c - tVar.f6575b) {
                t tVar2 = this.f6542c;
                t tVar3 = tVar2 != null ? tVar2.f6580g : null;
                if (tVar3 != null && tVar3.f6578e) {
                    if ((((long) tVar3.f6576c) + j2) - ((long) (tVar3.f6577d ? 0 : tVar3.f6575b)) <= 8192) {
                        tVar.d(tVar3, (int) j2);
                        fVar.f6543d -= j2;
                        this.f6543d += j2;
                        return;
                    }
                }
                int i2 = (int) j2;
                Objects.requireNonNull(tVar);
                if (i2 <= 0 || i2 > tVar.f6576c - tVar.f6575b) {
                    throw new IllegalArgumentException();
                }
                if (i2 >= 1024) {
                    tVarB = tVar.c();
                } else {
                    tVarB = u.b();
                    System.arraycopy(tVar.f6574a, tVar.f6575b, tVarB.f6574a, 0, i2);
                }
                tVarB.f6576c = tVarB.f6575b + i2;
                tVar.f6575b += i2;
                tVar.f6580g.b(tVarB);
                fVar.f6542c = tVarB;
            }
            t tVar4 = fVar.f6542c;
            long j3 = tVar4.f6576c - tVar4.f6575b;
            fVar.f6542c = tVar4.a();
            t tVar5 = this.f6542c;
            if (tVar5 == null) {
                this.f6542c = tVar4;
                tVar4.f6580g = tVar4;
                tVar4.f6579f = tVar4;
            } else {
                tVar5.f6580g.b(tVar4);
                t tVar6 = tVar4.f6580g;
                if (tVar6 == tVar4) {
                    throw new IllegalStateException();
                }
                if (tVar6.f6578e) {
                    int i3 = tVar4.f6576c - tVar4.f6575b;
                    if (i3 <= (8192 - tVar6.f6576c) + (tVar6.f6577d ? 0 : tVar6.f6575b)) {
                        tVar4.d(tVar6, i3);
                        tVar4.a();
                        u.a(tVar4);
                    }
                }
            }
            fVar.f6543d -= j3;
            this.f6543d += j3;
            j2 -= j3;
        }
    }

    public int hashCode() {
        t tVar = this.f6542c;
        if (tVar == null) {
            return 0;
        }
        int i2 = 1;
        do {
            int i3 = tVar.f6576c;
            for (int i4 = tVar.f6575b; i4 < i3; i4++) {
                i2 = (i2 * 31) + tVar.f6574a[i4];
            }
            tVar = tVar.f6579f;
        } while (tVar != this.f6542c);
        return i2;
    }

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

    @Override // h.h
    public i k(long j2) {
        return new i(s(j2));
    }

    @Override // h.h
    public void l(long j2) throws EOFException {
        while (j2 > 0) {
            if (this.f6542c == null) {
                throw new EOFException();
            }
            int iMin = (int) Math.min(j2, r0.f6576c - r0.f6575b);
            long j3 = iMin;
            this.f6543d -= j3;
            j2 -= j3;
            t tVar = this.f6542c;
            int i2 = tVar.f6575b + iMin;
            tVar.f6575b = i2;
            if (i2 == tVar.f6576c) {
                this.f6542c = tVar.a();
                u.a(tVar);
            }
        }
    }

    @Override // h.g
    public /* bridge */ /* synthetic */ g m(int i2) {
        d0(i2);
        return this;
    }

    @Override // h.h
    public String n() {
        return w(Long.MAX_VALUE);
    }

    @Override // h.h
    public int p() {
        int iC = c();
        Charset charset = z.f6589a;
        return ((iC & MKeyEvent.KEYCODE_SLEEP) << 24) | (((-16777216) & iC) >>> 24) | ((16711680 & iC) >>> 8) | ((65280 & iC) << 8);
    }

    @Override // h.h
    public boolean q() {
        return this.f6543d == 0;
    }

    @Override // h.g
    public /* bridge */ /* synthetic */ g r(int i2) {
        Z(i2);
        return this;
    }

    @Override // java.nio.channels.ReadableByteChannel
    public int read(ByteBuffer byteBuffer) {
        t tVar = this.f6542c;
        if (tVar == null) {
            return -1;
        }
        int iMin = Math.min(byteBuffer.remaining(), tVar.f6576c - tVar.f6575b);
        byteBuffer.put(tVar.f6574a, tVar.f6575b, iMin);
        int i2 = tVar.f6575b + iMin;
        tVar.f6575b = i2;
        this.f6543d -= (long) iMin;
        if (i2 == tVar.f6576c) {
            this.f6542c = tVar.a();
            u.a(tVar);
        }
        return iMin;
    }

    @Override // h.h
    public byte[] s(long j2) throws EOFException {
        z.b(this.f6543d, 0L, j2);
        if (j2 <= 2147483647L) {
            byte[] bArr = new byte[(int) j2];
            R(bArr);
            return bArr;
        }
        throw new IllegalArgumentException("byteCount > Integer.MAX_VALUE: " + j2);
    }

    @Override // h.g
    public /* bridge */ /* synthetic */ g t(i iVar) {
        W(iVar);
        return this;
    }

    public String toString() {
        long j2 = this.f6543d;
        if (j2 <= 2147483647L) {
            int i2 = (int) j2;
            return (i2 == 0 ? i.f6546c : new v(this, i2)).toString();
        }
        StringBuilder sbC = a.b.c.a.a.C("size > Integer.MAX_VALUE: ");
        sbC.append(this.f6543d);
        throw new IllegalArgumentException(sbC.toString());
    }

    @Override // h.h
    public short u() {
        short sY = y();
        Charset charset = z.f6589a;
        int i2 = sY & 65535;
        return (short) (((i2 & MKeyEvent.KEYCODE_SLEEP) << 8) | ((65280 & i2) >>> 8));
    }

    @Override // h.x
    public long v(f fVar, long j2) {
        if (fVar == null) {
            throw new IllegalArgumentException("sink == null");
        }
        if (j2 < 0) {
            throw new IllegalArgumentException("byteCount < 0: " + j2);
        }
        long j3 = this.f6543d;
        if (j3 == 0) {
            return -1L;
        }
        if (j2 > j3) {
            j2 = j3;
        }
        fVar.h(this, j2);
        return j2;
    }

    @Override // h.h
    public String w(long j2) throws EOFException {
        if (j2 < 0) {
            throw new IllegalArgumentException("limit < 0: " + j2);
        }
        long j3 = j2 != Long.MAX_VALUE ? j2 + 1 : Long.MAX_VALUE;
        long jO = O((byte) 10, 0L, j3);
        if (jO != -1) {
            return U(jO);
        }
        if (j3 < this.f6543d && N(j3 - 1) == 13 && N(j3) == 10) {
            return U(j3);
        }
        f fVar = new f();
        M(fVar, 0L, Math.min(32L, this.f6543d));
        StringBuilder sbC = a.b.c.a.a.C("\\n not found: limit=");
        sbC.append(Math.min(this.f6543d, j2));
        sbC.append(" content=");
        sbC.append(fVar.Q().g());
        sbC.append((char) 8230);
        throw new EOFException(sbC.toString());
    }

    @Override // java.nio.channels.WritableByteChannel
    public int write(ByteBuffer byteBuffer) {
        if (byteBuffer == null) {
            throw new IllegalArgumentException("source == null");
        }
        int iRemaining = byteBuffer.remaining();
        int i2 = iRemaining;
        while (i2 > 0) {
            t tVarV = V(1);
            int iMin = Math.min(i2, 8192 - tVarV.f6576c);
            byteBuffer.get(tVarV.f6574a, tVarV.f6576c, iMin);
            i2 -= iMin;
            tVarV.f6576c += iMin;
        }
        this.f6543d += (long) iRemaining;
        return iRemaining;
    }

    @Override // h.h
    public long x(w wVar) {
        long j2 = this.f6543d;
        if (j2 > 0) {
            ((f) wVar).h(this, j2);
        }
        return j2;
    }

    @Override // h.h
    public short y() {
        long j2 = this.f6543d;
        if (j2 < 2) {
            StringBuilder sbC = a.b.c.a.a.C("size < 2: ");
            sbC.append(this.f6543d);
            throw new IllegalStateException(sbC.toString());
        }
        t tVar = this.f6542c;
        int i2 = tVar.f6575b;
        int i3 = tVar.f6576c;
        if (i3 - i2 < 2) {
            return (short) (((J() & IMcuConstants.DEFAULT_VALUE) << 8) | (J() & IMcuConstants.DEFAULT_VALUE));
        }
        byte[] bArr = tVar.f6574a;
        int i4 = i2 + 1;
        int i5 = i4 + 1;
        int i6 = ((bArr[i2] & IMcuConstants.DEFAULT_VALUE) << 8) | (bArr[i4] & IMcuConstants.DEFAULT_VALUE);
        this.f6543d = j2 - 2;
        if (i5 == i3) {
            this.f6542c = tVar.a();
            u.a(tVar);
        } else {
            tVar.f6575b = i5;
        }
        return (short) i6;
    }
}
