package p138.p395.p396;

import java.io.IOException;
import javax.annotation.Nullable;
import p138.p139.p143.p144.C2803;
import p461.InterfaceC7106;

/* JADX INFO: renamed from: ދ.ބ.֏.ޑ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C6495 extends AbstractC6497 {

    /* JADX INFO: renamed from: ގ, reason: contains not printable characters */
    public static final String[] f19215 = new String[128];

    /* JADX INFO: renamed from: ދ, reason: contains not printable characters */
    public final InterfaceC7106 f19216;

    /* JADX INFO: renamed from: ތ, reason: contains not printable characters */
    public String f19217 = ":";

    /* JADX INFO: renamed from: ލ, reason: contains not printable characters */
    public String f19218;

    static {
        for (int i = 0; i <= 31; i++) {
            f19215[i] = String.format("\\u%04x", Integer.valueOf(i));
        }
        String[] strArr = f19215;
        strArr[34] = "\\\"";
        strArr[92] = "\\\\";
        strArr[9] = "\\t";
        strArr[8] = "\\b";
        strArr[10] = "\\n";
        strArr[13] = "\\r";
        strArr[12] = "\\f";
    }

    public C6495(InterfaceC7106 interfaceC7106) {
        if (interfaceC7106 == null) {
            throw new NullPointerException("sink == null");
        }
        this.f19216 = interfaceC7106;
        m9730(6);
    }

    /* JADX WARN: Removed duplicated region for block: B:16:0x002b  */
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static void m9713(InterfaceC7106 interfaceC7106, String str) {
        String str2;
        String[] strArr = f19215;
        interfaceC7106.writeByte(34);
        int length = str.length();
        int i = 0;
        for (int i2 = 0; i2 < length; i2++) {
            char cCharAt = str.charAt(i2);
            if (cCharAt < 128) {
                str2 = strArr[cCharAt];
                if (str2 != null) {
                    if (i < i2) {
                        interfaceC7106.mo10415(str, i, i2);
                    }
                    interfaceC7106.mo10414(str2);
                    i = i2 + 1;
                }
            } else {
                if (cCharAt == 8232) {
                    str2 = "\\u2028";
                } else if (cCharAt == 8233) {
                    str2 = "\\u2029";
                }
                if (i < i2) {
                }
                interfaceC7106.mo10414(str2);
                i = i2 + 1;
            }
        }
        if (i < length) {
            interfaceC7106.mo10415(str, i, length);
        }
        interfaceC7106.writeByte(34);
    }

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

    @Override // java.io.Flushable
    public void flush() {
        if (this.f19221 == 0) {
            throw new IllegalStateException("JsonWriter is closed.");
        }
        this.f19216.flush();
    }

    @Override // p138.p395.p396.AbstractC6497
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public AbstractC6497 mo9714() {
        if (this.f19227) {
            StringBuilder sbM4889 = C2803.m4889("Array cannot be used as a map key in JSON at path ");
            sbM4889.append(m9732());
            throw new IllegalStateException(sbM4889.toString());
        }
        m9728();
        m9720(1, 2, '[');
        return this;
    }

    @Override // p138.p395.p396.AbstractC6497
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public AbstractC6497 mo9715(double d) {
        if (!this.f19225 && (Double.isNaN(d) || Double.isInfinite(d))) {
            throw new IllegalArgumentException("Numeric values must be finite, but was " + d);
        }
        if (this.f19227) {
            mo9721(Double.toString(d));
            return this;
        }
        m9728();
        m9727();
        this.f19216.mo10414(Double.toString(d));
        int[] iArr = this.f19224;
        int i = this.f19221 - 1;
        iArr[i] = iArr[i] + 1;
        return this;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final AbstractC6497 m9716(int i, int i2, char c) {
        int iM9733 = m9733();
        if (iM9733 != i2 && iM9733 != i) {
            throw new IllegalStateException("Nesting problem.");
        }
        if (this.f19218 != null) {
            StringBuilder sbM4889 = C2803.m4889("Dangling name: ");
            sbM4889.append(this.f19218);
            throw new IllegalStateException(sbM4889.toString());
        }
        int i3 = this.f19221;
        int i4 = this.f19228;
        if (i3 == (~i4)) {
            this.f19228 = ~i4;
            return this;
        }
        int i5 = i3 - 1;
        this.f19221 = i5;
        this.f19223[i5] = null;
        int[] iArr = this.f19224;
        int i6 = i5 - 1;
        iArr[i6] = iArr[i6] + 1;
        this.f19216.writeByte(c);
        return this;
    }

    @Override // p138.p395.p396.AbstractC6497
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public AbstractC6497 mo9717(@Nullable Number number) {
        if (number == null) {
            mo9725();
            return this;
        }
        String string = number.toString();
        if (!this.f19225 && (string.equals("-Infinity") || string.equals("Infinity") || string.equals("NaN"))) {
            throw new IllegalArgumentException("Numeric values must be finite, but was " + number);
        }
        if (this.f19227) {
            mo9721(string);
            return this;
        }
        m9728();
        m9727();
        this.f19216.mo10414(string);
        int[] iArr = this.f19224;
        int i = this.f19221 - 1;
        iArr[i] = iArr[i] + 1;
        return this;
    }

    @Override // p138.p395.p396.AbstractC6497
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public AbstractC6497 mo9718(boolean z) {
        if (this.f19227) {
            StringBuilder sbM4889 = C2803.m4889("Boolean cannot be used as a map key in JSON at path ");
            sbM4889.append(m9732());
            throw new IllegalStateException(sbM4889.toString());
        }
        m9728();
        m9727();
        this.f19216.mo10414(z ? "true" : "false");
        int[] iArr = this.f19224;
        int i = this.f19221 - 1;
        iArr[i] = iArr[i] + 1;
        return this;
    }

    @Override // p138.p395.p396.AbstractC6497
    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public AbstractC6497 mo9719() {
        if (this.f19227) {
            StringBuilder sbM4889 = C2803.m4889("Object cannot be used as a map key in JSON at path ");
            sbM4889.append(m9732());
            throw new IllegalStateException(sbM4889.toString());
        }
        m9728();
        m9720(3, 5, '{');
        return this;
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final AbstractC6497 m9720(int i, int i2, char c) {
        int i3 = this.f19221;
        if (i3 == this.f19228) {
            int[] iArr = this.f19222;
            if (iArr[i3 - 1] == i || iArr[i3 - 1] == i2) {
                this.f19228 = ~this.f19228;
                return this;
            }
        }
        m9727();
        m9731();
        int[] iArr2 = this.f19222;
        int i4 = this.f19221;
        int i5 = i4 + 1;
        this.f19221 = i5;
        iArr2[i4] = i;
        this.f19224[i5 - 1] = 0;
        this.f19216.writeByte(c);
        return this;
    }

    @Override // p138.p395.p396.AbstractC6497
    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public AbstractC6497 mo9721(String str) {
        if (str == null) {
            throw new NullPointerException("name == null");
        }
        if (this.f19221 == 0) {
            throw new IllegalStateException("JsonWriter is closed.");
        }
        int iM9733 = m9733();
        if ((iM9733 != 3 && iM9733 != 5) || this.f19218 != null) {
            throw new IllegalStateException("Nesting problem.");
        }
        this.f19218 = str;
        this.f19223[this.f19221 - 1] = str;
        this.f19227 = false;
        return this;
    }

    @Override // p138.p395.p396.AbstractC6497
    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public AbstractC6497 mo9722(String str) {
        if (str == null) {
            mo9725();
            return this;
        }
        if (this.f19227) {
            mo9721(str);
            return this;
        }
        m9728();
        m9727();
        m9713(this.f19216, str);
        int[] iArr = this.f19224;
        int i = this.f19221 - 1;
        iArr[i] = iArr[i] + 1;
        return this;
    }

    @Override // p138.p395.p396.AbstractC6497
    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public AbstractC6497 mo9723() {
        m9716(1, 2, ']');
        return this;
    }

    @Override // p138.p395.p396.AbstractC6497
    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public AbstractC6497 mo9724() {
        this.f19227 = false;
        m9716(3, 5, '}');
        return this;
    }

    @Override // p138.p395.p396.AbstractC6497
    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public AbstractC6497 mo9725() {
        if (this.f19227) {
            StringBuilder sbM4889 = C2803.m4889("null cannot be used as a map key in JSON at path ");
            sbM4889.append(m9732());
            throw new IllegalStateException(sbM4889.toString());
        }
        if (this.f19218 != null) {
            if (!this.f19226) {
                this.f19218 = null;
                return this;
            }
            m9728();
        }
        m9727();
        this.f19216.mo10414("null");
        int[] iArr = this.f19224;
        int i = this.f19221 - 1;
        iArr[i] = iArr[i] + 1;
        return this;
    }

    @Override // p138.p395.p396.AbstractC6497
    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public AbstractC6497 mo9726(long j) {
        if (this.f19227) {
            mo9721(Long.toString(j));
            return this;
        }
        m9728();
        m9727();
        this.f19216.mo10414(Long.toString(j));
        int[] iArr = this.f19224;
        int i = this.f19221 - 1;
        iArr[i] = iArr[i] + 1;
        return this;
    }

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public final void m9727() {
        int iM9733 = m9733();
        int i = 2;
        if (iM9733 != 1) {
            if (iM9733 == 2) {
                this.f19216.writeByte(44);
            } else if (iM9733 == 4) {
                i = 5;
                this.f19216.mo10414(this.f19217);
            } else {
                if (iM9733 == 9) {
                    throw new IllegalStateException("Sink from valueSink() was not closed");
                }
                if (iM9733 != 6) {
                    if (iM9733 != 7) {
                        throw new IllegalStateException("Nesting problem.");
                    }
                    if (!this.f19225) {
                        throw new IllegalStateException("JSON must have only one top-level value.");
                    }
                }
                i = 7;
            }
        }
        this.f19222[this.f19221 - 1] = i;
    }

    /* JADX INFO: renamed from: ލ, reason: contains not printable characters */
    public final void m9728() {
        if (this.f19218 != null) {
            int iM9733 = m9733();
            if (iM9733 == 5) {
                this.f19216.writeByte(44);
            } else if (iM9733 != 3) {
                throw new IllegalStateException("Nesting problem.");
            }
            this.f19222[this.f19221 - 1] = 4;
            m9713(this.f19216, this.f19218);
            this.f19218 = null;
        }
    }
}
