discord-jadx/app/src/main/java/com/google/gson/stream/JsonWriter.java

292 lines
7.4 KiB
Java

package com.google.gson.stream;
import c.d.b.a.a;
import java.io.Closeable;
import java.io.Flushable;
import java.io.IOException;
import java.io.Writer;
import java.util.Arrays;
import java.util.Objects;
public class JsonWriter implements Closeable, Flushable {
public static final String[] i = new String[128];
public static final String[] j;
public final Writer k;
public int[] l = new int[32];
public int m = 0;
public String n;
public String o;
public boolean p;
public boolean q;
public String r;
/* renamed from: s reason: collision with root package name */
public boolean f2384s;
static {
for (int i2 = 0; i2 <= 31; i2++) {
i[i2] = String.format("\\u%04x", Integer.valueOf(i2));
}
String[] strArr = i;
strArr[34] = "\\\"";
strArr[92] = "\\\\";
strArr[9] = "\\t";
strArr[8] = "\\b";
strArr[10] = "\\n";
strArr[13] = "\\r";
strArr[12] = "\\f";
String[] strArr2 = (String[]) strArr.clone();
j = strArr2;
strArr2[60] = "\\u003c";
strArr2[62] = "\\u003e";
strArr2[38] = "\\u0026";
strArr2[61] = "\\u003d";
strArr2[39] = "\\u0027";
}
public JsonWriter(Writer writer) {
w(6);
this.o = ":";
this.f2384s = true;
Objects.requireNonNull(writer, "out == null");
this.k = writer;
}
public JsonWriter B(long j2) throws IOException {
K();
a();
this.k.write(Long.toString(j2));
return this;
}
public JsonWriter C(Boolean bool) throws IOException {
if (bool == null) {
return s();
}
K();
a();
this.k.write(bool.booleanValue() ? "true" : "false");
return this;
}
public JsonWriter G(Number number) throws IOException {
if (number == null) {
return s();
}
K();
String obj = number.toString();
if (this.p || (!obj.equals("-Infinity") && !obj.equals("Infinity") && !obj.equals("NaN"))) {
a();
this.k.append((CharSequence) obj);
return this;
}
throw new IllegalArgumentException("Numeric values must be finite, but was " + number);
}
public JsonWriter H(String str) throws IOException {
if (str == null) {
return s();
}
K();
a();
z(str);
return this;
}
public JsonWriter I(boolean z2) throws IOException {
K();
a();
this.k.write(z2 ? "true" : "false");
return this;
}
public final void K() throws IOException {
if (this.r != null) {
int t = t();
if (t == 5) {
this.k.write(44);
} else if (t != 3) {
throw new IllegalStateException("Nesting problem.");
}
r();
x(4);
z(this.r);
this.r = null;
}
}
public final void a() throws IOException {
int t = t();
if (t == 1) {
x(2);
r();
} else if (t == 2) {
this.k.append(',');
r();
} else if (t != 4) {
if (t != 6) {
if (t != 7) {
throw new IllegalStateException("Nesting problem.");
} else if (!this.p) {
throw new IllegalStateException("JSON must have only one top-level value.");
}
}
x(7);
} else {
this.k.append((CharSequence) this.o);
x(5);
}
}
public JsonWriter b() throws IOException {
K();
a();
w(1);
this.k.write(91);
return this;
}
public JsonWriter c() throws IOException {
K();
a();
w(3);
this.k.write(123);
return this;
}
@Override // java.io.Closeable, java.lang.AutoCloseable
public void close() throws IOException {
this.k.close();
int i2 = this.m;
if (i2 > 1 || (i2 == 1 && this.l[i2 - 1] != 7)) {
throw new IOException("Incomplete document");
}
this.m = 0;
}
public final JsonWriter d(int i2, int i3, char c2) throws IOException {
int t = t();
if (t != i3 && t != i2) {
throw new IllegalStateException("Nesting problem.");
} else if (this.r == null) {
this.m--;
if (t == i3) {
r();
}
this.k.write(c2);
return this;
} else {
StringBuilder L = a.L("Dangling name: ");
L.append(this.r);
throw new IllegalStateException(L.toString());
}
}
public JsonWriter e() throws IOException {
d(1, 2, ']');
return this;
}
public JsonWriter f() throws IOException {
d(3, 5, '}');
return this;
}
@Override // java.io.Flushable
public void flush() throws IOException {
if (this.m != 0) {
this.k.flush();
return;
}
throw new IllegalStateException("JsonWriter is closed.");
}
public JsonWriter p(String str) throws IOException {
Objects.requireNonNull(str, "name == null");
if (this.r != null) {
throw new IllegalStateException();
} else if (this.m != 0) {
this.r = str;
return this;
} else {
throw new IllegalStateException("JsonWriter is closed.");
}
}
public final void r() throws IOException {
if (this.n != null) {
this.k.write(10);
int i2 = this.m;
for (int i3 = 1; i3 < i2; i3++) {
this.k.write(this.n);
}
}
}
public JsonWriter s() throws IOException {
if (this.r != null) {
if (this.f2384s) {
K();
} else {
this.r = null;
return this;
}
}
a();
this.k.write("null");
return this;
}
public final int t() {
int i2 = this.m;
if (i2 != 0) {
return this.l[i2 - 1];
}
throw new IllegalStateException("JsonWriter is closed.");
}
public final void w(int i2) {
int i3 = this.m;
int[] iArr = this.l;
if (i3 == iArr.length) {
this.l = Arrays.copyOf(iArr, i3 * 2);
}
int[] iArr2 = this.l;
int i4 = this.m;
this.m = i4 + 1;
iArr2[i4] = i2;
}
public final void x(int i2) {
this.l[this.m - 1] = i2;
}
public final void z(String str) throws IOException {
String str2;
String[] strArr = this.q ? j : i;
this.k.write(34);
int length = str.length();
int i2 = 0;
for (int i3 = 0; i3 < length; i3++) {
char charAt = str.charAt(i3);
if (charAt < 128) {
str2 = strArr[charAt];
if (str2 == null) {
}
} else if (charAt == 8232) {
str2 = "\\u2028";
} else if (charAt == 8233) {
str2 = "\\u2029";
}
if (i2 < i3) {
this.k.write(str, i2, i3 - i2);
}
this.k.write(str2);
i2 = i3 + 1;
}
if (i2 < length) {
this.k.write(str, i2, length - i2);
}
this.k.write(34);
}
}