package h;

import com.seewo.adbcommons.model.base.ICmdMsg;
import com.seewo.sdk.model.SDKKeyboardCode;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
import javax.annotation.Nullable;

/* JADX INFO: compiled from: Buffer.java */
/* JADX INFO: loaded from: classes.dex */
public final class c implements e, d, Cloneable {

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private static final byte[] f4175g = {SDKKeyboardCode.FUNCTION_KEY_BOARD_RIGHT_SQUARE_BRACKET, SDKKeyboardCode.FUNCTION_KEY_BOARD_RIGHT_SLASH, 50, SDKKeyboardCode.FUNCTION_KEY_BOARD_SEMICOLON, SDKKeyboardCode.FUNCTION_KEY_BOARD_SINGLE_QUOTE_MARK, SDKKeyboardCode.FUNCTION_KEY_BOARD_GRAVE_ACCENT, SDKKeyboardCode.FUNCTION_KEY_BOARD_COMMA, SDKKeyboardCode.FUNCTION_KEY_BOARD_STOP, SDKKeyboardCode.FUNCTION_KEY_BOARD_LEFT_SLASH, SDKKeyboardCode.FUNCTION_KEY_BOARD_CAPS_LOCK, 97, 98, 99, 100, 101, 102};

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    @Nullable
    o f4176b;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    long f4177f;

    /* JADX INFO: compiled from: Buffer.java */
    class a extends OutputStream {
        a() {
        }

        @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 c.this + ".outputStream()";
        }

        @Override // java.io.OutputStream
        public void write(int i2) {
            c.this.N((byte) i2);
        }

        @Override // java.io.OutputStream
        public void write(byte[] bArr, int i2, int i3) {
            c.this.M(bArr, i2, i3);
        }
    }

    /* JADX INFO: compiled from: Buffer.java */
    class b extends InputStream {
        b() {
        }

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

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

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

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

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

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

    public long B() {
        return this.f4177f;
    }

    public f C() {
        long j2 = this.f4177f;
        if (j2 <= 2147483647L) {
            return D((int) j2);
        }
        throw new IllegalArgumentException("size > Integer.MAX_VALUE: " + this.f4177f);
    }

    public f D(int i2) {
        return i2 == 0 ? f.f4181i : new q(this, i2);
    }

    @Override // h.d
    public /* bridge */ /* synthetic */ d E(f fVar) throws IOException {
        H(fVar);
        return this;
    }

    o F(int i2) {
        if (i2 < 1 || i2 > 8192) {
            throw new IllegalArgumentException();
        }
        o oVar = this.f4176b;
        if (oVar == null) {
            o oVarB = p.b();
            this.f4176b = oVarB;
            oVarB.f4210g = oVarB;
            oVarB.f4209f = oVarB;
            return oVarB;
        }
        o oVar2 = oVar.f4210g;
        if (oVar2.f4206c + i2 <= 8192 && oVar2.f4208e) {
            return oVar2;
        }
        o oVarB2 = p.b();
        oVar2.c(oVarB2);
        return oVarB2;
    }

    @Override // h.e
    public void G(c cVar, long j2) throws EOFException {
        long j3 = this.f4177f;
        if (j3 >= j2) {
            cVar.write(this, j2);
        } else {
            cVar.write(this, j3);
            throw new EOFException();
        }
    }

    public c H(f fVar) {
        if (fVar == null) {
            throw new IllegalArgumentException("byteString == null");
        }
        fVar.w(this);
        return this;
    }

    @Override // h.e
    public short I() {
        return u.d(readShort());
    }

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

    @Override // h.d
    public /* bridge */ /* synthetic */ d K() throws IOException {
        j();
        return this;
    }

    /* JADX WARN: Code restructure failed: missing block: B:18:0x003c, code lost:
    
        r1 = new h.c();
        r1.P(r3);
        r1.N(r15);
     */
    /* JADX WARN: Code restructure failed: missing block: B:19:0x0047, code lost:
    
        if (r8 != false) goto L21;
     */
    /* JADX WARN: Code restructure failed: missing block: B:20:0x0049, code lost:
    
        r1.readByte();
     */
    /* JADX WARN: Code restructure failed: missing block: B:22:0x0066, code lost:
    
        throw new java.lang.NumberFormatException("Number too large: " + r1.r());
     */
    /* JADX WARN: Removed duplicated region for block: B:33:0x009c  */
    /* JADX WARN: Removed duplicated region for block: B:34:0x00a6  */
    @Override // h.e
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public long L() {
        /*
            Method dump skipped, instruction units count: 201
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: h.c.L():long");
    }

    public c M(byte[] bArr, int i2, int i3) {
        if (bArr == null) {
            throw new IllegalArgumentException("source == null");
        }
        long j2 = i3;
        u.b(bArr.length, i2, j2);
        int i4 = i3 + i2;
        while (i2 < i4) {
            o oVarF = F(1);
            int iMin = Math.min(i4 - i2, 8192 - oVarF.f4206c);
            System.arraycopy(bArr, i2, oVarF.a, oVarF.f4206c, iMin);
            i2 += iMin;
            oVarF.f4206c += iMin;
        }
        this.f4177f += j2;
        return this;
    }

    public c N(int i2) {
        o oVarF = F(1);
        byte[] bArr = oVarF.a;
        int i3 = oVarF.f4206c;
        oVarF.f4206c = i3 + 1;
        bArr[i3] = (byte) i2;
        this.f4177f++;
        return this;
    }

    @Override // h.e
    public long O(r rVar) throws IOException {
        long j2 = this.f4177f;
        if (j2 > 0) {
            rVar.write(this, j2);
        }
        return j2;
    }

    public c P(long j2) {
        if (j2 == 0) {
            N(48);
            return this;
        }
        boolean z = false;
        int i2 = 1;
        if (j2 < 0) {
            j2 = -j2;
            if (j2 < 0) {
                W("-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++;
        }
        o oVarF = F(i2);
        byte[] bArr = oVarF.a;
        int i3 = oVarF.f4206c + i2;
        while (j2 != 0) {
            i3--;
            bArr[i3] = f4175g[(int) (j2 % 10)];
            j2 /= 10;
        }
        if (z) {
            bArr[i3 - 1] = SDKKeyboardCode.FUNCTION_KEY_BOARD_MINUS;
        }
        oVarF.f4206c += i2;
        this.f4177f += (long) i2;
        return this;
    }

    public c Q(long j2) {
        if (j2 == 0) {
            N(48);
            return this;
        }
        int iNumberOfTrailingZeros = (Long.numberOfTrailingZeros(Long.highestOneBit(j2)) / 4) + 1;
        o oVarF = F(iNumberOfTrailingZeros);
        byte[] bArr = oVarF.a;
        int i2 = oVarF.f4206c;
        for (int i3 = (i2 + iNumberOfTrailingZeros) - 1; i3 >= i2; i3--) {
            bArr[i3] = f4175g[(int) (15 & j2)];
            j2 >>>= 4;
        }
        oVarF.f4206c += iNumberOfTrailingZeros;
        this.f4177f += (long) iNumberOfTrailingZeros;
        return this;
    }

    public c R(int i2) {
        o oVarF = F(4);
        byte[] bArr = oVarF.a;
        int i3 = oVarF.f4206c;
        int i4 = i3 + 1;
        bArr[i3] = (byte) ((i2 >>> 24) & 255);
        int i5 = i4 + 1;
        bArr[i4] = (byte) ((i2 >>> 16) & 255);
        int i6 = i5 + 1;
        bArr[i5] = (byte) ((i2 >>> 8) & 255);
        bArr[i6] = (byte) (i2 & 255);
        oVarF.f4206c = i6 + 1;
        this.f4177f += 4;
        return this;
    }

    public c S(long j2) {
        o oVarF = F(8);
        byte[] bArr = oVarF.a;
        int i2 = oVarF.f4206c;
        int i3 = i2 + 1;
        bArr[i2] = (byte) ((j2 >>> 56) & 255);
        int i4 = i3 + 1;
        bArr[i3] = (byte) ((j2 >>> 48) & 255);
        int i5 = i4 + 1;
        bArr[i4] = (byte) ((j2 >>> 40) & 255);
        int i6 = i5 + 1;
        bArr[i5] = (byte) ((j2 >>> 32) & 255);
        int i7 = i6 + 1;
        bArr[i6] = (byte) ((j2 >>> 24) & 255);
        int i8 = i7 + 1;
        bArr[i7] = (byte) ((j2 >>> 16) & 255);
        int i9 = i8 + 1;
        bArr[i8] = (byte) ((j2 >>> 8) & 255);
        bArr[i9] = (byte) (j2 & 255);
        oVarF.f4206c = i9 + 1;
        this.f4177f += 8;
        return this;
    }

    public c T(int i2) {
        o oVarF = F(2);
        byte[] bArr = oVarF.a;
        int i3 = oVarF.f4206c;
        int i4 = i3 + 1;
        bArr[i3] = (byte) ((i2 >>> 8) & 255);
        bArr[i4] = (byte) (i2 & 255);
        oVarF.f4206c = i4 + 1;
        this.f4177f += 2;
        return this;
    }

    public c U(String str, int i2, int i3, Charset charset) {
        if (str == null) {
            throw new IllegalArgumentException("string == null");
        }
        if (i2 < 0) {
            throw new IllegalAccessError("beginIndex < 0: " + i2);
        }
        if (i3 < i2) {
            throw new IllegalArgumentException("endIndex < beginIndex: " + i3 + " < " + i2);
        }
        if (i3 > str.length()) {
            throw new IllegalArgumentException("endIndex > string.length: " + i3 + " > " + str.length());
        }
        if (charset == null) {
            throw new IllegalArgumentException("charset == null");
        }
        if (charset.equals(u.a)) {
            Z(str, i2, i3);
            return this;
        }
        byte[] bytes = str.substring(i2, i3).getBytes(charset);
        M(bytes, 0, bytes.length);
        return this;
    }

    public c V(String str, Charset charset) {
        U(str, 0, str.length(), charset);
        return this;
    }

    public c W(String str) {
        Z(str, 0, str.length());
        return this;
    }

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

    @Override // h.d
    public /* bridge */ /* synthetic */ d Y(String str) throws IOException {
        W(str);
        return this;
    }

    public c Z(String str, int i2, int i3) {
        if (str == null) {
            throw new IllegalArgumentException("string == null");
        }
        if (i2 < 0) {
            throw new IllegalArgumentException("beginIndex < 0: " + i2);
        }
        if (i3 < i2) {
            throw new IllegalArgumentException("endIndex < beginIndex: " + i3 + " < " + i2);
        }
        if (i3 > str.length()) {
            throw new IllegalArgumentException("endIndex > string.length: " + i3 + " > " + str.length());
        }
        while (i2 < i3) {
            char cCharAt = str.charAt(i2);
            if (cCharAt < 128) {
                o oVarF = F(1);
                byte[] bArr = oVarF.a;
                int i4 = oVarF.f4206c - i2;
                int iMin = Math.min(i3, 8192 - i4);
                int i5 = i2 + 1;
                bArr[i2 + i4] = (byte) cCharAt;
                while (i5 < iMin) {
                    char cCharAt2 = str.charAt(i5);
                    if (cCharAt2 >= 128) {
                        break;
                    }
                    bArr[i5 + i4] = (byte) cCharAt2;
                    i5++;
                }
                int i6 = oVarF.f4206c;
                int i7 = (i4 + i5) - i6;
                oVarF.f4206c = i6 + i7;
                this.f4177f += (long) i7;
                i2 = i5;
            } else {
                if (cCharAt < 2048) {
                    N((cCharAt >> 6) | 192);
                    N((cCharAt & '?') | ICmdMsg.ACTION_START_ACTIVITY);
                } else if (cCharAt < 55296 || cCharAt > 57343) {
                    N((cCharAt >> '\f') | 224);
                    N(((cCharAt >> 6) & 63) | ICmdMsg.ACTION_START_ACTIVITY);
                    N((cCharAt & '?') | ICmdMsg.ACTION_START_ACTIVITY);
                } else {
                    int i8 = i2 + 1;
                    char cCharAt3 = i8 < i3 ? str.charAt(i8) : (char) 0;
                    if (cCharAt > 56319 || cCharAt3 < 56320 || cCharAt3 > 57343) {
                        N(63);
                        i2 = i8;
                    } else {
                        int i9 = (((cCharAt & 10239) << 10) | (9215 & cCharAt3)) + 65536;
                        N((i9 >> 18) | 240);
                        N(((i9 >> 12) & 63) | ICmdMsg.ACTION_START_ACTIVITY);
                        N(((i9 >> 6) & 63) | ICmdMsg.ACTION_START_ACTIVITY);
                        N((i9 & 63) | ICmdMsg.ACTION_START_ACTIVITY);
                        i2 += 2;
                    }
                }
                i2++;
            }
        }
        return this;
    }

    public void a() {
        try {
            skip(this.f4177f);
        } catch (EOFException e2) {
            throw new AssertionError(e2);
        }
    }

    @Override // h.d
    public /* bridge */ /* synthetic */ d a0(long j2) throws IOException {
        P(j2);
        return this;
    }

    @Override // h.d
    public long b(s sVar) throws IOException {
        if (sVar == null) {
            throw new IllegalArgumentException("source == null");
        }
        long j2 = 0;
        while (true) {
            long j3 = sVar.read(this, 8192L);
            if (j3 == -1) {
                return j2;
            }
            j2 += j3;
        }
    }

    public c b0(int i2) {
        if (i2 < 128) {
            N(i2);
        } else if (i2 < 2048) {
            N((i2 >> 6) | 192);
            N((i2 & 63) | ICmdMsg.ACTION_START_ACTIVITY);
        } else if (i2 < 65536) {
            if (i2 < 55296 || i2 > 57343) {
                N((i2 >> 12) | 224);
                N(((i2 >> 6) & 63) | ICmdMsg.ACTION_START_ACTIVITY);
                N((i2 & 63) | ICmdMsg.ACTION_START_ACTIVITY);
            } else {
                N(63);
            }
        } else {
            if (i2 > 1114111) {
                throw new IllegalArgumentException("Unexpected code point: " + Integer.toHexString(i2));
            }
            N((i2 >> 18) | 240);
            N(((i2 >> 12) & 63) | ICmdMsg.ACTION_START_ACTIVITY);
            N(((i2 >> 6) & 63) | ICmdMsg.ACTION_START_ACTIVITY);
            N((i2 & 63) | ICmdMsg.ACTION_START_ACTIVITY);
        }
        return this;
    }

    @Override // h.e, h.d
    public c buffer() {
        return this;
    }

    @Override // h.d
    public /* bridge */ /* synthetic */ d c(long j2) throws IOException {
        Q(j2);
        return this;
    }

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

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

    @Override // h.e
    public f e(long j2) throws EOFException {
        return new f(A(j2));
    }

    @Override // h.e
    public boolean e0(long j2, f fVar) {
        return o(j2, fVar, 0, fVar.q());
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof c)) {
            return false;
        }
        c cVar = (c) obj;
        long j2 = this.f4177f;
        if (j2 != cVar.f4177f) {
            return false;
        }
        long j3 = 0;
        if (j2 == 0) {
            return true;
        }
        o oVar = this.f4176b;
        o oVar2 = cVar.f4176b;
        int i2 = oVar.f4205b;
        int i3 = oVar2.f4205b;
        while (j3 < this.f4177f) {
            long jMin = Math.min(oVar.f4206c - i2, oVar2.f4206c - i3);
            int i4 = 0;
            while (i4 < jMin) {
                int i5 = i2 + 1;
                int i6 = i3 + 1;
                if (oVar.a[i2] != oVar2.a[i3]) {
                    return false;
                }
                i4++;
                i2 = i5;
                i3 = i6;
            }
            if (i2 == oVar.f4206c) {
                oVar = oVar.f4209f;
                i2 = oVar.f4205b;
            }
            if (i3 == oVar2.f4206c) {
                oVar2 = oVar2.f4209f;
                i3 = oVar2.f4205b;
            }
            j3 += jMin;
        }
        return true;
    }

    /* JADX INFO: renamed from: f, reason: merged with bridge method [inline-methods] */
    public c clone() {
        c cVar = new c();
        if (this.f4177f == 0) {
            return cVar;
        }
        o oVar = new o(this.f4176b);
        cVar.f4176b = oVar;
        oVar.f4210g = oVar;
        oVar.f4209f = oVar;
        o oVar2 = this.f4176b;
        while (true) {
            oVar2 = oVar2.f4209f;
            if (oVar2 == this.f4176b) {
                cVar.f4177f = this.f4177f;
                return cVar;
            }
            cVar.f4176b.f4210g.c(new o(oVar2));
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:33:0x0091  */
    /* JADX WARN: Removed duplicated region for block: B:34:0x009b  */
    /* JADX WARN: Removed duplicated region for block: B:36:0x009f  */
    /* JADX WARN: Removed duplicated region for block: B:44:0x00a3 A[EDGE_INSN: B:44:0x00a3->B:38:0x00a3 BREAK  A[LOOP:0: B:5:0x000b->B:46:?], SYNTHETIC] */
    @Override // h.e
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public long f0() {
        /*
            r14 = this;
            long r0 = r14.f4177f
            r2 = 0
            int r0 = (r0 > r2 ? 1 : (r0 == r2 ? 0 : -1))
            if (r0 == 0) goto Laa
            r0 = 0
            r1 = r0
            r4 = r2
        Lb:
            h.o r6 = r14.f4176b
            byte[] r7 = r6.a
            int r8 = r6.f4205b
            int r9 = r6.f4206c
        L13:
            if (r8 >= r9) goto L8f
            r10 = r7[r8]
            r11 = 48
            if (r10 < r11) goto L22
            r11 = 57
            if (r10 > r11) goto L22
            int r11 = r10 + (-48)
            goto L3a
        L22:
            r11 = 97
            if (r10 < r11) goto L2f
            r11 = 102(0x66, float:1.43E-43)
            if (r10 > r11) goto L2f
            int r11 = r10 + (-97)
        L2c:
            int r11 = r11 + 10
            goto L3a
        L2f:
            r11 = 65
            if (r10 < r11) goto L70
            r11 = 70
            if (r10 > r11) goto L70
            int r11 = r10 + (-65)
            goto L2c
        L3a:
            r12 = -1152921504606846976(0xf000000000000000, double:-3.105036184601418E231)
            long r12 = r12 & r4
            int r12 = (r12 > r2 ? 1 : (r12 == r2 ? 0 : -1))
            if (r12 != 0) goto L4a
            r10 = 4
            long r4 = r4 << r10
            long r10 = (long) r11
            long r4 = r4 | r10
            int r8 = r8 + 1
            int r0 = r0 + 1
            goto L13
        L4a:
            h.c r0 = new h.c
            r0.<init>()
            r0.Q(r4)
            r0.N(r10)
            java.lang.NumberFormatException r1 = new java.lang.NumberFormatException
            java.lang.StringBuilder r2 = new java.lang.StringBuilder
            r2.<init>()
            java.lang.String r3 = "Number too large: "
            r2.append(r3)
            java.lang.String r0 = r0.r()
            r2.append(r0)
            java.lang.String r0 = r2.toString()
            r1.<init>(r0)
            throw r1
        L70:
            if (r0 == 0) goto L74
            r1 = 1
            goto L8f
        L74:
            java.lang.NumberFormatException r0 = new java.lang.NumberFormatException
            java.lang.StringBuilder r1 = new java.lang.StringBuilder
            r1.<init>()
            java.lang.String r2 = "Expected leading [0-9a-fA-F] character but was 0x"
            r1.append(r2)
            java.lang.String r2 = java.lang.Integer.toHexString(r10)
            r1.append(r2)
            java.lang.String r1 = r1.toString()
            r0.<init>(r1)
            throw r0
        L8f:
            if (r8 != r9) goto L9b
            h.o r7 = r6.b()
            r14.f4176b = r7
            h.p.a(r6)
            goto L9d
        L9b:
            r6.f4205b = r8
        L9d:
            if (r1 != 0) goto La3
            h.o r6 = r14.f4176b
            if (r6 != 0) goto Lb
        La3:
            long r1 = r14.f4177f
            long r6 = (long) r0
            long r1 = r1 - r6
            r14.f4177f = r1
            return r4
        Laa:
            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.c.f0():long");
    }

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

    public long g() {
        long j2 = this.f4177f;
        if (j2 == 0) {
            return 0L;
        }
        o oVar = this.f4176b.f4210g;
        int i2 = oVar.f4206c;
        return (i2 >= 8192 || !oVar.f4208e) ? j2 : j2 - ((long) (i2 - oVar.f4205b));
    }

    public c h(c cVar, long j2, long j3) {
        if (cVar == null) {
            throw new IllegalArgumentException("out == null");
        }
        u.b(this.f4177f, j2, j3);
        if (j3 == 0) {
            return this;
        }
        cVar.f4177f += j3;
        o oVar = this.f4176b;
        while (true) {
            int i2 = oVar.f4206c;
            int i3 = oVar.f4205b;
            if (j2 < i2 - i3) {
                break;
            }
            j2 -= (long) (i2 - i3);
            oVar = oVar.f4209f;
        }
        while (j3 > 0) {
            o oVar2 = new o(oVar);
            int i4 = (int) (((long) oVar2.f4205b) + j2);
            oVar2.f4205b = i4;
            oVar2.f4206c = Math.min(i4 + ((int) j3), oVar2.f4206c);
            o oVar3 = cVar.f4176b;
            if (oVar3 == null) {
                oVar2.f4210g = oVar2;
                oVar2.f4209f = oVar2;
                cVar.f4176b = oVar2;
            } else {
                oVar3.f4210g.c(oVar2);
            }
            j3 -= (long) (oVar2.f4206c - oVar2.f4205b);
            oVar = oVar.f4209f;
            j2 = 0;
        }
        return this;
    }

    @Override // h.e
    public String h0(Charset charset) {
        try {
            return q(this.f4177f, charset);
        } catch (EOFException e2) {
            throw new AssertionError(e2);
        }
    }

    public int hashCode() {
        o oVar = this.f4176b;
        if (oVar == null) {
            return 0;
        }
        int i2 = 1;
        do {
            int i3 = oVar.f4206c;
            for (int i4 = oVar.f4205b; i4 < i3; i4++) {
                i2 = (i2 * 31) + oVar.a[i4];
            }
            oVar = oVar.f4209f;
        } while (oVar != this.f4176b);
        return i2;
    }

    @Override // h.d
    public d i() {
        return this;
    }

    public c j() {
        return this;
    }

    public byte k(long j2) {
        u.b(this.f4177f, j2, 1L);
        o oVar = this.f4176b;
        while (true) {
            int i2 = oVar.f4206c;
            int i3 = oVar.f4205b;
            long j3 = i2 - i3;
            if (j2 < j3) {
                return oVar.a[i3 + ((int) j2)];
            }
            j2 -= j3;
            oVar = oVar.f4209f;
        }
    }

    @Override // h.e
    public InputStream k0() {
        return new b();
    }

    @Override // h.e
    public boolean l(long j2) {
        return this.f4177f >= j2;
    }

    public long m(byte b2, long j2, long j3) {
        o oVar;
        long j4 = 0;
        if (j2 < 0 || j3 < j2) {
            throw new IllegalArgumentException(String.format("size=%s fromIndex=%s toIndex=%s", Long.valueOf(this.f4177f), Long.valueOf(j2), Long.valueOf(j3)));
        }
        long j5 = this.f4177f;
        if (j3 <= j5) {
            j5 = j3;
        }
        if (j2 == j5 || (oVar = this.f4176b) == null) {
            return -1L;
        }
        long j6 = this.f4177f;
        if (j6 - j2 < j2) {
            while (j6 > j2) {
                oVar = oVar.f4210g;
                j6 -= (long) (oVar.f4206c - oVar.f4205b);
            }
        } else {
            while (true) {
                long j7 = ((long) (oVar.f4206c - oVar.f4205b)) + j4;
                if (j7 >= j2) {
                    break;
                }
                oVar = oVar.f4209f;
                j4 = j7;
            }
            j6 = j4;
        }
        long j8 = j2;
        while (j6 < j5) {
            byte[] bArr = oVar.a;
            int iMin = (int) Math.min(oVar.f4206c, (((long) oVar.f4205b) + j5) - j6);
            for (int i2 = (int) ((((long) oVar.f4205b) + j8) - j6); i2 < iMin; i2++) {
                if (bArr[i2] == b2) {
                    return ((long) (i2 - oVar.f4205b)) + j6;
                }
            }
            j6 += (long) (oVar.f4206c - oVar.f4205b);
            oVar = oVar.f4209f;
            j8 = j6;
        }
        return -1L;
    }

    public OutputStream n() {
        return new a();
    }

    public boolean o(long j2, f fVar, int i2, int i3) {
        if (j2 < 0 || i2 < 0 || i3 < 0 || this.f4177f - j2 < i3 || fVar.q() - i2 < i3) {
            return false;
        }
        for (int i4 = 0; i4 < i3; i4++) {
            if (k(((long) i4) + j2) != fVar.i(i2 + i4)) {
                return false;
            }
        }
        return true;
    }

    public f p() {
        return new f(t());
    }

    public String q(long j2, Charset charset) throws EOFException {
        u.b(this.f4177f, 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 "";
        }
        o oVar = this.f4176b;
        if (((long) oVar.f4205b) + j2 > oVar.f4206c) {
            return new String(A(j2), charset);
        }
        String str = new String(oVar.a, oVar.f4205b, (int) j2, charset);
        int i2 = (int) (((long) oVar.f4205b) + j2);
        oVar.f4205b = i2;
        this.f4177f -= j2;
        if (i2 == oVar.f4206c) {
            this.f4176b = oVar.b();
            p.a(oVar);
        }
        return str;
    }

    public String r() {
        try {
            return q(this.f4177f, u.a);
        } catch (EOFException e2) {
            throw new AssertionError(e2);
        }
    }

    @Override // h.e
    public int read(byte[] bArr, int i2, int i3) {
        u.b(bArr.length, i2, i3);
        o oVar = this.f4176b;
        if (oVar == null) {
            return -1;
        }
        int iMin = Math.min(i3, oVar.f4206c - oVar.f4205b);
        System.arraycopy(oVar.a, oVar.f4205b, bArr, i2, iMin);
        int i4 = oVar.f4205b + iMin;
        oVar.f4205b = i4;
        this.f4177f -= (long) iMin;
        if (i4 == oVar.f4206c) {
            this.f4176b = oVar.b();
            p.a(oVar);
        }
        return iMin;
    }

    @Override // h.e
    public byte readByte() {
        long j2 = this.f4177f;
        if (j2 == 0) {
            throw new IllegalStateException("size == 0");
        }
        o oVar = this.f4176b;
        int i2 = oVar.f4205b;
        int i3 = oVar.f4206c;
        int i4 = i2 + 1;
        byte b2 = oVar.a[i2];
        this.f4177f = j2 - 1;
        if (i4 == i3) {
            this.f4176b = oVar.b();
            p.a(oVar);
        } else {
            oVar.f4205b = i4;
        }
        return b2;
    }

    @Override // h.e
    public void readFully(byte[] bArr) throws EOFException {
        int i2 = 0;
        while (i2 < bArr.length) {
            int i3 = read(bArr, i2, bArr.length - i2);
            if (i3 == -1) {
                throw new EOFException();
            }
            i2 += i3;
        }
    }

    @Override // h.e
    public int readInt() {
        long j2 = this.f4177f;
        if (j2 < 4) {
            throw new IllegalStateException("size < 4: " + this.f4177f);
        }
        o oVar = this.f4176b;
        int i2 = oVar.f4205b;
        int i3 = oVar.f4206c;
        if (i3 - i2 < 4) {
            return ((readByte() & 255) << 24) | ((readByte() & 255) << 16) | ((readByte() & 255) << 8) | (readByte() & 255);
        }
        byte[] bArr = oVar.a;
        int i4 = i2 + 1;
        int i5 = i4 + 1;
        int i6 = ((bArr[i2] & 255) << 24) | ((bArr[i4] & 255) << 16);
        int i7 = i5 + 1;
        int i8 = i6 | ((bArr[i5] & 255) << 8);
        int i9 = i7 + 1;
        int i10 = i8 | (bArr[i7] & 255);
        this.f4177f = j2 - 4;
        if (i9 == i3) {
            this.f4176b = oVar.b();
            p.a(oVar);
        } else {
            oVar.f4205b = i9;
        }
        return i10;
    }

    @Override // h.e
    public long readLong() {
        long j2 = this.f4177f;
        if (j2 < 8) {
            throw new IllegalStateException("size < 8: " + this.f4177f);
        }
        o oVar = this.f4176b;
        int i2 = oVar.f4205b;
        int i3 = oVar.f4206c;
        if (i3 - i2 < 8) {
            return ((((long) readInt()) & 4294967295L) << 32) | (4294967295L & ((long) readInt()));
        }
        byte[] bArr = oVar.a;
        int i4 = i2 + 1;
        long j3 = (((long) bArr[i2]) & 255) << 56;
        int i5 = i4 + 1;
        long j4 = ((((long) bArr[i4]) & 255) << 48) | j3;
        int i6 = i5 + 1;
        long j5 = j4 | ((((long) bArr[i5]) & 255) << 40);
        int i7 = i6 + 1;
        int i8 = i7 + 1;
        long j6 = j5 | ((((long) bArr[i6]) & 255) << 32) | ((((long) bArr[i7]) & 255) << 24);
        int i9 = i8 + 1;
        long j7 = j6 | ((((long) bArr[i8]) & 255) << 16);
        int i10 = i9 + 1;
        long j8 = j7 | ((((long) bArr[i9]) & 255) << 8);
        int i11 = i10 + 1;
        long j9 = j8 | (((long) bArr[i10]) & 255);
        this.f4177f = j2 - 8;
        if (i11 == i3) {
            this.f4176b = oVar.b();
            p.a(oVar);
        } else {
            oVar.f4205b = i11;
        }
        return j9;
    }

    @Override // h.e
    public short readShort() {
        long j2 = this.f4177f;
        if (j2 < 2) {
            throw new IllegalStateException("size < 2: " + this.f4177f);
        }
        o oVar = this.f4176b;
        int i2 = oVar.f4205b;
        int i3 = oVar.f4206c;
        if (i3 - i2 < 2) {
            return (short) (((readByte() & 255) << 8) | (readByte() & 255));
        }
        byte[] bArr = oVar.a;
        int i4 = i2 + 1;
        int i5 = i4 + 1;
        int i6 = ((bArr[i2] & 255) << 8) | (bArr[i4] & 255);
        this.f4177f = j2 - 2;
        if (i5 == i3) {
            this.f4176b = oVar.b();
            p.a(oVar);
        } else {
            oVar.f4205b = i5;
        }
        return (short) i6;
    }

    @Override // h.e
    public String s() throws EOFException {
        return y(Long.MAX_VALUE);
    }

    @Override // h.e
    public void skip(long j2) throws EOFException {
        while (j2 > 0) {
            if (this.f4176b == null) {
                throw new EOFException();
            }
            int iMin = (int) Math.min(j2, r0.f4206c - r0.f4205b);
            long j3 = iMin;
            this.f4177f -= j3;
            j2 -= j3;
            o oVar = this.f4176b;
            int i2 = oVar.f4205b + iMin;
            oVar.f4205b = i2;
            if (i2 == oVar.f4206c) {
                this.f4176b = oVar.b();
                p.a(oVar);
            }
        }
    }

    @Override // h.e
    public byte[] t() {
        try {
            return A(this.f4177f);
        } catch (EOFException e2) {
            throw new AssertionError(e2);
        }
    }

    @Override // h.s
    public t timeout() {
        return t.NONE;
    }

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

    public String u(long j2) throws EOFException {
        return q(j2, u.a);
    }

    @Override // h.e
    public int v() {
        return u.c(readInt());
    }

    public int w() throws EOFException {
        int i2;
        int i3;
        int i4;
        if (this.f4177f == 0) {
            throw new EOFException();
        }
        byte bK = k(0L);
        if ((bK & SDKKeyboardCode.FUNCTION_KEY_BOARD_VOLUME_DOWN) == 0) {
            i2 = bK & SDKKeyboardCode.FUNCTION_KEY_BOARD_VOLUME_UP;
            i4 = 0;
            i3 = 1;
        } else if ((bK & 224) == 192) {
            i2 = bK & SDKKeyboardCode.FUNCTION_KEY_BOARD_2;
            i3 = 2;
            i4 = 128;
        } else if ((bK & 240) == 224) {
            i2 = bK & SDKKeyboardCode.FUNCTION_KEY_BOARD_L;
            i3 = 3;
            i4 = 2048;
        } else {
            if ((bK & SDKKeyboardCode.FUNCTION_KEY_SLEEP) != 240) {
                skip(1L);
                return 65533;
            }
            i2 = bK & 7;
            i3 = 4;
            i4 = 65536;
        }
        long j2 = i3;
        if (this.f4177f < j2) {
            throw new EOFException("size < " + i3 + ": " + this.f4177f + " (to read code point prefixed 0x" + Integer.toHexString(bK) + ")");
        }
        for (int i5 = 1; i5 < i3; i5++) {
            long j3 = i5;
            byte bK2 = k(j3);
            if ((bK2 & 192) != 128) {
                skip(j3);
                return 65533;
            }
            i2 = (i2 << 6) | (bK2 & SDKKeyboardCode.FUNCTION_KEY_BOARD_F6);
        }
        skip(j2);
        if (i2 > 1114111) {
            return 65533;
        }
        if ((i2 < 55296 || i2 > 57343) && i2 >= i4) {
            return i2;
        }
        return 65533;
    }

    @Override // h.d
    public /* bridge */ /* synthetic */ d write(byte[] bArr) throws IOException {
        J(bArr);
        return this;
    }

    @Override // h.d
    public /* bridge */ /* synthetic */ d writeByte(int i2) throws IOException {
        N(i2);
        return this;
    }

    @Override // h.d
    public /* bridge */ /* synthetic */ d writeInt(int i2) throws IOException {
        R(i2);
        return this;
    }

    @Override // h.d
    public /* bridge */ /* synthetic */ d writeLong(long j2) throws IOException {
        S(j2);
        return this;
    }

    @Override // h.d
    public /* bridge */ /* synthetic */ d writeShort(int i2) throws IOException {
        T(i2);
        return this;
    }

    String x(long j2) throws EOFException {
        if (j2 > 0) {
            long j3 = j2 - 1;
            if (k(j3) == 13) {
                String strU = u(j3);
                skip(2L);
                return strU;
            }
        }
        String strU2 = u(j2);
        skip(1L);
        return strU2;
    }

    public String y(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 jM = m((byte) 10, 0L, j3);
        if (jM != -1) {
            return x(jM);
        }
        if (j3 < B() && k(j3 - 1) == 13 && k(j3) == 10) {
            return x(j3);
        }
        c cVar = new c();
        h(cVar, 0L, Math.min(32L, B()));
        throw new EOFException("\\n not found: limit=" + Math.min(B(), j2) + " content=" + cVar.p().j() + (char) 8230);
    }

    @Override // h.e
    public boolean z() {
        return this.f4177f == 0;
    }

    @Override // h.d
    public /* bridge */ /* synthetic */ d write(byte[] bArr, int i2, int i3) throws IOException {
        M(bArr, i2, i3);
        return this;
    }

    @Override // h.r
    public void write(c cVar, long j2) {
        if (cVar == null) {
            throw new IllegalArgumentException("source == null");
        }
        if (cVar != this) {
            u.b(cVar.f4177f, 0L, j2);
            while (j2 > 0) {
                o oVar = cVar.f4176b;
                if (j2 < oVar.f4206c - oVar.f4205b) {
                    o oVar2 = this.f4176b;
                    o oVar3 = oVar2 != null ? oVar2.f4210g : null;
                    if (oVar3 != null && oVar3.f4208e) {
                        if ((((long) oVar3.f4206c) + j2) - ((long) (oVar3.f4207d ? 0 : oVar3.f4205b)) <= 8192) {
                            cVar.f4176b.e(oVar3, (int) j2);
                            cVar.f4177f -= j2;
                            this.f4177f += j2;
                            return;
                        }
                    }
                    cVar.f4176b = cVar.f4176b.d((int) j2);
                }
                o oVar4 = cVar.f4176b;
                long j3 = oVar4.f4206c - oVar4.f4205b;
                cVar.f4176b = oVar4.b();
                o oVar5 = this.f4176b;
                if (oVar5 == null) {
                    this.f4176b = oVar4;
                    oVar4.f4210g = oVar4;
                    oVar4.f4209f = oVar4;
                } else {
                    oVar5.f4210g.c(oVar4);
                    oVar4.a();
                }
                cVar.f4177f -= j3;
                this.f4177f += j3;
                j2 -= j3;
            }
            return;
        }
        throw new IllegalArgumentException("source == this");
    }

    @Override // h.s
    public long read(c cVar, long j2) {
        if (cVar == null) {
            throw new IllegalArgumentException("sink == null");
        }
        if (j2 >= 0) {
            long j3 = this.f4177f;
            if (j3 == 0) {
                return -1L;
            }
            if (j2 > j3) {
                j2 = j3;
            }
            cVar.write(this, j2);
            return j2;
        }
        throw new IllegalArgumentException("byteCount < 0: " + j2);
    }
}
