package V1;

import Z0.o;
import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
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 f7197a;

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

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

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

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

    public static c a(long j4, ByteOrder byteOrder) {
        long[] jArr = {j4};
        ByteBuffer byteBufferWrap = ByteBuffer.wrap(new byte[g.f7211E[4]]);
        byteBufferWrap.order(byteOrder);
        byteBufferWrap.putInt((int) jArr[0]);
        return new c(byteBufferWrap.array(), 4, 1);
    }

    public static c b(e eVar, ByteOrder byteOrder) {
        ByteBuffer byteBufferWrap = ByteBuffer.wrap(new byte[g.f7211E[5]]);
        byteBufferWrap.order(byteOrder);
        e eVar2 = new e[]{eVar}[0];
        byteBufferWrap.putInt((int) eVar2.f7205a);
        byteBufferWrap.putInt((int) eVar2.f7206b);
        return new c(byteBufferWrap.array(), 5, 1);
    }

    public static c c(int i6, ByteOrder byteOrder) {
        ByteBuffer byteBufferWrap = ByteBuffer.wrap(new byte[g.f7211E[3]]);
        byteBufferWrap.order(byteOrder);
        byteBufferWrap.putShort((short) new int[]{i6}[0]);
        return new c(byteBufferWrap.array(), 3, 1);
    }

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

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

    public final String f(ByteOrder byteOrder) throws Throwable {
        Object objG = g(byteOrder);
        if (objG == null) {
            return null;
        }
        if (objG instanceof String) {
            return (String) objG;
        }
        StringBuilder sb = new StringBuilder();
        int i6 = 0;
        if (objG instanceof long[]) {
            long[] jArr = (long[]) objG;
            while (i6 < jArr.length) {
                sb.append(jArr[i6]);
                i6++;
                if (i6 != jArr.length) {
                    sb.append(",");
                }
            }
            return sb.toString();
        }
        if (objG instanceof int[]) {
            int[] iArr = (int[]) objG;
            while (i6 < iArr.length) {
                sb.append(iArr[i6]);
                i6++;
                if (i6 != iArr.length) {
                    sb.append(",");
                }
            }
            return sb.toString();
        }
        if (objG instanceof double[]) {
            double[] dArr = (double[]) objG;
            while (i6 < dArr.length) {
                sb.append(dArr[i6]);
                i6++;
                if (i6 != dArr.length) {
                    sb.append(",");
                }
            }
            return sb.toString();
        }
        if (!(objG instanceof e[])) {
            return null;
        }
        e[] eVarArr = (e[]) objG;
        while (i6 < eVarArr.length) {
            sb.append(eVarArr[i6].f7205a);
            sb.append('/');
            sb.append(eVarArr[i6].f7206b);
            i6++;
            if (i6 != eVarArr.length) {
                sb.append(",");
            }
        }
        return sb.toString();
    }

    /* JADX WARN: Not initialized variable reg: 6, insn: 0x0033: MOVE (r5 I:??[OBJECT, ARRAY]) = (r6 I:??[OBJECT, ARRAY]) (LINE:52), block:B:16:0x0033 */
    /* JADX WARN: Removed duplicated region for block: B:153:0x016d A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Type inference failed for: r15v22, types: [int[], java.io.Serializable] */
    /* JADX WARN: Type inference failed for: r15v23, types: [java.io.Serializable, long[]] */
    /* JADX WARN: Type inference failed for: r15v24, types: [V1.e[], java.io.Serializable] */
    /* JADX WARN: Type inference failed for: r15v25, types: [int[], java.io.Serializable] */
    /* JADX WARN: Type inference failed for: r15v26, types: [int[], java.io.Serializable] */
    /* JADX WARN: Type inference failed for: r15v27, types: [V1.e[], java.io.Serializable] */
    /* JADX WARN: Type inference failed for: r15v28, types: [double[], java.io.Serializable] */
    /* JADX WARN: Type inference failed for: r15v29, types: [double[], java.io.Serializable] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Serializable g(ByteOrder byteOrder) throws Throwable {
        b bVar;
        InputStream inputStream;
        byte b5;
        String string;
        int length = 0;
        byte[] bArr = this.f7200d;
        InputStream inputStream2 = null;
        try {
            try {
                try {
                    bVar = new b(bArr);
                    try {
                        bVar.f7194c = byteOrder;
                        int i6 = this.f7197a;
                        int i7 = this.f7198b;
                        switch (i6) {
                            case 1:
                            case 6:
                                if (bArr.length != 1 || (b5 = bArr[0]) < 0 || b5 > 1) {
                                    String str = new String(bArr, g.f7220N);
                                    try {
                                        bVar.close();
                                        return str;
                                    } catch (IOException e6) {
                                        Log.e("ExifInterface", "IOException occurred while closing InputStream", e6);
                                        return str;
                                    }
                                }
                                String str2 = new String(new char[]{(char) (b5 + 48)});
                                try {
                                    bVar.close();
                                    return str2;
                                } catch (IOException e7) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e7);
                                    return str2;
                                }
                            case 2:
                            case 7:
                                if (i7 >= g.f7212F.length) {
                                    int i8 = 0;
                                    while (true) {
                                        byte[] bArr2 = g.f7212F;
                                        if (i8 >= bArr2.length) {
                                            length = bArr2.length;
                                        } else if (bArr[i8] == bArr2[i8]) {
                                            i8++;
                                        }
                                    }
                                }
                                StringBuilder sb = new StringBuilder();
                                try {
                                    while (length < i7) {
                                        byte b6 = bArr[length];
                                        if (b6 == 0) {
                                            string = sb.toString();
                                            bVar.close();
                                            return string;
                                        }
                                        if (b6 >= 32) {
                                            sb.append((char) b6);
                                        } else {
                                            sb.append('?');
                                        }
                                        length++;
                                    }
                                    bVar.close();
                                    return string;
                                } catch (IOException e8) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e8);
                                    return string;
                                }
                                string = sb.toString();
                            case 3:
                                ?? r15 = new int[i7];
                                while (length < i7) {
                                    r15[length] = bVar.readUnsignedShort();
                                    length++;
                                }
                                try {
                                    bVar.close();
                                    return r15;
                                } catch (IOException e9) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e9);
                                    return r15;
                                }
                            case 4:
                                ?? r152 = new long[i7];
                                while (length < i7) {
                                    r152[length] = ((long) bVar.readInt()) & 4294967295L;
                                    length++;
                                }
                                try {
                                    bVar.close();
                                    return r152;
                                } catch (IOException e10) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e10);
                                    return r152;
                                }
                            case 5:
                                ?? r153 = new e[i7];
                                while (length < i7) {
                                    r153[length] = new e(((long) bVar.readInt()) & 4294967295L, ((long) bVar.readInt()) & 4294967295L);
                                    length++;
                                }
                                try {
                                    bVar.close();
                                    return r153;
                                } catch (IOException e11) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e11);
                                    return r153;
                                }
                            case 8:
                                ?? r154 = new int[i7];
                                while (length < i7) {
                                    r154[length] = bVar.readShort();
                                    length++;
                                }
                                try {
                                    bVar.close();
                                    return r154;
                                } catch (IOException e12) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e12);
                                    return r154;
                                }
                            case 9:
                                ?? r155 = new int[i7];
                                while (length < i7) {
                                    r155[length] = bVar.readInt();
                                    length++;
                                }
                                try {
                                    bVar.close();
                                    return r155;
                                } catch (IOException e13) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e13);
                                    return r155;
                                }
                            case 10:
                                ?? r156 = new e[i7];
                                while (length < i7) {
                                    r156[length] = new e(bVar.readInt(), bVar.readInt());
                                    length++;
                                }
                                try {
                                    bVar.close();
                                    return r156;
                                } catch (IOException e14) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e14);
                                    return r156;
                                }
                            case 11:
                                ?? r157 = new double[i7];
                                while (length < i7) {
                                    r157[length] = bVar.readFloat();
                                    length++;
                                }
                                try {
                                    bVar.close();
                                    return r157;
                                } catch (IOException e15) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e15);
                                    return r157;
                                }
                            case 12:
                                ?? r158 = new double[i7];
                                while (length < i7) {
                                    r158[length] = bVar.readDouble();
                                    length++;
                                }
                                try {
                                    bVar.close();
                                    return r158;
                                } catch (IOException e16) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e16);
                                    return r158;
                                }
                            default:
                                bVar.close();
                                return null;
                        }
                    } catch (IOException e17) {
                        e = e17;
                        Log.w("ExifInterface", "IOException occurred during reading a value", e);
                        if (bVar != null) {
                            bVar.close();
                        }
                        return null;
                    }
                } catch (Throwable th) {
                    th = th;
                    inputStream2 = inputStream;
                    if (inputStream2 != null) {
                        try {
                            inputStream2.close();
                        } catch (IOException e18) {
                            Log.e("ExifInterface", "IOException occurred while closing InputStream", e18);
                        }
                    }
                    throw th;
                }
            } catch (IOException e19) {
                e = e19;
                bVar = null;
            } catch (Throwable th2) {
                th = th2;
                if (inputStream2 != null) {
                }
                throw th;
            }
        } catch (IOException e20) {
            Log.e("ExifInterface", "IOException occurred while closing InputStream", e20);
        }
    }

    public final String toString() {
        StringBuilder sb = new StringBuilder("(");
        sb.append(g.f7210D[this.f7197a]);
        sb.append(", data length:");
        return o.q(sb, this.f7200d.length, ")");
    }

    public c(long j4, byte[] bArr, int i6, int i7) {
        this.f7197a = i6;
        this.f7198b = i7;
        this.f7199c = j4;
        this.f7200d = bArr;
    }
}
