package f0;

import android.util.Log;
import d5.AbstractC0844a;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

/* JADX INFO: renamed from: f0.c, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0903c {

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

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

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

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

    public C0903c(byte[] bArr, int i, int i5) {
        this(-1L, bArr, i, i5);
    }

    public static C0903c a(long j8, ByteOrder byteOrder) {
        long[] jArr = {j8};
        ByteBuffer byteBufferWrap = ByteBuffer.wrap(new byte[C0907g.f12624C[4]]);
        byteBufferWrap.order(byteOrder);
        byteBufferWrap.putInt((int) jArr[0]);
        return new C0903c(byteBufferWrap.array(), 4, 1);
    }

    public static C0903c b(C0905e c0905e, ByteOrder byteOrder) {
        C0905e[] c0905eArr = {c0905e};
        ByteBuffer byteBufferWrap = ByteBuffer.wrap(new byte[C0907g.f12624C[5]]);
        byteBufferWrap.order(byteOrder);
        C0905e c0905e2 = c0905eArr[0];
        byteBufferWrap.putInt((int) c0905e2.f12620a);
        byteBufferWrap.putInt((int) c0905e2.f12621b);
        return new C0903c(byteBufferWrap.array(), 5, 1);
    }

    public static C0903c c(int i, ByteOrder byteOrder) {
        ByteBuffer byteBufferWrap = ByteBuffer.wrap(new byte[C0907g.f12624C[3]]);
        byteBufferWrap.order(byteOrder);
        byteBufferWrap.putShort((short) new int[]{i}[0]);
        return new C0903c(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 C0905e[])) {
            throw new NumberFormatException("Couldn't find a double value");
        }
        C0905e[] c0905eArr = (C0905e[]) objG;
        if (c0905eArr.length != 1) {
            throw new NumberFormatException("There are more than one component");
        }
        C0905e c0905e = c0905eArr[0];
        return c0905e.f12620a / c0905e.f12621b;
    }

    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 i = 0;
        if (objG instanceof long[]) {
            long[] jArr = (long[]) objG;
            while (i < jArr.length) {
                sb.append(jArr[i]);
                i++;
                if (i != jArr.length) {
                    sb.append(",");
                }
            }
            return sb.toString();
        }
        if (objG instanceof int[]) {
            int[] iArr = (int[]) objG;
            while (i < iArr.length) {
                sb.append(iArr[i]);
                i++;
                if (i != iArr.length) {
                    sb.append(",");
                }
            }
            return sb.toString();
        }
        if (objG instanceof double[]) {
            double[] dArr = (double[]) objG;
            while (i < dArr.length) {
                sb.append(dArr[i]);
                i++;
                if (i != dArr.length) {
                    sb.append(",");
                }
            }
            return sb.toString();
        }
        if (!(objG instanceof C0905e[])) {
            return null;
        }
        C0905e[] c0905eArr = (C0905e[]) objG;
        while (i < c0905eArr.length) {
            sb.append(c0905eArr[i].f12620a);
            sb.append('/');
            sb.append(c0905eArr[i].f12621b);
            i++;
            if (i != c0905eArr.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: [f0.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: [f0.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 {
        C0902b c0902b;
        InputStream inputStream;
        byte b8;
        String string;
        int length = 0;
        byte[] bArr = this.f12615d;
        InputStream inputStream2 = null;
        try {
            try {
                try {
                    c0902b = new C0902b(bArr);
                    try {
                        c0902b.f12609s = byteOrder;
                        int i = this.f12612a;
                        int i5 = this.f12613b;
                        switch (i) {
                            case 1:
                            case Z.g.STRING_SET_FIELD_NUMBER /* 6 */:
                                if (bArr.length != 1 || (b8 = bArr[0]) < 0 || b8 > 1) {
                                    String str = new String(bArr, C0907g.f12631L);
                                    try {
                                        c0902b.close();
                                        return str;
                                    } catch (IOException e8) {
                                        Log.e("ExifInterface", "IOException occurred while closing InputStream", e8);
                                        return str;
                                    }
                                }
                                String str2 = new String(new char[]{(char) (b8 + 48)});
                                try {
                                    c0902b.close();
                                    return str2;
                                } catch (IOException e9) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e9);
                                    return str2;
                                }
                            case 2:
                            case Z.g.DOUBLE_FIELD_NUMBER /* 7 */:
                                if (i5 >= C0907g.D.length) {
                                    int i8 = 0;
                                    while (true) {
                                        byte[] bArr2 = C0907g.D;
                                        if (i8 >= bArr2.length) {
                                            length = bArr2.length;
                                        } else if (bArr[i8] == bArr2[i8]) {
                                            i8++;
                                        }
                                    }
                                }
                                StringBuilder sb = new StringBuilder();
                                try {
                                    while (length < i5) {
                                        byte b9 = bArr[length];
                                        if (b9 == 0) {
                                            string = sb.toString();
                                            c0902b.close();
                                            return string;
                                        }
                                        if (b9 >= 32) {
                                            sb.append((char) b9);
                                        } else {
                                            sb.append('?');
                                        }
                                        length++;
                                    }
                                    c0902b.close();
                                    return string;
                                } catch (IOException e10) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e10);
                                    return string;
                                }
                                string = sb.toString();
                            case 3:
                                ?? r15 = new int[i5];
                                while (length < i5) {
                                    r15[length] = c0902b.readUnsignedShort();
                                    length++;
                                }
                                try {
                                    c0902b.close();
                                    return r15;
                                } catch (IOException e11) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e11);
                                    return r15;
                                }
                            case 4:
                                ?? r152 = new long[i5];
                                while (length < i5) {
                                    r152[length] = ((long) c0902b.readInt()) & 4294967295L;
                                    length++;
                                }
                                try {
                                    c0902b.close();
                                    return r152;
                                } catch (IOException e12) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e12);
                                    return r152;
                                }
                            case 5:
                                ?? r153 = new C0905e[i5];
                                while (length < i5) {
                                    r153[length] = new C0905e(((long) c0902b.readInt()) & 4294967295L, ((long) c0902b.readInt()) & 4294967295L);
                                    length++;
                                }
                                try {
                                    c0902b.close();
                                    return r153;
                                } catch (IOException e13) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e13);
                                    return r153;
                                }
                            case Z.g.BYTES_FIELD_NUMBER /* 8 */:
                                ?? r154 = new int[i5];
                                while (length < i5) {
                                    r154[length] = c0902b.readShort();
                                    length++;
                                }
                                try {
                                    c0902b.close();
                                    return r154;
                                } catch (IOException e14) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e14);
                                    return r154;
                                }
                            case 9:
                                ?? r155 = new int[i5];
                                while (length < i5) {
                                    r155[length] = c0902b.readInt();
                                    length++;
                                }
                                try {
                                    c0902b.close();
                                    return r155;
                                } catch (IOException e15) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e15);
                                    return r155;
                                }
                            case 10:
                                ?? r156 = new C0905e[i5];
                                while (length < i5) {
                                    r156[length] = new C0905e(c0902b.readInt(), c0902b.readInt());
                                    length++;
                                }
                                try {
                                    c0902b.close();
                                    return r156;
                                } catch (IOException e16) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e16);
                                    return r156;
                                }
                            case 11:
                                ?? r157 = new double[i5];
                                while (length < i5) {
                                    r157[length] = c0902b.readFloat();
                                    length++;
                                }
                                try {
                                    c0902b.close();
                                    return r157;
                                } catch (IOException e17) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e17);
                                    return r157;
                                }
                            case 12:
                                ?? r158 = new double[i5];
                                while (length < i5) {
                                    r158[length] = c0902b.readDouble();
                                    length++;
                                }
                                try {
                                    c0902b.close();
                                    return r158;
                                } catch (IOException e18) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e18);
                                    return r158;
                                }
                            default:
                                c0902b.close();
                                return null;
                        }
                    } catch (IOException e19) {
                        e = e19;
                        Log.w("ExifInterface", "IOException occurred during reading a value", e);
                        if (c0902b != null) {
                            c0902b.close();
                        }
                        return null;
                    }
                } catch (Throwable th) {
                    th = th;
                    inputStream2 = inputStream;
                    if (inputStream2 != null) {
                        try {
                            inputStream2.close();
                        } catch (IOException e20) {
                            Log.e("ExifInterface", "IOException occurred while closing InputStream", e20);
                        }
                    }
                    throw th;
                }
            } catch (IOException e21) {
                e = e21;
                c0902b = null;
            } catch (Throwable th2) {
                th = th2;
                if (inputStream2 != null) {
                }
                throw th;
            }
        } catch (IOException e22) {
            Log.e("ExifInterface", "IOException occurred while closing InputStream", e22);
        }
    }

    public final String toString() {
        StringBuilder sb = new StringBuilder("(");
        sb.append(C0907g.f12623B[this.f12612a]);
        sb.append(", data length:");
        return AbstractC0844a.n(sb, this.f12615d.length, ")");
    }

    public C0903c(long j8, byte[] bArr, int i, int i5) {
        this.f12612a = i;
        this.f12613b = i5;
        this.f12614c = j8;
        this.f12615d = bArr;
    }
}
