discord-jadx/app/src/main/java/androidx/versionedparcelable/VersionedParcelStream.java

550 lines
19 KiB
Java

package androidx.versionedparcelable;
import android.os.Bundle;
import android.os.IBinder;
import android.os.IInterface;
import android.os.Parcelable;
import androidx.annotation.RestrictTo;
import androidx.collection.ArrayMap;
import androidx.versionedparcelable.VersionedParcel;
import c.d.b.a.a;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.nio.charset.Charset;
import java.util.Set;
@RestrictTo({RestrictTo.Scope.LIBRARY})
public class VersionedParcelStream extends VersionedParcel {
private static final int TYPE_BOOLEAN = 5;
private static final int TYPE_BOOLEAN_ARRAY = 6;
private static final int TYPE_DOUBLE = 7;
private static final int TYPE_DOUBLE_ARRAY = 8;
private static final int TYPE_FLOAT = 13;
private static final int TYPE_FLOAT_ARRAY = 14;
private static final int TYPE_INT = 9;
private static final int TYPE_INT_ARRAY = 10;
private static final int TYPE_LONG = 11;
private static final int TYPE_LONG_ARRAY = 12;
private static final int TYPE_NULL = 0;
private static final int TYPE_STRING = 3;
private static final int TYPE_STRING_ARRAY = 4;
private static final int TYPE_SUB_BUNDLE = 1;
private static final int TYPE_SUB_PERSISTABLE_BUNDLE = 2;
private static final Charset UTF_16 = Charset.forName("UTF-16");
public int mCount;
private DataInputStream mCurrentInput;
private DataOutputStream mCurrentOutput;
private FieldBuffer mFieldBuffer;
private int mFieldId;
public int mFieldSize;
private boolean mIgnoreParcelables;
private final DataInputStream mMasterInput;
private final DataOutputStream mMasterOutput;
/* renamed from: androidx.versionedparcelable.VersionedParcelStream$1 reason: invalid class name */
public class AnonymousClass1 extends FilterInputStream {
public AnonymousClass1(InputStream inputStream) {
super(inputStream);
}
@Override // java.io.FilterInputStream, java.io.InputStream
public int read() throws IOException {
VersionedParcelStream versionedParcelStream = VersionedParcelStream.this;
int i = versionedParcelStream.mFieldSize;
if (i == -1 || versionedParcelStream.mCount < i) {
int read = super.read();
VersionedParcelStream.this.mCount++;
return read;
}
throw new IOException();
}
@Override // java.io.FilterInputStream, java.io.InputStream
public int read(byte[] bArr, int i, int i2) throws IOException {
VersionedParcelStream versionedParcelStream = VersionedParcelStream.this;
int i3 = versionedParcelStream.mFieldSize;
if (i3 == -1 || versionedParcelStream.mCount < i3) {
int read = super.read(bArr, i, i2);
if (read > 0) {
VersionedParcelStream.this.mCount += read;
}
return read;
}
throw new IOException();
}
@Override // java.io.FilterInputStream, java.io.InputStream
public long skip(long j) throws IOException {
VersionedParcelStream versionedParcelStream = VersionedParcelStream.this;
int i = versionedParcelStream.mFieldSize;
if (i == -1 || versionedParcelStream.mCount < i) {
long skip = super.skip(j);
if (skip > 0) {
VersionedParcelStream.this.mCount += (int) skip;
}
return skip;
}
throw new IOException();
}
}
public static class FieldBuffer {
public final DataOutputStream mDataStream;
private final int mFieldId;
public final ByteArrayOutputStream mOutput;
private final DataOutputStream mTarget;
public FieldBuffer(int i, DataOutputStream dataOutputStream) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
this.mOutput = byteArrayOutputStream;
this.mDataStream = new DataOutputStream(byteArrayOutputStream);
this.mFieldId = i;
this.mTarget = dataOutputStream;
}
public void flushField() throws IOException {
this.mDataStream.flush();
int size = this.mOutput.size();
this.mTarget.writeInt((this.mFieldId << 16) | (size >= 65535 ? 65535 : size));
if (size >= 65535) {
this.mTarget.writeInt(size);
}
this.mOutput.writeTo(this.mTarget);
}
}
public VersionedParcelStream(InputStream inputStream, OutputStream outputStream) {
this(inputStream, outputStream, new ArrayMap(), new ArrayMap(), new ArrayMap());
}
private VersionedParcelStream(InputStream inputStream, OutputStream outputStream, ArrayMap<String, Method> arrayMap, ArrayMap<String, Method> arrayMap2, ArrayMap<String, Class> arrayMap3) {
super(arrayMap, arrayMap2, arrayMap3);
this.mCount = 0;
this.mFieldId = -1;
this.mFieldSize = -1;
DataOutputStream dataOutputStream = null;
DataInputStream dataInputStream = inputStream != null ? new DataInputStream(new AnonymousClass1(inputStream)) : null;
this.mMasterInput = dataInputStream;
dataOutputStream = outputStream != null ? new DataOutputStream(outputStream) : dataOutputStream;
this.mMasterOutput = dataOutputStream;
this.mCurrentInput = dataInputStream;
this.mCurrentOutput = dataOutputStream;
}
private void readObject(int i, String str, Bundle bundle) {
switch (i) {
case 0:
bundle.putParcelable(str, null);
return;
case 1:
bundle.putBundle(str, readBundle());
return;
case 2:
bundle.putBundle(str, readBundle());
return;
case 3:
bundle.putString(str, readString());
return;
case 4:
bundle.putStringArray(str, (String[]) readArray(new String[0]));
return;
case 5:
bundle.putBoolean(str, readBoolean());
return;
case 6:
bundle.putBooleanArray(str, readBooleanArray());
return;
case 7:
bundle.putDouble(str, readDouble());
return;
case 8:
bundle.putDoubleArray(str, readDoubleArray());
return;
case 9:
bundle.putInt(str, readInt());
return;
case 10:
bundle.putIntArray(str, readIntArray());
return;
case 11:
bundle.putLong(str, readLong());
return;
case 12:
bundle.putLongArray(str, readLongArray());
return;
case 13:
bundle.putFloat(str, readFloat());
return;
case 14:
bundle.putFloatArray(str, readFloatArray());
return;
default:
throw new RuntimeException(a.k("Unknown type ", i));
}
}
private void writeObject(Object obj) {
if (obj == null) {
writeInt(0);
} else if (obj instanceof Bundle) {
writeInt(1);
writeBundle((Bundle) obj);
} else if (obj instanceof String) {
writeInt(3);
writeString((String) obj);
} else if (obj instanceof String[]) {
writeInt(4);
writeArray((String[]) obj);
} else if (obj instanceof Boolean) {
writeInt(5);
writeBoolean(((Boolean) obj).booleanValue());
} else if (obj instanceof boolean[]) {
writeInt(6);
writeBooleanArray((boolean[]) obj);
} else if (obj instanceof Double) {
writeInt(7);
writeDouble(((Double) obj).doubleValue());
} else if (obj instanceof double[]) {
writeInt(8);
writeDoubleArray((double[]) obj);
} else if (obj instanceof Integer) {
writeInt(9);
writeInt(((Integer) obj).intValue());
} else if (obj instanceof int[]) {
writeInt(10);
writeIntArray((int[]) obj);
} else if (obj instanceof Long) {
writeInt(11);
writeLong(((Long) obj).longValue());
} else if (obj instanceof long[]) {
writeInt(12);
writeLongArray((long[]) obj);
} else if (obj instanceof Float) {
writeInt(13);
writeFloat(((Float) obj).floatValue());
} else if (obj instanceof float[]) {
writeInt(14);
writeFloatArray((float[]) obj);
} else {
StringBuilder L = a.L("Unsupported type ");
L.append(obj.getClass());
throw new IllegalArgumentException(L.toString());
}
}
@Override // androidx.versionedparcelable.VersionedParcel
public void closeField() {
FieldBuffer fieldBuffer = this.mFieldBuffer;
if (fieldBuffer != null) {
try {
if (fieldBuffer.mOutput.size() != 0) {
this.mFieldBuffer.flushField();
}
this.mFieldBuffer = null;
} catch (IOException e) {
throw new VersionedParcel.ParcelException(e);
}
}
}
@Override // androidx.versionedparcelable.VersionedParcel
public VersionedParcel createSubParcel() {
return new VersionedParcelStream(this.mCurrentInput, this.mCurrentOutput, this.mReadCache, this.mWriteCache, this.mParcelizerCache);
}
@Override // androidx.versionedparcelable.VersionedParcel
public boolean isStream() {
return true;
}
@Override // androidx.versionedparcelable.VersionedParcel
public boolean readBoolean() {
try {
return this.mCurrentInput.readBoolean();
} catch (IOException e) {
throw new VersionedParcel.ParcelException(e);
}
}
@Override // androidx.versionedparcelable.VersionedParcel
public Bundle readBundle() {
int readInt = readInt();
if (readInt < 0) {
return null;
}
Bundle bundle = new Bundle();
for (int i = 0; i < readInt; i++) {
readObject(readInt(), readString(), bundle);
}
return bundle;
}
@Override // androidx.versionedparcelable.VersionedParcel
public byte[] readByteArray() {
try {
int readInt = this.mCurrentInput.readInt();
if (readInt <= 0) {
return null;
}
byte[] bArr = new byte[readInt];
this.mCurrentInput.readFully(bArr);
return bArr;
} catch (IOException e) {
throw new VersionedParcel.ParcelException(e);
}
}
@Override // androidx.versionedparcelable.VersionedParcel
public CharSequence readCharSequence() {
return null;
}
@Override // androidx.versionedparcelable.VersionedParcel
public double readDouble() {
try {
return this.mCurrentInput.readDouble();
} catch (IOException e) {
throw new VersionedParcel.ParcelException(e);
}
}
@Override // androidx.versionedparcelable.VersionedParcel
public boolean readField(int i) {
while (true) {
try {
int i2 = this.mFieldId;
if (i2 == i) {
return true;
}
if (String.valueOf(i2).compareTo(String.valueOf(i)) > 0) {
return false;
}
int i3 = this.mCount;
int i4 = this.mFieldSize;
if (i3 < i4) {
this.mMasterInput.skip((long) (i4 - i3));
}
this.mFieldSize = -1;
int readInt = this.mMasterInput.readInt();
this.mCount = 0;
int i5 = readInt & 65535;
if (i5 == 65535) {
i5 = this.mMasterInput.readInt();
}
this.mFieldId = (readInt >> 16) & 65535;
this.mFieldSize = i5;
} catch (IOException unused) {
return false;
}
}
}
@Override // androidx.versionedparcelable.VersionedParcel
public float readFloat() {
try {
return this.mCurrentInput.readFloat();
} catch (IOException e) {
throw new VersionedParcel.ParcelException(e);
}
}
@Override // androidx.versionedparcelable.VersionedParcel
public int readInt() {
try {
return this.mCurrentInput.readInt();
} catch (IOException e) {
throw new VersionedParcel.ParcelException(e);
}
}
@Override // androidx.versionedparcelable.VersionedParcel
public long readLong() {
try {
return this.mCurrentInput.readLong();
} catch (IOException e) {
throw new VersionedParcel.ParcelException(e);
}
}
@Override // androidx.versionedparcelable.VersionedParcel
public <T extends Parcelable> T readParcelable() {
return null;
}
@Override // androidx.versionedparcelable.VersionedParcel
public String readString() {
try {
int readInt = this.mCurrentInput.readInt();
if (readInt <= 0) {
return null;
}
byte[] bArr = new byte[readInt];
this.mCurrentInput.readFully(bArr);
return new String(bArr, UTF_16);
} catch (IOException e) {
throw new VersionedParcel.ParcelException(e);
}
}
@Override // androidx.versionedparcelable.VersionedParcel
public IBinder readStrongBinder() {
return null;
}
@Override // androidx.versionedparcelable.VersionedParcel
public void setOutputField(int i) {
closeField();
FieldBuffer fieldBuffer = new FieldBuffer(i, this.mMasterOutput);
this.mFieldBuffer = fieldBuffer;
this.mCurrentOutput = fieldBuffer.mDataStream;
}
@Override // androidx.versionedparcelable.VersionedParcel
public void setSerializationFlags(boolean z2, boolean z3) {
if (z2) {
this.mIgnoreParcelables = z3;
return;
}
throw new RuntimeException("Serialization of this object is not allowed");
}
@Override // androidx.versionedparcelable.VersionedParcel
public void writeBoolean(boolean z2) {
try {
this.mCurrentOutput.writeBoolean(z2);
} catch (IOException e) {
throw new VersionedParcel.ParcelException(e);
}
}
@Override // androidx.versionedparcelable.VersionedParcel
public void writeBundle(Bundle bundle) {
if (bundle != null) {
try {
Set<String> keySet = bundle.keySet();
this.mCurrentOutput.writeInt(keySet.size());
for (String str : keySet) {
writeString(str);
writeObject(bundle.get(str));
}
} catch (IOException e) {
throw new VersionedParcel.ParcelException(e);
}
} else {
this.mCurrentOutput.writeInt(-1);
}
}
@Override // androidx.versionedparcelable.VersionedParcel
public void writeByteArray(byte[] bArr) {
if (bArr != null) {
try {
this.mCurrentOutput.writeInt(bArr.length);
this.mCurrentOutput.write(bArr);
} catch (IOException e) {
throw new VersionedParcel.ParcelException(e);
}
} else {
this.mCurrentOutput.writeInt(-1);
}
}
@Override // androidx.versionedparcelable.VersionedParcel
public void writeByteArray(byte[] bArr, int i, int i2) {
if (bArr != null) {
try {
this.mCurrentOutput.writeInt(i2);
this.mCurrentOutput.write(bArr, i, i2);
} catch (IOException e) {
throw new VersionedParcel.ParcelException(e);
}
} else {
this.mCurrentOutput.writeInt(-1);
}
}
@Override // androidx.versionedparcelable.VersionedParcel
public void writeCharSequence(CharSequence charSequence) {
if (!this.mIgnoreParcelables) {
throw new RuntimeException("CharSequence cannot be written to an OutputStream");
}
}
@Override // androidx.versionedparcelable.VersionedParcel
public void writeDouble(double d) {
try {
this.mCurrentOutput.writeDouble(d);
} catch (IOException e) {
throw new VersionedParcel.ParcelException(e);
}
}
@Override // androidx.versionedparcelable.VersionedParcel
public void writeFloat(float f) {
try {
this.mCurrentOutput.writeFloat(f);
} catch (IOException e) {
throw new VersionedParcel.ParcelException(e);
}
}
@Override // androidx.versionedparcelable.VersionedParcel
public void writeInt(int i) {
try {
this.mCurrentOutput.writeInt(i);
} catch (IOException e) {
throw new VersionedParcel.ParcelException(e);
}
}
@Override // androidx.versionedparcelable.VersionedParcel
public void writeLong(long j) {
try {
this.mCurrentOutput.writeLong(j);
} catch (IOException e) {
throw new VersionedParcel.ParcelException(e);
}
}
@Override // androidx.versionedparcelable.VersionedParcel
public void writeParcelable(Parcelable parcelable) {
if (!this.mIgnoreParcelables) {
throw new RuntimeException("Parcelables cannot be written to an OutputStream");
}
}
@Override // androidx.versionedparcelable.VersionedParcel
public void writeString(String str) {
if (str != null) {
try {
byte[] bytes = str.getBytes(UTF_16);
this.mCurrentOutput.writeInt(bytes.length);
this.mCurrentOutput.write(bytes);
} catch (IOException e) {
throw new VersionedParcel.ParcelException(e);
}
} else {
this.mCurrentOutput.writeInt(-1);
}
}
@Override // androidx.versionedparcelable.VersionedParcel
public void writeStrongBinder(IBinder iBinder) {
if (!this.mIgnoreParcelables) {
throw new RuntimeException("Binders cannot be written to an OutputStream");
}
}
@Override // androidx.versionedparcelable.VersionedParcel
public void writeStrongInterface(IInterface iInterface) {
if (!this.mIgnoreParcelables) {
throw new RuntimeException("Binders cannot be written to an OutputStream");
}
}
}