package c.b.a.w;

import com.cvte.vman.instance.InvokeCmd;
import java.io.Closeable;
import java.io.Flushable;
import java.io.IOException;
import java.io.Writer;
import java.util.Arrays;
import java.util.Objects;

/* JADX INFO: loaded from: classes.dex */
public class c implements Closeable, Flushable {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final String[] f1396a = new String[InvokeCmd.CMD_SYSTEMCTRL_SET_HDMI_CLOCK_WAKEUP_STATE];

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final String[] f1397b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Writer f1398c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int[] f1399d = new int[32];

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public int f1400e = 0;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public String f1401f;
    public String g;
    public boolean h;
    public boolean i;
    public String j;
    public boolean k;

    static {
        for (int i = 0; i <= 31; i++) {
            f1396a[i] = String.format("\\u%04x", Integer.valueOf(i));
        }
        String[] strArr = f1396a;
        strArr[34] = "\\\"";
        strArr[92] = "\\\\";
        strArr[9] = "\\t";
        strArr[8] = "\\b";
        strArr[10] = "\\n";
        strArr[13] = "\\r";
        strArr[12] = "\\f";
        String[] strArr2 = (String[]) strArr.clone();
        f1397b = strArr2;
        strArr2[60] = "\\u003c";
        strArr2[62] = "\\u003e";
        strArr2[38] = "\\u0026";
        strArr2[61] = "\\u003d";
        strArr2[39] = "\\u0027";
    }

    public c(Writer writer) {
        k(6);
        this.g = ":";
        this.k = true;
        Objects.requireNonNull(writer, "out == null");
        this.f1398c = writer;
    }

    public final void a() throws IOException {
        int iJ = j();
        if (iJ == 1) {
            l(2);
        } else {
            if (iJ != 2) {
                if (iJ == 4) {
                    this.f1398c.append((CharSequence) this.g);
                    l(5);
                    return;
                }
                if (iJ != 6) {
                    if (iJ != 7) {
                        throw new IllegalStateException("Nesting problem.");
                    }
                    if (!this.h) {
                        throw new IllegalStateException("JSON must have only one top-level value.");
                    }
                }
                l(7);
                return;
            }
            this.f1398c.append(',');
        }
        h();
    }

    public c b() throws IOException {
        s();
        a();
        k(1);
        this.f1398c.write(91);
        return this;
    }

    public c c() throws IOException {
        s();
        a();
        k(3);
        this.f1398c.write(InvokeCmd.CMD_SYSTEMCTRL_SET_SCREENOFF_AUDIO_ENABLE);
        return this;
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable
    public void close() throws IOException {
        this.f1398c.close();
        int i = this.f1400e;
        if (i > 1 || (i == 1 && this.f1399d[i - 1] != 7)) {
            throw new IOException("Incomplete document");
        }
        this.f1400e = 0;
    }

    public final c d(int i, int i2, char c2) throws IOException {
        int iJ = j();
        if (iJ != i2 && iJ != i) {
            throw new IllegalStateException("Nesting problem.");
        }
        if (this.j != null) {
            StringBuilder sbD = c.a.a.a.a.d("Dangling name: ");
            sbD.append(this.j);
            throw new IllegalStateException(sbD.toString());
        }
        this.f1400e--;
        if (iJ == i2) {
            h();
        }
        this.f1398c.write(c2);
        return this;
    }

    public c e() throws IOException {
        d(1, 2, ']');
        return this;
    }

    public c f() throws IOException {
        d(3, 5, '}');
        return this;
    }

    public void flush() throws IOException {
        if (this.f1400e == 0) {
            throw new IllegalStateException("JsonWriter is closed.");
        }
        this.f1398c.flush();
    }

    public c g(String str) {
        Objects.requireNonNull(str, "name == null");
        if (this.j != null) {
            throw new IllegalStateException();
        }
        if (this.f1400e == 0) {
            throw new IllegalStateException("JsonWriter is closed.");
        }
        this.j = str;
        return this;
    }

    public final void h() throws IOException {
        if (this.f1401f == null) {
            return;
        }
        this.f1398c.write(10);
        int i = this.f1400e;
        for (int i2 = 1; i2 < i; i2++) {
            this.f1398c.write(this.f1401f);
        }
    }

    public c i() throws IOException {
        if (this.j != null) {
            if (!this.k) {
                this.j = null;
                return this;
            }
            s();
        }
        a();
        this.f1398c.write("null");
        return this;
    }

    public final int j() {
        int i = this.f1400e;
        if (i != 0) {
            return this.f1399d[i - 1];
        }
        throw new IllegalStateException("JsonWriter is closed.");
    }

    public final void k(int i) {
        int i2 = this.f1400e;
        int[] iArr = this.f1399d;
        if (i2 == iArr.length) {
            this.f1399d = Arrays.copyOf(iArr, i2 * 2);
        }
        int[] iArr2 = this.f1399d;
        int i3 = this.f1400e;
        this.f1400e = i3 + 1;
        iArr2[i3] = i;
    }

    public final void l(int i) {
        this.f1399d[this.f1400e - 1] = i;
    }

    /* JADX WARN: Removed duplicated region for block: B:20:0x0034  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final void m(java.lang.String r9) throws java.io.IOException {
        /*
            r8 = this;
            boolean r0 = r8.i
            if (r0 == 0) goto L7
            java.lang.String[] r0 = c.b.a.w.c.f1397b
            goto L9
        L7:
            java.lang.String[] r0 = c.b.a.w.c.f1396a
        L9:
            java.io.Writer r1 = r8.f1398c
            r2 = 34
            r1.write(r2)
            int r1 = r9.length()
            r3 = 0
            r4 = r3
        L16:
            if (r3 >= r1) goto L45
            char r5 = r9.charAt(r3)
            r6 = 128(0x80, float:1.8E-43)
            if (r5 >= r6) goto L25
            r5 = r0[r5]
            if (r5 != 0) goto L32
            goto L42
        L25:
            r6 = 8232(0x2028, float:1.1535E-41)
            if (r5 != r6) goto L2c
            java.lang.String r5 = "\\u2028"
            goto L32
        L2c:
            r6 = 8233(0x2029, float:1.1537E-41)
            if (r5 != r6) goto L42
            java.lang.String r5 = "\\u2029"
        L32:
            if (r4 >= r3) goto L3b
            java.io.Writer r6 = r8.f1398c
            int r7 = r3 - r4
            r6.write(r9, r4, r7)
        L3b:
            java.io.Writer r4 = r8.f1398c
            r4.write(r5)
            int r4 = r3 + 1
        L42:
            int r3 = r3 + 1
            goto L16
        L45:
            if (r4 >= r1) goto L4d
            java.io.Writer r0 = r8.f1398c
            int r1 = r1 - r4
            r0.write(r9, r4, r1)
        L4d:
            java.io.Writer r8 = r8.f1398c
            r8.write(r2)
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: c.b.a.w.c.m(java.lang.String):void");
    }

    public c n(long j) throws IOException {
        s();
        a();
        this.f1398c.write(Long.toString(j));
        return this;
    }

    public c o(Boolean bool) throws IOException {
        if (bool == null) {
            return i();
        }
        s();
        a();
        this.f1398c.write(bool.booleanValue() ? "true" : "false");
        return this;
    }

    public c p(Number number) throws IOException {
        if (number == null) {
            return i();
        }
        s();
        String string = number.toString();
        if (this.h || !(string.equals("-Infinity") || string.equals("Infinity") || string.equals("NaN"))) {
            a();
            this.f1398c.append((CharSequence) string);
            return this;
        }
        throw new IllegalArgumentException("Numeric values must be finite, but was " + number);
    }

    public c q(String str) throws IOException {
        if (str == null) {
            return i();
        }
        s();
        a();
        m(str);
        return this;
    }

    public c r(boolean z) throws IOException {
        s();
        a();
        this.f1398c.write(z ? "true" : "false");
        return this;
    }

    public final void s() throws IOException {
        if (this.j != null) {
            int iJ = j();
            if (iJ == 5) {
                this.f1398c.write(44);
            } else if (iJ != 3) {
                throw new IllegalStateException("Nesting problem.");
            }
            h();
            l(4);
            m(this.j);
            this.j = null;
        }
    }
}
