discord-jadx/app/src/main/java/okio/ByteString.java

562 lines
20 KiB
Java
Raw Normal View History

2021-08-03 07:33:18 +00:00
package okio;
import d0.g0.c;
import d0.g0.t;
import d0.t.j;
import d0.z.d.m;
import g0.e;
import g0.z.b;
import java.io.EOFException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.util.Arrays;
import kotlin.jvm.internal.DefaultConstructorMarker;
/* compiled from: ByteString.kt */
public class ByteString implements Serializable, Comparable<ByteString> {
public static final ByteString i = new ByteString(new byte[0]);
public static final a j = new a(null);
private static final long serialVersionUID = 1;
private final byte[] data;
public transient int k;
public transient String l;
/* compiled from: ByteString.kt */
public static final class a {
public a(DefaultConstructorMarker defaultConstructorMarker) {
}
public static ByteString d(a aVar, byte[] bArr, int i, int i2, int i3) {
if ((i3 & 1) != 0) {
i = 0;
}
if ((i3 & 2) != 0) {
i2 = bArr.length;
}
m.checkParameterIsNotNull(bArr, "$this$toByteString");
c.q.a.k.a.l((long) bArr.length, (long) i, (long) i2);
return new ByteString(j.copyOfRange(bArr, i, i2 + i));
}
public final ByteString a(String str) {
m.checkParameterIsNotNull(str, "$this$decodeHex");
if (str.length() % 2 == 0) {
int length = str.length() / 2;
byte[] bArr = new byte[length];
for (int i = 0; i < length; i++) {
int i2 = i * 2;
bArr[i] = (byte) (b.a(str.charAt(i2 + 1)) + (b.a(str.charAt(i2)) << 4));
}
return new ByteString(bArr);
}
2021-08-28 06:29:07 +00:00
throw new IllegalArgumentException(c.d.b.a.a.u("Unexpected hex string: ", str).toString());
2021-08-03 07:33:18 +00:00
}
public final ByteString b(String str, Charset charset) {
m.checkParameterIsNotNull(str, "$this$encode");
m.checkParameterIsNotNull(charset, "charset");
byte[] bytes = str.getBytes(charset);
m.checkExpressionValueIsNotNull(bytes, "(this as java.lang.String).getBytes(charset)");
return new ByteString(bytes);
}
public final ByteString c(String str) {
m.checkParameterIsNotNull(str, "$this$encodeUtf8");
m.checkParameterIsNotNull(str, "$this$asUtf8ToByteArray");
byte[] bytes = str.getBytes(c.a);
m.checkExpressionValueIsNotNull(bytes, "(this as java.lang.String).getBytes(charset)");
ByteString byteString = new ByteString(bytes);
byteString.l = str;
return byteString;
}
}
public ByteString(byte[] bArr) {
m.checkParameterIsNotNull(bArr, "data");
this.data = bArr;
}
public static final ByteString h(String str) {
m.checkParameterIsNotNull(str, "$this$encodeUtf8");
m.checkParameterIsNotNull(str, "$this$asUtf8ToByteArray");
byte[] bytes = str.getBytes(c.a);
m.checkExpressionValueIsNotNull(bytes, "(this as java.lang.String).getBytes(charset)");
ByteString byteString = new ByteString(bytes);
byteString.l = str;
return byteString;
}
private final void readObject(ObjectInputStream objectInputStream) throws IOException {
int readInt = objectInputStream.readInt();
m.checkParameterIsNotNull(objectInputStream, "$this$readByteString");
int i2 = 0;
if (readInt >= 0) {
byte[] bArr = new byte[readInt];
while (i2 < readInt) {
int read = objectInputStream.read(bArr, i2, readInt - i2);
if (read != -1) {
i2 += read;
} else {
throw new EOFException();
}
}
ByteString byteString = new ByteString(bArr);
Field declaredField = ByteString.class.getDeclaredField("data");
m.checkExpressionValueIsNotNull(declaredField, "field");
declaredField.setAccessible(true);
declaredField.set(this, byteString.data);
return;
}
2021-08-28 06:29:07 +00:00
throw new IllegalArgumentException(c.d.b.a.a.l("byteCount < 0: ", readInt).toString());
2021-08-03 07:33:18 +00:00
}
private final void writeObject(ObjectOutputStream objectOutputStream) throws IOException {
objectOutputStream.writeInt(this.data.length);
objectOutputStream.write(this.data);
}
/* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
/* JADX WARNING: Removed duplicated region for block: B:8:0x0030 A[RETURN, SYNTHETIC] */
/* JADX WARNING: Removed duplicated region for block: B:9:0x0032 A[ORIG_RETURN, RETURN, SYNTHETIC] */
@Override // java.lang.Comparable
public int compareTo(ByteString byteString) {
ByteString byteString2 = byteString;
m.checkParameterIsNotNull(byteString2, "other");
int j2 = j();
int j3 = byteString2.j();
int min = Math.min(j2, j3);
for (int i2 = 0; i2 < min; i2++) {
int m = m(i2) & 255;
int m2 = byteString2.m(i2) & 255;
if (m != m2) {
return m < m2 ? -1 : 1;
}
}
if (j2 == j3) {
return 0;
}
if (j2 < j3) {
}
}
@Override // java.lang.Object
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof ByteString) {
ByteString byteString = (ByteString) obj;
int j2 = byteString.j();
byte[] bArr = this.data;
if (j2 == bArr.length && byteString.o(0, bArr, 0, bArr.length)) {
return true;
}
}
return false;
}
public String f() {
byte[] bArr = this.data;
byte[] bArr2 = g0.a.a;
byte[] bArr3 = g0.a.a;
m.checkParameterIsNotNull(bArr, "$this$encodeBase64");
m.checkParameterIsNotNull(bArr3, "map");
byte[] bArr4 = new byte[(((bArr.length + 2) / 3) * 4)];
int length = bArr.length - (bArr.length % 3);
int i2 = 0;
int i3 = 0;
while (i2 < length) {
int i4 = i2 + 1;
byte b = bArr[i2];
int i5 = i4 + 1;
byte b2 = bArr[i4];
int i6 = i5 + 1;
byte b3 = bArr[i5];
int i7 = i3 + 1;
bArr4[i3] = bArr3[(b & 255) >> 2];
int i8 = i7 + 1;
bArr4[i7] = bArr3[((b & 3) << 4) | ((b2 & 255) >> 4)];
int i9 = i8 + 1;
bArr4[i8] = bArr3[((b2 & 15) << 2) | ((b3 & 255) >> 6)];
i3 = i9 + 1;
bArr4[i9] = bArr3[b3 & 63];
i2 = i6;
}
int length2 = bArr.length - length;
if (length2 == 1) {
byte b4 = bArr[i2];
int i10 = i3 + 1;
bArr4[i3] = bArr3[(b4 & 255) >> 2];
int i11 = i10 + 1;
bArr4[i10] = bArr3[(b4 & 3) << 4];
byte b5 = (byte) 61;
bArr4[i11] = b5;
bArr4[i11 + 1] = b5;
} else if (length2 == 2) {
int i12 = i2 + 1;
byte b6 = bArr[i2];
byte b7 = bArr[i12];
int i13 = i3 + 1;
bArr4[i3] = bArr3[(b6 & 255) >> 2];
int i14 = i13 + 1;
bArr4[i13] = bArr3[((b6 & 3) << 4) | ((b7 & 255) >> 4)];
bArr4[i14] = bArr3[(b7 & 15) << 2];
bArr4[i14 + 1] = (byte) 61;
}
m.checkParameterIsNotNull(bArr4, "$this$toUtf8String");
return new String(bArr4, c.a);
}
public ByteString g(String str) {
m.checkParameterIsNotNull(str, "algorithm");
byte[] digest = MessageDigest.getInstance(str).digest(this.data);
m.checkExpressionValueIsNotNull(digest, "MessageDigest.getInstance(algorithm).digest(data)");
return new ByteString(digest);
}
@Override // java.lang.Object
public int hashCode() {
int i2 = this.k;
if (i2 != 0) {
return i2;
}
int hashCode = Arrays.hashCode(this.data);
this.k = hashCode;
return hashCode;
}
public final byte[] i() {
return this.data;
}
public int j() {
return this.data.length;
}
public String k() {
byte[] bArr = this.data;
char[] cArr = new char[(bArr.length * 2)];
int i2 = 0;
for (byte b : bArr) {
int i3 = i2 + 1;
char[] cArr2 = b.a;
cArr[i2] = cArr2[(b >> 4) & 15];
i2 = i3 + 1;
cArr[i3] = cArr2[b & 15];
}
return new String(cArr);
}
public byte[] l() {
return this.data;
}
public byte m(int i2) {
return this.data[i2];
}
public boolean n(int i2, ByteString byteString, int i3, int i4) {
m.checkParameterIsNotNull(byteString, "other");
return byteString.o(i3, this.data, i2, i4);
}
public boolean o(int i2, byte[] bArr, int i3, int i4) {
m.checkParameterIsNotNull(bArr, "other");
if (i2 >= 0) {
byte[] bArr2 = this.data;
if (i2 <= bArr2.length - i4 && i3 >= 0 && i3 <= bArr.length - i4 && c.q.a.k.a.e(bArr2, i2, bArr, i3, i4)) {
return true;
}
}
return false;
}
public ByteString p() {
byte b;
int i2 = 0;
while (true) {
byte[] bArr = this.data;
if (i2 >= bArr.length) {
return this;
}
byte b2 = bArr[i2];
byte b3 = (byte) 65;
if (b2 < b3 || b2 > (b = (byte) 90)) {
i2++;
} else {
byte[] copyOf = Arrays.copyOf(bArr, bArr.length);
m.checkExpressionValueIsNotNull(copyOf, "java.util.Arrays.copyOf(this, size)");
copyOf[i2] = (byte) (b2 + 32);
for (int i3 = i2 + 1; i3 < copyOf.length; i3++) {
byte b4 = copyOf[i3];
if (b4 >= b3 && b4 <= b) {
copyOf[i3] = (byte) (b4 + 32);
}
}
return new ByteString(copyOf);
}
}
}
public String q() {
String str = this.l;
if (str != null) {
return str;
}
byte[] l = l();
m.checkParameterIsNotNull(l, "$this$toUtf8String");
String str2 = new String(l, c.a);
this.l = str2;
return str2;
}
public void r(OutputStream outputStream) throws IOException {
m.checkParameterIsNotNull(outputStream, "out");
outputStream.write(this.data);
}
public void s(e eVar, int i2, int i3) {
m.checkParameterIsNotNull(eVar, "buffer");
m.checkParameterIsNotNull(this, "$this$commonWrite");
m.checkParameterIsNotNull(eVar, "buffer");
eVar.S(this.data, i2, i3);
}
/* JADX WARNING: Code restructure failed: missing block: B:101:0x0120, code lost:
if (r4 == 64) goto L_0x01ef;
*/
/* JADX WARNING: Code restructure failed: missing block: B:127:0x015e, code lost:
if (r4 == 64) goto L_0x01ef;
*/
/* JADX WARNING: Code restructure failed: missing block: B:133:0x0171, code lost:
if (r4 == 64) goto L_0x01ef;
*/
/* JADX WARNING: Code restructure failed: missing block: B:139:0x0182, code lost:
if (r4 == 64) goto L_0x01ef;
*/
/* JADX WARNING: Code restructure failed: missing block: B:145:0x0191, code lost:
if (r4 == 64) goto L_0x01ef;
*/
/* JADX WARNING: Code restructure failed: missing block: B:148:0x01a7, code lost:
if (r4 == 64) goto L_0x01ef;
*/
/* JADX WARNING: Code restructure failed: missing block: B:151:0x01af, code lost:
if (r4 == 64) goto L_0x01ef;
*/
/* JADX WARNING: Code restructure failed: missing block: B:154:0x01b6, code lost:
if (r4 == 64) goto L_0x01ef;
*/
/* JADX WARNING: Code restructure failed: missing block: B:177:0x01eb, code lost:
if (r4 == 64) goto L_0x01ef;
*/
/* JADX WARNING: Code restructure failed: missing block: B:178:0x01ee, code lost:
r5 = -1;
*/
/* JADX WARNING: Code restructure failed: missing block: B:51:0x0089, code lost:
if (r4 == 64) goto L_0x01ef;
*/
/* JADX WARNING: Code restructure failed: missing block: B:57:0x009a, code lost:
if (r4 == 64) goto L_0x01ef;
*/
/* JADX WARNING: Code restructure failed: missing block: B:60:0x00a5, code lost:
if (r4 == 64) goto L_0x01ef;
*/
/* JADX WARNING: Code restructure failed: missing block: B:83:0x00e3, code lost:
if (r4 == 64) goto L_0x01ef;
*/
/* JADX WARNING: Code restructure failed: missing block: B:89:0x00f6, code lost:
if (r4 == 64) goto L_0x01ef;
*/
/* JADX WARNING: Code restructure failed: missing block: B:95:0x0105, code lost:
if (r4 == 64) goto L_0x01ef;
*/
/* JADX WARNING: Code restructure failed: missing block: B:98:0x0117, code lost:
if (r4 == 64) goto L_0x01ef;
*/
@Override // java.lang.Object
public String toString() {
byte[] bArr = this.data;
if (bArr.length == 0) {
return "[size=0]";
}
int length = bArr.length;
int i2 = 0;
int i3 = 0;
int i4 = 0;
loop0:
while (true) {
if (i2 >= length) {
break;
}
byte b = bArr[i2];
if (b >= 0) {
int i5 = i3 + 1;
if (i3 == 64) {
break;
}
if (!(b == 10 || b == 13)) {
if ((b >= 0 && 31 >= b) || (Byte.MAX_VALUE <= b && 159 >= b)) {
break;
}
}
if (b == 65533) {
break;
}
i4 += b < 65536 ? 1 : 2;
i2++;
while (true) {
i3 = i5;
if (i2 >= length || bArr[i2] < 0) {
break;
}
int i6 = i2 + 1;
byte b2 = bArr[i2];
i5 = i3 + 1;
if (i3 == 64) {
break loop0;
}
if (!(b2 == 10 || b2 == 13)) {
if ((b2 >= 0 && 31 >= b2) || (Byte.MAX_VALUE <= b2 && 159 >= b2)) {
break loop0;
}
}
if (b2 == 65533) {
break loop0;
}
i4 += b2 < 65536 ? 1 : 2;
i2 = i6;
}
} else if ((b >> 5) == -2) {
int i7 = i2 + 1;
if (length > i7) {
byte b3 = bArr[i2];
byte b4 = bArr[i7];
if ((b4 & 192) == 128) {
int i8 = (b4 ^ 3968) ^ (b3 << 6);
if (i8 >= 128) {
int i9 = i3 + 1;
if (i3 == 64) {
break;
}
if (!(i8 == 10 || i8 == 13)) {
if ((i8 >= 0 && 31 >= i8) || (127 <= i8 && 159 >= i8)) {
break;
}
}
if (i8 == 65533) {
break;
}
i4 += i8 < 65536 ? 1 : 2;
i2 += 2;
i3 = i9;
}
}
}
} else if ((b >> 4) == -2) {
int i10 = i2 + 2;
if (length > i10) {
byte b5 = bArr[i2];
byte b6 = bArr[i2 + 1];
if ((b6 & 192) == 128) {
byte b7 = bArr[i10];
if ((b7 & 192) == 128) {
int i11 = ((b7 ^ -123008) ^ (b6 << 6)) ^ (b5 << 12);
if (i11 >= 2048) {
if (55296 > i11 || 57343 < i11) {
int i12 = i3 + 1;
if (i3 == 64) {
break;
}
if (!(i11 == 10 || i11 == 13)) {
if ((i11 >= 0 && 31 >= i11) || (127 <= i11 && 159 >= i11)) {
break;
}
}
if (i11 == 65533) {
break;
}
i4 += i11 < 65536 ? 1 : 2;
i2 += 3;
i3 = i12;
}
}
}
}
}
} else if ((b >> 3) == -2) {
int i13 = i2 + 3;
if (length > i13) {
byte b8 = bArr[i2];
byte b9 = bArr[i2 + 1];
if ((b9 & 192) == 128) {
byte b10 = bArr[i2 + 2];
if ((b10 & 192) == 128) {
byte b11 = bArr[i13];
if ((b11 & 192) == 128) {
int i14 = (((b11 ^ 3678080) ^ (b10 << 6)) ^ (b9 << 12)) ^ (b8 << 18);
if (i14 <= 1114111) {
if (55296 > i14 || 57343 < i14) {
if (i14 >= 65536) {
int i15 = i3 + 1;
if (i3 == 64) {
break;
}
if (!(i14 == 10 || i14 == 13)) {
if ((i14 >= 0 && 31 >= i14) || (127 <= i14 && 159 >= i14)) {
break;
}
}
if (i14 == 65533) {
break;
}
i4 += i14 < 65536 ? 1 : 2;
i2 += 4;
i3 = i15;
}
}
}
}
}
}
}
}
}
if (i4 != -1) {
String q = q();
String substring = q.substring(0, i4);
m.checkExpressionValueIsNotNull(substring, "(this as java.lang.Strin…ing(startIndex, endIndex)");
String replace$default = t.replace$default(t.replace$default(t.replace$default(substring, "\\", "\\\\", false, 4, (Object) null), "\n", "\\n", false, 4, (Object) null), "\r", "\\r", false, 4, (Object) null);
if (i4 < q.length()) {
2021-10-09 06:29:02 +00:00
StringBuilder O = c.d.b.a.a.O("[size=");
O.append(this.data.length);
O.append(" text=");
O.append(replace$default);
O.append("…]");
return O.toString();
2021-08-03 07:33:18 +00:00
}
return "[text=" + replace$default + ']';
} else if (this.data.length <= 64) {
2021-10-09 06:29:02 +00:00
StringBuilder O2 = c.d.b.a.a.O("[hex=");
O2.append(k());
O2.append(']');
return O2.toString();
2021-08-03 07:33:18 +00:00
} else {
2021-10-09 06:29:02 +00:00
StringBuilder O3 = c.d.b.a.a.O("[size=");
O3.append(this.data.length);
O3.append(" hex=");
2021-08-03 07:33:18 +00:00
byte[] bArr2 = this.data;
if (64 <= bArr2.length) {
2021-10-09 06:29:02 +00:00
O3.append((64 == bArr2.length ? this : new ByteString(j.copyOfRange(bArr2, 0, 64))).k());
O3.append("…]");
return O3.toString();
2021-08-03 07:33:18 +00:00
}
2021-10-09 06:29:02 +00:00
throw new IllegalArgumentException(c.d.b.a.a.y(c.d.b.a.a.O("endIndex > length("), this.data.length, ')').toString());
2021-08-03 07:33:18 +00:00
}
}
}