package h1;

import java.io.IOException;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

/* JADX INFO: loaded from: classes.dex */
public final class c {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final int f26358a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final int f26359b;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final byte[] f26361d;

    public c(int i10, int i11, byte[] bArr) {
        this(-1L, bArr, i10, i11);
    }

    public static c a(String str) {
        byte[] bytes = str.concat("\u0000").getBytes(g.V);
        return new c(2, bytes.length, bytes);
    }

    public static c b(long j10, ByteOrder byteOrder) {
        return c(new long[]{j10}, byteOrder);
    }

    public static c c(long[] jArr, ByteOrder byteOrder) {
        ByteBuffer byteBufferWrap = ByteBuffer.wrap(new byte[g.M[4] * jArr.length]);
        byteBufferWrap.order(byteOrder);
        for (long j10 : jArr) {
            byteBufferWrap.putInt((int) j10);
        }
        return new c(4, jArr.length, byteBufferWrap.array());
    }

    public static c d(e[] eVarArr, ByteOrder byteOrder) {
        ByteBuffer byteBufferWrap = ByteBuffer.wrap(new byte[g.M[5] * eVarArr.length]);
        byteBufferWrap.order(byteOrder);
        for (e eVar : eVarArr) {
            byteBufferWrap.putInt((int) eVar.f26366a);
            byteBufferWrap.putInt((int) eVar.f26367b);
        }
        return new c(5, eVarArr.length, byteBufferWrap.array());
    }

    public static c e(int i10, ByteOrder byteOrder) {
        return f(new int[]{i10}, byteOrder);
    }

    public static c f(int[] iArr, ByteOrder byteOrder) {
        ByteBuffer byteBufferWrap = ByteBuffer.wrap(new byte[g.M[3] * iArr.length]);
        byteBufferWrap.order(byteOrder);
        for (int i10 : iArr) {
            byteBufferWrap.putShort((short) i10);
        }
        return new c(3, iArr.length, byteBufferWrap.array());
    }

    public final double g(ByteOrder byteOrder) throws Throwable {
        Object objJ = j(byteOrder);
        if (objJ == null) {
            throw new NumberFormatException("NULL can't be converted to a double value");
        }
        if (objJ instanceof String) {
            return Double.parseDouble((String) objJ);
        }
        if (objJ instanceof long[]) {
            if (((long[]) objJ).length == 1) {
                return r5[0];
            }
            throw new NumberFormatException("There are more than one component");
        }
        if (objJ instanceof int[]) {
            if (((int[]) objJ).length == 1) {
                return r5[0];
            }
            throw new NumberFormatException("There are more than one component");
        }
        if (objJ instanceof double[]) {
            double[] dArr = (double[]) objJ;
            if (dArr.length == 1) {
                return dArr[0];
            }
            throw new NumberFormatException("There are more than one component");
        }
        if (!(objJ instanceof e[])) {
            throw new NumberFormatException("Couldn't find a double value");
        }
        e[] eVarArr = (e[]) objJ;
        if (eVarArr.length != 1) {
            throw new NumberFormatException("There are more than one component");
        }
        e eVar = eVarArr[0];
        return eVar.f26366a / eVar.f26367b;
    }

    public final int h(ByteOrder byteOrder) throws Throwable {
        Object objJ = j(byteOrder);
        if (objJ == null) {
            throw new NumberFormatException("NULL can't be converted to a integer value");
        }
        if (objJ instanceof String) {
            return Integer.parseInt((String) objJ);
        }
        if (objJ instanceof long[]) {
            long[] jArr = (long[]) objJ;
            if (jArr.length == 1) {
                return (int) jArr[0];
            }
            throw new NumberFormatException("There are more than one component");
        }
        if (!(objJ instanceof int[])) {
            throw new NumberFormatException("Couldn't find a integer value");
        }
        int[] iArr = (int[]) objJ;
        if (iArr.length == 1) {
            return iArr[0];
        }
        throw new NumberFormatException("There are more than one component");
    }

    public final String i(ByteOrder byteOrder) throws Throwable {
        Object objJ = j(byteOrder);
        if (objJ == null) {
            return null;
        }
        if (objJ instanceof String) {
            return (String) objJ;
        }
        StringBuilder sb = new StringBuilder();
        int i10 = 0;
        if (objJ instanceof long[]) {
            long[] jArr = (long[]) objJ;
            while (i10 < jArr.length) {
                sb.append(jArr[i10]);
                i10++;
                if (i10 != jArr.length) {
                    sb.append(",");
                }
            }
            return sb.toString();
        }
        if (objJ instanceof int[]) {
            int[] iArr = (int[]) objJ;
            while (i10 < iArr.length) {
                sb.append(iArr[i10]);
                i10++;
                if (i10 != iArr.length) {
                    sb.append(",");
                }
            }
            return sb.toString();
        }
        if (objJ instanceof double[]) {
            double[] dArr = (double[]) objJ;
            while (i10 < dArr.length) {
                sb.append(dArr[i10]);
                i10++;
                if (i10 != dArr.length) {
                    sb.append(",");
                }
            }
            return sb.toString();
        }
        if (!(objJ instanceof e[])) {
            return null;
        }
        e[] eVarArr = (e[]) objJ;
        while (i10 < eVarArr.length) {
            sb.append(eVarArr[i10].f26366a);
            sb.append('/');
            sb.append(eVarArr[i10].f26367b);
            i10++;
            if (i10 != eVarArr.length) {
                sb.append(",");
            }
        }
        return sb.toString();
    }

    /* JADX WARN: Can't wrap try/catch for region: R(9:59|(2:61|(2:62|(2:64|(2:148|66)(1:67))(2:149|68)))|69|(2:71|(6:151|73|79|143|80|81)(3:74|(2:76|153)(2:77|152)|78))|150|79|143|80|81) */
    /* JADX WARN: Type inference failed for: r12v17, types: [int[], java.io.Serializable] */
    /* JADX WARN: Type inference failed for: r12v18, types: [java.io.Serializable, long[]] */
    /* JADX WARN: Type inference failed for: r12v19, types: [h1.e[], java.io.Serializable] */
    /* JADX WARN: Type inference failed for: r12v20, types: [int[], java.io.Serializable] */
    /* JADX WARN: Type inference failed for: r12v21, types: [int[], java.io.Serializable] */
    /* JADX WARN: Type inference failed for: r12v22, types: [h1.e[], java.io.Serializable] */
    /* JADX WARN: Type inference failed for: r12v23, types: [double[], java.io.Serializable] */
    /* JADX WARN: Type inference failed for: r12v24, types: [double[], java.io.Serializable] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Serializable j(ByteOrder byteOrder) throws Throwable {
        b bVar;
        byte b10;
        byte[] bArr = this.f26361d;
        b bVar2 = null;
        try {
            bVar = new b(bArr);
        } catch (IOException unused) {
            bVar = null;
        } catch (Throwable th) {
            th = th;
        }
        try {
            bVar.f26355b = byteOrder;
            int i10 = this.f26358a;
            int length = 0;
            int i11 = this.f26359b;
            switch (i10) {
                case 1:
                case 6:
                    if (bArr.length != 1 || (b10 = bArr[0]) < 0 || b10 > 1) {
                        String str = new String(bArr, g.V);
                        try {
                            bVar.close();
                            break;
                        } catch (IOException unused2) {
                        }
                        return str;
                    }
                    String str2 = new String(new char[]{(char) (b10 + 48)});
                    try {
                        bVar.close();
                        break;
                    } catch (IOException unused3) {
                    }
                    return str2;
                case 2:
                case 7:
                    if (i11 >= g.N.length) {
                        int i12 = 0;
                        while (true) {
                            byte[] bArr2 = g.N;
                            if (i12 >= bArr2.length) {
                                length = bArr2.length;
                            } else if (bArr[i12] == bArr2[i12]) {
                                i12++;
                            }
                        }
                    }
                    StringBuilder sb = new StringBuilder();
                    while (length < i11) {
                        byte b11 = bArr[length];
                        if (b11 == 0) {
                            String string = sb.toString();
                            bVar.close();
                            return string;
                        }
                        if (b11 >= 32) {
                            sb.append((char) b11);
                        } else {
                            sb.append('?');
                        }
                        length++;
                    }
                    String string2 = sb.toString();
                    bVar.close();
                    return string2;
                case 3:
                    ?? r12 = new int[i11];
                    while (length < i11) {
                        r12[length] = bVar.readUnsignedShort();
                        length++;
                    }
                    try {
                        bVar.close();
                        break;
                    } catch (IOException unused4) {
                    }
                    return r12;
                case 4:
                    ?? r122 = new long[i11];
                    while (length < i11) {
                        r122[length] = ((long) bVar.readInt()) & 4294967295L;
                        length++;
                    }
                    try {
                        bVar.close();
                        break;
                    } catch (IOException unused5) {
                    }
                    return r122;
                case 5:
                    ?? r123 = new e[i11];
                    while (length < i11) {
                        r123[length] = new e(((long) bVar.readInt()) & 4294967295L, ((long) bVar.readInt()) & 4294967295L);
                        length++;
                    }
                    try {
                        bVar.close();
                        break;
                    } catch (IOException unused6) {
                    }
                    return r123;
                case 8:
                    ?? r124 = new int[i11];
                    while (length < i11) {
                        r124[length] = bVar.readShort();
                        length++;
                    }
                    try {
                        bVar.close();
                        break;
                    } catch (IOException unused7) {
                    }
                    return r124;
                case 9:
                    ?? r125 = new int[i11];
                    while (length < i11) {
                        r125[length] = bVar.readInt();
                        length++;
                    }
                    try {
                        bVar.close();
                        break;
                    } catch (IOException unused8) {
                    }
                    return r125;
                case 10:
                    ?? r126 = new e[i11];
                    while (length < i11) {
                        r126[length] = new e(bVar.readInt(), bVar.readInt());
                        length++;
                    }
                    try {
                        bVar.close();
                        break;
                    } catch (IOException unused9) {
                    }
                    return r126;
                case 11:
                    ?? r127 = new double[i11];
                    while (length < i11) {
                        r127[length] = bVar.readFloat();
                        length++;
                    }
                    try {
                        bVar.close();
                        break;
                    } catch (IOException unused10) {
                    }
                    return r127;
                case 12:
                    ?? r128 = new double[i11];
                    while (length < i11) {
                        r128[length] = bVar.readDouble();
                        length++;
                    }
                    try {
                        bVar.close();
                        break;
                    } catch (IOException unused11) {
                    }
                    return r128;
                default:
                    try {
                        bVar.close();
                        break;
                    } catch (IOException unused12) {
                    }
                    return null;
            }
        } catch (IOException unused13) {
            if (bVar != null) {
                try {
                    bVar.close();
                } catch (IOException unused14) {
                }
            }
            return null;
        } catch (Throwable th2) {
            th = th2;
            bVar2 = bVar;
            if (bVar2 != null) {
                try {
                    bVar2.close();
                } catch (IOException unused15) {
                }
            }
            throw th;
        }
    }

    public final String toString() {
        StringBuilder sb = new StringBuilder("(");
        sb.append(g.L[this.f26358a]);
        sb.append(", data length:");
        return u.a.b(sb, this.f26361d.length, ")");
    }

    public c(long j10, byte[] bArr, int i10, int i11) {
        this.f26358a = i10;
        this.f26359b = i11;
        this.f26360c = j10;
        this.f26361d = bArr;
    }
}
