LINE.apk(点击下载) / a.java


package e3;

import a1.k;
import ai.clova.cic.clientlib.exoplayer2.C;
import android.content.res.AssetManager;
import android.media.MediaDataSource;
import android.media.MediaMetadataRetriever;
import android.system.Os;
import android.system.OsConstants;
import android.util.Log;
import android.util.Pair;
import io.card.payment.CardScanner;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.CRC32;
import kotlin.UByte;
import okhttp3.internal.ws.WebSocketProtocol;
import zo1.v1;

public class a {
    public static final byte[] A = {109, 105, 102, 49};
    public static final byte[] B = {104, 101, 105, 99};
    public static final byte[] C = {79, 76, 89, 77, 80, 0};
    public static final byte[] D = {79, 76, 89, 77, 80, 85, 83, 0, 73, 73};
    public static final byte[] E = {-119, 80, 78, 71, 13, 10, 26, 10};
    public static final byte[] F = {101, 88, 73, 102};
    public static final byte[] G = {73, 72, 68, 82};
    public static final byte[] H = {73, 69, 78, 68};
    public static final byte[] I = {82, 73, 70, 70};
    public static final byte[] J = {87, 69, 66, 80};
    public static final byte[] K = {69, 88, 73, 70};
    public static final byte[] L = {-99, 1, 42};
    public static final byte[] M = "VP8X".getBytes(Charset.defaultCharset());
    public static final byte[] N = "VP8L".getBytes(Charset.defaultCharset());
    public static final byte[] O = "VP8 ".getBytes(Charset.defaultCharset());
    public static final byte[] P = "ANIM".getBytes(Charset.defaultCharset());
    public static final byte[] Q = "ANMF".getBytes(Charset.defaultCharset());
    public static final String[] R = {"", "BYTE", "STRING", "USHORT", "ULONG", "URATIONAL", "SBYTE", v1.UNDEFINED, "SSHORT", "SLONG", "SRATIONAL", "SINGLE", "DOUBLE", "IFD"};
    public static final int[] S = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 1};
    public static final byte[] T = {65, 83, 67, 73, 73, 0, 0, 0};
    public static final e U = new e("StripOffsets", 273, 3);
    public static final e[][] V;
    public static final e[] W = {new e("SubIFDPointer", 330, 4), new e("ExifIFDPointer", 34665, 4), new e("GPSInfoIFDPointer", 34853, 4), new e("InteroperabilityIFDPointer", 40965, 4), new e("CameraSettingsIFDPointer", 8224, 1), new e("ImageProcessingIFDPointer", 8256, 1)};
    public static final e X = new e("JPEGInterchangeFormat", 513, 4);
    public static final e Y = new e("JPEGInterchangeFormatLength", 514, 4);
    public static final HashMap<Integer, e>[] Z = new HashMap[10];

    /* renamed from: a0  reason: collision with root package name */
    public static final HashMap<String, e>[] f66326a0 = new HashMap[10];

    /* renamed from: b0  reason: collision with root package name */
    public static final HashSet<String> f66327b0 = new HashSet<>(Arrays.asList("FNumber", "DigitalZoomRatio", "ExposureTime", "SubjectDistance", "GPSTimeStamp"));

    /* renamed from: c0  reason: collision with root package name */
    public static final HashMap<Integer, Integer> f66328c0 = new HashMap<>();

    /* renamed from: d0  reason: collision with root package name */
    public static final Charset f66329d0;

    /* renamed from: e0  reason: collision with root package name */
    public static final byte[] f66330e0;

    /* renamed from: f0  reason: collision with root package name */
    public static final byte[] f66331f0;

    /* renamed from: g0  reason: collision with root package name */
    public static final Pattern f66332g0 = Pattern.compile("^(\\d{2}):(\\d{2}):(\\d{2})$");

    /* renamed from: h0  reason: collision with root package name */
    public static final Pattern f66333h0 = Pattern.compile("^(\\d{4}):(\\d{2}):(\\d{2})\\s(\\d{2}):(\\d{2}):(\\d{2})$");

    /* renamed from: i0  reason: collision with root package name */
    public static final Pattern f66334i0 = Pattern.compile("^(\\d{4})-(\\d{2})-(\\d{2})\\s(\\d{2}):(\\d{2}):(\\d{2})$");

    /* renamed from: t  reason: collision with root package name */
    public static final boolean f66335t = Log.isLoggable("ExifInterface", 3);

    /* renamed from: u  reason: collision with root package name */
    public static final List<Integer> f66336u = Arrays.asList(1, 6, 3, 8);

    /* renamed from: v  reason: collision with root package name */
    public static final List<Integer> f66337v = Arrays.asList(2, 7, 4, 5);

    /* renamed from: w  reason: collision with root package name */
    public static final int[] f66338w = {8, 8, 8};

    /* renamed from: x  reason: collision with root package name */
    public static final int[] f66339x = {8};

    /* renamed from: y  reason: collision with root package name */
    public static final byte[] f66340y = {-1, -40, -1};

    /* renamed from: z  reason: collision with root package name */
    public static final byte[] f66341z = {102, 116, 121, 112};

    /* renamed from: a  reason: collision with root package name */
    public String f66342a;

    /* renamed from: b  reason: collision with root package name */
    public FileDescriptor f66343b;

    /* renamed from: c  reason: collision with root package name */
    public AssetManager.AssetInputStream f66344c;

    /* renamed from: d  reason: collision with root package name */
    public int f66345d;

    /* renamed from: e  reason: collision with root package name */
    public boolean f66346e;

    /* renamed from: f  reason: collision with root package name */
    public final HashMap<String, d>[] f66347f;

    /* renamed from: g  reason: collision with root package name */
    public Set<Integer> f66348g;

    /* renamed from: h  reason: collision with root package name */
    public ByteOrder f66349h = ByteOrder.BIG_ENDIAN;

    /* renamed from: i  reason: collision with root package name */
    public boolean f66350i;

    /* renamed from: j  reason: collision with root package name */
    public boolean f66351j;

    /* renamed from: k  reason: collision with root package name */
    public int f66352k;

    /* renamed from: l  reason: collision with root package name */
    public int f66353l;

    /* renamed from: m  reason: collision with root package name */
    public byte[] f66354m;

    /* renamed from: n  reason: collision with root package name */
    public int f66355n;

    /* renamed from: o  reason: collision with root package name */
    public int f66356o;

    /* renamed from: p  reason: collision with root package name */
    public int f66357p;

    /* renamed from: q  reason: collision with root package name */
    public int f66358q;

    /* renamed from: r  reason: collision with root package name */
    public int f66359r;

    /* renamed from: s  reason: collision with root package name */
    public boolean f66360s;

    /* renamed from: e3.a$a  reason: collision with other inner class name */
    public class C0748a extends MediaDataSource {

        /* renamed from: b  reason: collision with root package name */
        public long f66361b;

        /* renamed from: c  reason: collision with root package name */
        public final /* synthetic */ b f66362c;

        public C0748a(a aVar, b bVar) {
            this.f66362c = bVar;
        }

        @Override // java.io.Closeable, java.lang.AutoCloseable
        public void close() throws IOException {
        }

        @Override // android.media.MediaDataSource
        public long getSize() throws IOException {
            return -1;
        }

        @Override // android.media.MediaDataSource
        public int readAt(long j14, byte[] bArr, int i14, int i15) throws IOException {
            if (i15 == 0) {
                return 0;
            }
            if (j14 < 0) {
                return -1;
            }
            try {
                long j15 = this.f66361b;
                if (j15 != j14) {
                    if (j15 >= 0 && j14 >= j15 + ((long) this.f66362c.available())) {
                        return -1;
                    }
                    this.f66362c.b(j14);
                    this.f66361b = j14;
                }
                if (i15 > this.f66362c.available()) {
                    i15 = this.f66362c.available();
                }
                b bVar = this.f66362c;
                int read = bVar.f66365b.read(bArr, i14, i15);
                bVar.f66368e += read;
                if (read >= 0) {
                    this.f66361b += (long) read;
                    return read;
                }
            } catch (IOException unused) {
            }
            this.f66361b = -1;
            return -1;
        }
    }

    public static class c extends FilterOutputStream {

        /* renamed from: b  reason: collision with root package name */
        public final OutputStream f66369b;

        /* renamed from: c  reason: collision with root package name */
        public ByteOrder f66370c;

        public c(OutputStream outputStream, ByteOrder byteOrder) {
            super(outputStream);
            this.f66369b = outputStream;
            this.f66370c = byteOrder;
        }

        public void a(int i14) throws IOException {
            ByteOrder byteOrder = this.f66370c;
            if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
                this.f66369b.write((i14 >>> 0) & 255);
                this.f66369b.write((i14 >>> 8) & 255);
                this.f66369b.write((i14 >>> 16) & 255);
                this.f66369b.write((i14 >>> 24) & 255);
            } else if (byteOrder == ByteOrder.BIG_ENDIAN) {
                this.f66369b.write((i14 >>> 24) & 255);
                this.f66369b.write((i14 >>> 16) & 255);
                this.f66369b.write((i14 >>> 8) & 255);
                this.f66369b.write((i14 >>> 0) & 255);
            }
        }

        public void b(short s14) throws IOException {
            ByteOrder byteOrder = this.f66370c;
            if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
                this.f66369b.write((s14 >>> 0) & 255);
                this.f66369b.write((s14 >>> 8) & 255);
            } else if (byteOrder == ByteOrder.BIG_ENDIAN) {
                this.f66369b.write((s14 >>> 8) & 255);
                this.f66369b.write((s14 >>> 0) & 255);
            }
        }

        @Override // java.io.OutputStream, java.io.FilterOutputStream
        public void write(byte[] bArr) throws IOException {
            this.f66369b.write(bArr);
        }

        @Override // java.io.OutputStream, java.io.FilterOutputStream
        public void write(byte[] bArr, int i14, int i15) throws IOException {
            this.f66369b.write(bArr, i14, i15);
        }
    }

    public static class f {

        /* renamed from: a  reason: collision with root package name */
        public final long f66379a;

        /* renamed from: b  reason: collision with root package name */
        public final long f66380b;

        public f(long j14, long j15) {
            if (j15 == 0) {
                this.f66379a = 0;
                this.f66380b = 1;
                return;
            }
            this.f66379a = j14;
            this.f66380b = j15;
        }

        public String toString() {
            return this.f66379a + "/" + this.f66380b;
        }
    }

    static {
        e[] eVarArr = {new e("NewSubfileType", 254, 4), new e("SubfileType", 255, 4), new e("ImageWidth", 256, 3, 4), new e("ImageLength", 257, 3, 4), new e("BitsPerSample", 258, 3), new e("Compression", 259, 3), new e("PhotometricInterpretation", 262, 3), new e("ImageDescription", CardScanner.CREDIT_CARD_TARGET_HEIGHT, 2), new e("Make", 271, 2), new e("Model", 272, 2), new e("StripOffsets", 273, 3, 4), new e("Orientation", 274, 3), new e("SamplesPerPixel", 277, 3), new e("RowsPerStrip", 278, 3, 4), new e("StripByteCounts", 279, 3, 4), new e("XResolution", 282, 5), new e("YResolution", 283, 5), new e("PlanarConfiguration", 284, 3), new e("ResolutionUnit", 296, 3), new e("TransferFunction", 301, 3), new e("Software", 305, 2), new e("DateTime", 306, 2), new e("Artist", 315, 2), new e("WhitePoint", 318, 5), new e("PrimaryChromaticities", 319, 5), new e("SubIFDPointer", 330, 4), new e("JPEGInterchangeFormat", 513, 4), new e("JPEGInterchangeFormatLength", 514, 4), new e("YCbCrCoefficients", 529, 5), new e("YCbCrSubSampling", 530, 3), new e("YCbCrPositioning", 531, 3), new e("ReferenceBlackWhite", 532, 5), new e("Copyright", 33432, 2), new e("ExifIFDPointer", 34665, 4), new e("GPSInfoIFDPointer", 34853, 4), new e("SensorTopBorder", 4, 4), new e("SensorLeftBorder", 5, 4), new e("SensorBottomBorder", 6, 4), new e("SensorRightBorder", 7, 4), new e("ISO", 23, 3), new e("JpgFromRaw", 46, 7), new e("Xmp", 700, 1)};
        V = new e[][]{eVarArr, new e[]{new e("ExposureTime", 33434, 5), new e("FNumber", 33437, 5), new e("ExposureProgram", 34850, 3), new e("SpectralSensitivity", 34852, 2), new e("PhotographicSensitivity", 34855, 3), new e("OECF", 34856, 7), new e("SensitivityType", 34864, 3), new e("StandardOutputSensitivity", 34865, 4), new e("RecommendedExposureIndex", 34866, 4), new e("ISOSpeed", 34867, 4), new e("ISOSpeedLatitudeyyy", 34868, 4), new e("ISOSpeedLatitudezzz", 34869, 4), new e("ExifVersion", 36864, 2), new e("DateTimeOriginal", 36867, 2), new e("DateTimeDigitized", 36868, 2), new e("OffsetTime", 36880, 2), new e("OffsetTimeOriginal", 36881, 2), new e("OffsetTimeDigitized", 36882, 2), new e("ComponentsConfiguration", 37121, 7), new e("CompressedBitsPerPixel", 37122, 5), new e("ShutterSpeedValue", 37377, 10), new e("ApertureValue", 37378, 5), new e("BrightnessValue", 37379, 10), new e("ExposureBiasValue", 37380, 10), new e("MaxApertureValue", 37381, 5), new e("SubjectDistance", 37382, 5), new e("MeteringMode", 37383, 3), new e("LightSource", 37384, 3), new e("Flash", 37385, 3), new e("FocalLength", 37386, 5), new e("SubjectArea", 37396, 3), new e("MakerNote", 37500, 7), new e("UserComment", 37510, 7), new e("SubSecTime", 37520, 2), new e("SubSecTimeOriginal", 37521, 2), new e("SubSecTimeDigitized", 37522, 2), new e("FlashpixVersion", 40960, 7), new e("ColorSpace", 40961, 3), new e("PixelXDimension", 40962, 3, 4), new e("PixelYDimension", 40963, 3, 4), new e("RelatedSoundFile", 40964, 2), new e("InteroperabilityIFDPointer", 40965, 4), new e("FlashEnergy", 41483, 5), new e("SpatialFrequencyResponse", 41484, 7), new e("FocalPlaneXResolution", 41486, 5), new e("FocalPlaneYResolution", 41487, 5), new e("FocalPlaneResolutionUnit", 41488, 3), new e("SubjectLocation", 41492, 3), new e("ExposureIndex", 41493, 5), new e("SensingMethod", 41495, 3), new e("FileSource", 41728, 7), new e("SceneType", 41729, 7), new e("CFAPattern", 41730, 7), new e("CustomRendered", 41985, 3), new e("ExposureMode", 41986, 3), new e("WhiteBalance", 41987, 3), new e("DigitalZoomRatio", 41988, 5), new e("FocalLengthIn35mmFilm", 41989, 3), new e("SceneCaptureType", 41990, 3), new e("GainControl", 41991, 3), new e("Contrast", 41992, 3), new e("Saturation", 41993, 3), new e("Sharpness", 41994, 3), new e("DeviceSettingDescription", 41995, 7), new e("SubjectDistanceRange", 41996, 3), new e("ImageUniqueID", 42016, 2), new e("CameraOwnerName", 42032, 2), new e("BodySerialNumber", 42033, 2), new e("LensSpecification", 42034, 5), new e("LensMake", 42035, 2), new e("LensModel", 42036, 2), new e("Gamma", 42240, 5), new e("DNGVersion", 50706, 1), new e("DefaultCropSize", 50720, 3, 4)}, new e[]{new e("GPSVersionID", 0, 1), new e("GPSLatitudeRef", 1, 2), new e("GPSLatitude", 2, 5, 10), new e("GPSLongitudeRef", 3, 2), new e("GPSLongitude", 4, 5, 10), new e("GPSAltitudeRef", 5, 1), new e("GPSAltitude", 6, 5), new e("GPSTimeStamp", 7, 5), new e("GPSSatellites", 8, 2), new e("GPSStatus", 9, 2), new e("GPSMeasureMode", 10, 2), new e("GPSDOP", 11, 5), new e("GPSSpeedRef", 12, 2), new e("GPSSpeed", 13, 5), new e("GPSTrackRef", 14, 2), new e("GPSTrack", 15, 5), new e("GPSImgDirectionRef", 16, 2), new e("GPSImgDirection", 17, 5), new e("GPSMapDatum", 18, 2), new e("GPSDestLatitudeRef", 19, 2), new e("GPSDestLatitude", 20, 5), new e("GPSDestLongitudeRef", 21, 2), new e("GPSDestLongitude", 22, 5), new e("GPSDestBearingRef", 23, 2), new e("GPSDestBearing", 24, 5), new e("GPSDestDistanceRef", 25, 2), new e("GPSDestDistance", 26, 5), new e("GPSProcessingMethod", 27, 7), new e("GPSAreaInformation", 28, 7), new e("GPSDateStamp", 29, 2), new e("GPSDifferential", 30, 3), new e("GPSHPositioningError", 31, 5)}, new e[]{new e("InteroperabilityIndex", 1, 2)}, new e[]{new e("NewSubfileType", 254, 4), new e("SubfileType", 255, 4), new e("ThumbnailImageWidth", 256, 3, 4), new e("ThumbnailImageLength", 257, 3, 4), new e("BitsPerSample", 258, 3), new e("Compression", 259, 3), new e("PhotometricInterpretation", 262, 3), new e("ImageDescription", CardScanner.CREDIT_CARD_TARGET_HEIGHT, 2), new e("Make", 271, 2), new e("Model", 272, 2), new e("StripOffsets", 273, 3, 4), new e("ThumbnailOrientation", 274, 3), new e("SamplesPerPixel", 277, 3), new e("RowsPerStrip", 278, 3, 4), new e("StripByteCounts", 279, 3, 4), new e("XResolution", 282, 5), new e("YResolution", 283, 5), new e("PlanarConfiguration", 284, 3), new e("ResolutionUnit", 296, 3), new e("TransferFunction", 301, 3), new e("Software", 305, 2), new e("DateTime", 306, 2), new e("Artist", 315, 2), new e("WhitePoint", 318, 5), new e("PrimaryChromaticities", 319, 5), new e("SubIFDPointer", 330, 4), new e("JPEGInterchangeFormat", 513, 4), new e("JPEGInterchangeFormatLength", 514, 4), new e("YCbCrCoefficients", 529, 5), new e("YCbCrSubSampling", 530, 3), new e("YCbCrPositioning", 531, 3), new e("ReferenceBlackWhite", 532, 5), new e("Copyright", 33432, 2), new e("ExifIFDPointer", 34665, 4), new e("GPSInfoIFDPointer", 34853, 4), new e("DNGVersion", 50706, 1), new e("DefaultCropSize", 50720, 3, 4)}, eVarArr, new e[]{new e("ThumbnailImage", 256, 7), new e("CameraSettingsIFDPointer", 8224, 4), new e("ImageProcessingIFDPointer", 8256, 4)}, new e[]{new e("PreviewImageStart", 257, 4), new e("PreviewImageLength", 258, 4)}, new e[]{new e("AspectFrame", 4371, 3)}, new e[]{new e("ColorSpace", 55, 3)}};
        Charset forName = Charset.forName(C.ASCII_NAME);
        f66329d0 = forName;
        f66330e0 = "Exif\u0000\u0000".getBytes(forName);
        f66331f0 = "http://ns.adobe.com/xap/1.0/\u0000".getBytes(forName);
        Locale locale = Locale.US;
        new SimpleDateFormat("yyyy:MM:dd HH:mm:ss", locale).setTimeZone(TimeZone.getTimeZone("UTC"));
        new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", locale).setTimeZone(TimeZone.getTimeZone("UTC"));
        int i14 = 0;
        while (true) {
            e[][] eVarArr2 = V;
            if (i14 < eVarArr2.length) {
                Z[i14] = new HashMap<>();
                f66326a0[i14] = new HashMap<>();
                e[] eVarArr3 = eVarArr2[i14];
                for (e eVar : eVarArr3) {
                    Z[i14].put(Integer.valueOf(eVar.f66375a), eVar);
                    f66326a0[i14].put(eVar.f66376b, eVar);
                }
                i14++;
            } else {
                HashMap<Integer, Integer> hashMap = f66328c0;
                e[] eVarArr4 = W;
                hashMap.put(Integer.valueOf(eVarArr4[0].f66375a), 5);
                hashMap.put(Integer.valueOf(eVarArr4[1].f66375a), 1);
                hashMap.put(Integer.valueOf(eVarArr4[2].f66375a), 2);
                hashMap.put(Integer.valueOf(eVarArr4[3].f66375a), 3);
                hashMap.put(Integer.valueOf(eVarArr4[4].f66375a), 7);
                hashMap.put(Integer.valueOf(eVarArr4[5].f66375a), 8);
                Pattern.compile(".*[1-9].*");
                return;
            }
        }
    }

    public a(File file) throws IOException {
        e[][] eVarArr = V;
        this.f66347f = new HashMap[eVarArr.length];
        this.f66348g = new HashSet(eVarArr.length);
        z(file.getAbsolutePath());
    }

    public static boolean O(byte[] bArr, byte[] bArr2) {
        if (bArr2 == null || bArr.length < bArr2.length) {
            return false;
        }
        for (int i14 = 0; i14 < bArr2.length; i14++) {
            if (bArr[i14] != bArr2[i14]) {
                return false;
            }
        }
        return true;
    }

    public static String b(byte[] bArr) {
        StringBuilder sb4 = new StringBuilder(bArr.length * 2);
        for (int i14 = 0; i14 < bArr.length; i14++) {
            sb4.append(String.format("%02x", Byte.valueOf(bArr[i14])));
        }
        return sb4.toString();
    }

    public static void c(Closeable closeable) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (RuntimeException e14) {
                throw e14;
            } catch (Exception unused) {
            }
        }
    }

    public static long[] d(Object obj) {
        if (obj instanceof int[]) {
            int[] iArr = (int[]) obj;
            long[] jArr = new long[iArr.length];
            for (int i14 = 0; i14 < iArr.length; i14++) {
                jArr[i14] = (long) iArr[i14];
            }
            return jArr;
        } else if (obj instanceof long[]) {
            return (long[]) obj;
        } else {
            return null;
        }
    }

    public static int e(InputStream inputStream, OutputStream outputStream) throws IOException {
        byte[] bArr = new byte[8192];
        int i14 = 0;
        while (true) {
            int read = inputStream.read(bArr);
            if (read == -1) {
                return i14;
            }
            i14 += read;
            outputStream.write(bArr, 0, read);
        }
    }

    public static void f(InputStream inputStream, OutputStream outputStream, int i14) throws IOException {
        byte[] bArr = new byte[8192];
        while (i14 > 0) {
            int min = Math.min(i14, 8192);
            int read = inputStream.read(bArr, 0, min);
            if (read == min) {
                i14 -= read;
                ((c) outputStream).f66369b.write(bArr, 0, read);
            } else {
                throw new IOException("Failed to copy the given amount of bytes from the inputstream to the output stream.");
            }
        }
    }

    /* JADX WARNING: Can't wrap try/catch for region: R(3:68|69|70) */
    /* JADX WARNING: Code restructure failed: missing block: B:69:?, code lost:
        java.lang.Double.parseDouble(r12);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:70:0x015c, code lost:
        return new android.util.Pair<>(12, -1);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:73:0x0162, code lost:
        return new android.util.Pair<>(2, -1);
     */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Missing exception handler attribute for start block: B:68:0x014e */
    public static Pair<Integer, Integer> x(String str) {
        if (str.contains(",")) {
            String[] split = str.split(",", -1);
            Pair<Integer, Integer> x14 = x(split[0]);
            if (((Integer) x14.first).intValue() == 2) {
                return x14;
            }
            for (int i14 = 1; i14 < split.length; i14++) {
                Pair<Integer, Integer> x15 = x(split[i14]);
                int intValue = (((Integer) x15.first).equals(x14.first) || ((Integer) x15.second).equals(x14.first)) ? ((Integer) x14.first).intValue() : -1;
                int intValue2 = (((Integer) x14.second).intValue() == -1 || (!((Integer) x15.first).equals(x14.second) && !((Integer) x15.second).equals(x14.second))) ? -1 : ((Integer) x14.second).intValue();
                if (intValue == -1 && intValue2 == -1) {
                    return new Pair<>(2, -1);
                }
                if (intValue == -1) {
                    x14 = new Pair<>(Integer.valueOf(intValue2), -1);
                } else if (intValue2 == -1) {
                    x14 = new Pair<>(Integer.valueOf(intValue), -1);
                }
            }
            return x14;
        } else if (str.contains("/")) {
            String[] split2 = str.split("/", -1);
            if (split2.length == 2) {
                try {
                    long parseDouble = (long) Double.parseDouble(split2[0]);
                    long parseDouble2 = (long) Double.parseDouble(split2[1]);
                    if (parseDouble >= 0) {
                        if (parseDouble2 >= 0) {
                            if (parseDouble <= 2147483647L) {
                                if (parseDouble2 <= 2147483647L) {
                                    return new Pair<>(10, 5);
                                }
                            }
                            return new Pair<>(5, -1);
                        }
                    }
                    return new Pair<>(10, -1);
                } catch (NumberFormatException unused) {
                }
            }
            return new Pair<>(2, -1);
        } else {
            Long valueOf = Long.valueOf(Long.parseLong(str));
            if (valueOf.longValue() >= 0 && valueOf.longValue() <= WebSocketProtocol.PAYLOAD_SHORT_MAX) {
                return new Pair<>(3, 4);
            }
            if (valueOf.longValue() < 0) {
                return new Pair<>(9, -1);
            }
            return new Pair<>(4, -1);
        }
    }

    public final boolean A(HashMap hashMap) throws IOException {
        d dVar = (d) hashMap.get("ImageLength");
        d dVar2 = (d) hashMap.get("ImageWidth");
        if (dVar == null || dVar2 == null) {
            return false;
        }
        return dVar.h(this.f66349h) <= 512 && dVar2.h(this.f66349h) <= 512;
    }

    /* JADX WARNING: Can't wrap try/catch for region: R(4:36|37|38|(1:58)) */
    /* JADX WARNING: Code restructure failed: missing block: B:35:0x009c, code lost:
        r5 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:37:?, code lost:
        r5 = e3.a.f66335t;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:38:0x00a0, code lost:
        a();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:39:0x00a3, code lost:
        if (r5 == false) goto L_?;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:41:0x00a9, code lost:
        a();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:42:0x00ae, code lost:
        if (e3.a.f66335t != false) goto L_0x00b0;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:43:0x00b0, code lost:
        D();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:44:0x00b3, code lost:
        throw r5;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:58:?, code lost:
        return;
     */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Missing exception handler attribute for start block: B:36:0x009e */
    public final void B(InputStream inputStream) {
        int i14 = 0;
        while (true) {
            if (i14 < V.length) {
                this.f66347f[i14] = new HashMap<>();
                i14++;
            } else {
                if (!this.f66346e) {
                    BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream, 5000);
                    this.f66345d = n(bufferedInputStream);
                    inputStream = bufferedInputStream;
                }
                b bVar = new b(inputStream, ByteOrder.BIG_ENDIAN);
                if (!this.f66346e) {
                    switch (this.f66345d) {
                        case 0:
                        case 1:
                        case 2:
                        case 3:
                        case 5:
                        case 6:
                        case 8:
                        case 11:
                            r(bVar);
                            break;
                        case 4:
                            m(bVar, 0, 0);
                            a();
                            if (f66335t) {
                                D();
                                return;
                            }
                            return;
                        case 7:
                            o(bVar);
                            break;
                        case 9:
                            q(bVar);
                            a();
                            if (f66335t) {
                                D();
                                return;
                            }
                            return;
                        case 10:
                            t(bVar);
                            a();
                            if (f66335t) {
                                D();
                                return;
                            }
                            return;
                        case 12:
                            l(bVar);
                            break;
                        case 13:
                            p(bVar);
                            a();
                            if (f66335t) {
                                D();
                                return;
                            }
                            return;
                        case 14:
                            w(bVar);
                            a();
                            if (f66335t) {
                                D();
                                return;
                            }
                            return;
                    }
                } else {
                    u(bVar);
                }
                bVar.b((long) this.f66356o);
                N(bVar);
                a();
                if (!f66335t) {
                    return;
                }
            }
        }
        D();
    }

    public final void C(b bVar, int i14) throws IOException {
        ByteOrder E2 = E(bVar);
        this.f66349h = E2;
        bVar.f66366c = E2;
        int readUnsignedShort = bVar.readUnsignedShort();
        int i15 = this.f66345d;
        if (i15 == 7 || i15 == 10 || readUnsignedShort == 42) {
            int readInt = bVar.readInt();
            if (readInt < 8 || readInt >= i14) {
                throw new IOException(k.a("Invalid first Ifd offset: ", readInt));
            }
            int i16 = readInt - 8;
            if (i16 > 0 && bVar.skipBytes(i16) != i16) {
                throw new IOException(k.a("Couldn't jump to first Ifd: ", i16));
            }
            return;
        }
        StringBuilder a14 = b.d.a("Invalid start code: ");
        a14.append(Integer.toHexString(readUnsignedShort));
        throw new IOException(a14.toString());
    }

    public final void D() {
        for (int i14 = 0; i14 < this.f66347f.length; i14++) {
            this.f66347f[i14].size();
            for (Map.Entry<String, d> entry : this.f66347f[i14].entrySet()) {
                d value = entry.getValue();
                entry.getKey();
                value.toString();
                value.i(this.f66349h);
            }
        }
    }

    public final ByteOrder E(b bVar) throws IOException {
        short readShort = bVar.readShort();
        if (readShort == 18761) {
            return ByteOrder.LITTLE_ENDIAN;
        }
        if (readShort == 19789) {
            return ByteOrder.BIG_ENDIAN;
        }
        StringBuilder a14 = b.d.a("Invalid byte order: ");
        a14.append(Integer.toHexString(readShort));
        throw new IOException(a14.toString());
    }

    public final void F(byte[] bArr, int i14) throws IOException {
        b bVar = new b(bArr);
        C(bVar, bArr.length);
        G(bVar, i14);
    }

    /* JADX WARNING: Removed duplicated region for block: B:59:0x00e8  */
    /* JADX WARNING: Removed duplicated region for block: B:60:0x00f1  */
    /* JADX WARNING: Removed duplicated region for block: B:75:0x016e  */
    /* JADX WARNING: Removed duplicated region for block: B:76:0x0172  */
    /* JADX WARNING: Removed duplicated region for block: B:98:0x01be  */
    public final void G(b bVar, int i14) throws IOException {
        short s14;
        boolean z14;
        long j14;
        short s15;
        short s16;
        char c14;
        String str;
        e eVar;
        boolean z15;
        int i15;
        int i16;
        long j15;
        int i17;
        this.f66348g.add(Integer.valueOf(bVar.f66368e));
        if (bVar.f66368e + 2 <= bVar.f66367d) {
            short readShort = bVar.readShort();
            if ((readShort * 12) + bVar.f66368e <= bVar.f66367d && readShort > 0) {
                char c15 = 0;
                short s17 = 0;
                while (s17 < readShort) {
                    int readUnsignedShort = bVar.readUnsignedShort();
                    int readUnsignedShort2 = bVar.readUnsignedShort();
                    int readInt = bVar.readInt();
                    long j16 = ((long) bVar.f66368e) + 4;
                    e eVar2 = Z[i14].get(Integer.valueOf(readUnsignedShort));
                    boolean z16 = f66335t;
                    if (z16) {
                        Object[] objArr = new Object[5];
                        objArr[c15] = Integer.valueOf(i14);
                        objArr[1] = Integer.valueOf(readUnsignedShort);
                        objArr[2] = eVar2 != null ? eVar2.f66376b : null;
                        objArr[3] = Integer.valueOf(readUnsignedShort2);
                        objArr[4] = Integer.valueOf(readInt);
                        String.format("ifdType: %d, tagNumber: %d, tagName: %s, dataFormat: %d, numberOfComponents: %d", objArr);
                    }
                    if (eVar2 != null && readUnsignedShort2 > 0) {
                        int[] iArr = S;
                        if (readUnsignedShort2 < iArr.length) {
                            int i18 = eVar2.f66377c;
                            if (i18 == 7 || readUnsignedShort2 == 7 || i18 == readUnsignedShort2 || (i17 = eVar2.f66378d) == readUnsignedShort2 || ((i18 == 4 || i17 == 4) && readUnsignedShort2 == 3) || (((i18 == 9 || i17 == 9) && readUnsignedShort2 == 8) || ((i18 == 12 || i17 == 12) && readUnsignedShort2 == 11))) {
                                if (readUnsignedShort2 == 7) {
                                    readUnsignedShort2 = i18;
                                }
                                int i19 = iArr[readUnsignedShort2];
                                s14 = s17;
                                j14 = ((long) readInt) * ((long) i19);
                                if (j14 >= 0 && j14 <= 2147483647L) {
                                    z14 = true;
                                    if (!z14) {
                                        bVar.b(j16);
                                        s16 = readShort;
                                        s15 = s14;
                                    } else {
                                        if (j14 > 4) {
                                            int readInt2 = bVar.readInt();
                                            s16 = readShort;
                                            s15 = s14;
                                            if (this.f66345d == 7) {
                                                if ("MakerNote".equals(eVar2.f66376b)) {
                                                    this.f66357p = readInt2;
                                                } else if (i14 == 6 && "ThumbnailImage".equals(eVar2.f66376b)) {
                                                    this.f66358q = readInt2;
                                                    this.f66359r = readInt;
                                                    d e14 = d.e(6, this.f66349h);
                                                    eVar = eVar2;
                                                    i15 = readInt;
                                                    d b14 = d.b((long) this.f66358q, this.f66349h);
                                                    z15 = z16;
                                                    d b15 = d.b((long) this.f66359r, this.f66349h);
                                                    this.f66347f[4].put("Compression", e14);
                                                    this.f66347f[4].put("JPEGInterchangeFormat", b14);
                                                    this.f66347f[4].put("JPEGInterchangeFormatLength", b15);
                                                    j15 = (long) readInt2;
                                                    str = "Compression";
                                                    if (j15 + j14 > ((long) bVar.f66367d)) {
                                                        bVar.b(j15);
                                                    } else {
                                                        bVar.b(j16);
                                                    }
                                                }
                                            }
                                            eVar = eVar2;
                                            z15 = z16;
                                            i15 = readInt;
                                            j15 = (long) readInt2;
                                            str = "Compression";
                                            if (j15 + j14 > ((long) bVar.f66367d)) {
                                            }
                                        } else {
                                            s16 = readShort;
                                            str = "Compression";
                                            eVar = eVar2;
                                            s15 = s14;
                                            z15 = z16;
                                            i15 = readInt;
                                        }
                                        Integer num = f66328c0.get(Integer.valueOf(readUnsignedShort));
                                        if (num != null) {
                                            long j17 = -1;
                                            if (readUnsignedShort2 != 3) {
                                                if (readUnsignedShort2 == 4) {
                                                    j17 = bVar.a();
                                                } else if (readUnsignedShort2 == 8) {
                                                    i16 = bVar.readShort();
                                                } else if (readUnsignedShort2 == 9 || readUnsignedShort2 == 13) {
                                                    i16 = bVar.readInt();
                                                }
                                                c14 = 2;
                                                if (z15) {
                                                    String.format("Offset: %d, tagName: %s", Long.valueOf(j17), eVar.f66376b);
                                                }
                                                if (j17 > 0 && j17 < ((long) bVar.f66367d) && !this.f66348g.contains(Integer.valueOf((int) j17))) {
                                                    bVar.b(j17);
                                                    G(bVar, num.intValue());
                                                }
                                                bVar.b(j16);
                                            } else {
                                                i16 = bVar.readUnsignedShort();
                                            }
                                            j17 = (long) i16;
                                            c14 = 2;
                                            if (z15) {
                                            }
                                            bVar.b(j17);
                                            G(bVar, num.intValue());
                                            bVar.b(j16);
                                        } else {
                                            c14 = 2;
                                            byte[] bArr = new byte[((int) j14)];
                                            bVar.readFully(bArr);
                                            d dVar = new d(readUnsignedShort2, i15, (long) (bVar.f66368e + this.f66356o), bArr);
                                            this.f66347f[i14].put(eVar.f66376b, dVar);
                                            if ("DNGVersion".equals(eVar.f66376b)) {
                                                this.f66345d = 3;
                                            }
                                            if ((("Make".equals(eVar.f66376b) || "Model".equals(eVar.f66376b)) && dVar.i(this.f66349h).contains("PENTAX")) || (str.equals(eVar.f66376b) && dVar.h(this.f66349h) == 65535)) {
                                                this.f66345d = 8;
                                            }
                                            if (((long) bVar.f66368e) != j16) {
                                                bVar.b(j16);
                                            }
                                        }
                                        c15 = 0;
                                        s17 = (short) (s15 + 1);
                                        readShort = s16;
                                    }
                                    c14 = 2;
                                    c15 = 0;
                                    s17 = (short) (s15 + 1);
                                    readShort = s16;
                                }
                                z14 = false;
                                if (!z14) {
                                }
                                c14 = 2;
                                c15 = 0;
                                s17 = (short) (s15 + 1);
                                readShort = s16;
                            } else if (z16) {
                                String str2 = R[readUnsignedShort2];
                            }
                        }
                    }
                    s14 = s17;
                    j14 = 0;
                    z14 = false;
                    if (!z14) {
                    }
                    c14 = 2;
                    c15 = 0;
                    s17 = (short) (s15 + 1);
                    readShort = s16;
                }
                if (bVar.f66368e + 4 <= bVar.f66367d) {
                    int readInt3 = bVar.readInt();
                    if (f66335t) {
                        String.format("nextIfdOffset: %d", Integer.valueOf(readInt3));
                    }
                    long j18 = (long) readInt3;
                    if (j18 > 0 && readInt3 < bVar.f66367d && !this.f66348g.contains(Integer.valueOf(readInt3))) {
                        bVar.b(j18);
                        if (this.f66347f[4].isEmpty()) {
                            G(bVar, 4);
                        } else if (this.f66347f[5].isEmpty()) {
                            G(bVar, 5);
                        }
                    }
                }
            }
        }
    }

    public final void H(String str) {
        for (int i14 = 0; i14 < V.length; i14++) {
            this.f66347f[i14].remove(str);
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:56:0x00bb, code lost:
        r2 = e;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:57:0x00bc, code lost:
        r11 = null;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:58:0x00be, code lost:
        r2 = e;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:59:0x00bf, code lost:
        r10 = null;
        r11 = null;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:60:0x00c1, code lost:
        r12 = r11;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:62:0x00c4, code lost:
        r2 = th;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:63:0x00c5, code lost:
        r12 = null;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:94:0x0134, code lost:
        r0.delete();
     */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Removed duplicated region for block: B:62:0x00c4 A[ExcHandler: all (th java.lang.Throwable), Splitter:B:30:0x006a] */
    /* JADX WARNING: Removed duplicated region for block: B:71:0x00d5 A[Catch:{ Exception -> 0x0100, all -> 0x00fd }] */
    /* JADX WARNING: Removed duplicated region for block: B:72:0x00e4 A[Catch:{ Exception -> 0x0100, all -> 0x00fd }] */
    /* JADX WARNING: Removed duplicated region for block: B:94:0x0134  */
    public void I() throws IOException {
        byte[] bArr;
        FileOutputStream fileOutputStream;
        Throwable th4;
        Exception e14;
        FileInputStream fileInputStream;
        OutputStream outputStream;
        Throwable th5;
        InputStream inputStream;
        FileOutputStream fileOutputStream2;
        Exception e15;
        Throwable th6;
        Exception e16;
        FileInputStream fileInputStream2;
        FileOutputStream fileOutputStream3;
        int i14 = this.f66345d;
        if (!(i14 == 4 || i14 == 13 || i14 == 14)) {
            throw new IOException("ExifInterface only supports saving attributes on JPEG, PNG, or WebP formats.");
        } else if (this.f66343b == null && this.f66342a == null) {
            throw new IOException("ExifInterface does not support saving attributes for the current input.");
        } else {
            int i15 = this.f66355n;
            FileInputStream fileInputStream3 = null;
            if (i15 == 6 || i15 == 7) {
                bArr = v();
            } else {
                bArr = null;
            }
            this.f66354m = bArr;
            try {
                File createTempFile = File.createTempFile("temp", "tmp");
                if (this.f66342a != null) {
                    fileInputStream = new FileInputStream(this.f66342a);
                } else {
                    Os.lseek(this.f66343b, 0, OsConstants.SEEK_SET);
                    fileInputStream = new FileInputStream(this.f66343b);
                }
                try {
                    fileOutputStream = new FileOutputStream(createTempFile);
                } catch (Exception e17) {
                    e14 = e17;
                    fileOutputStream = null;
                    fileInputStream3 = fileInputStream;
                    try {
                        throw new IOException("Failed to copy original file to temp file", e14);
                    } catch (Throwable th7) {
                        th4 = th7;
                        c(fileInputStream3);
                        c(fileOutputStream);
                        throw th4;
                    }
                } catch (Throwable th8) {
                    th4 = th8;
                    fileOutputStream = null;
                    fileInputStream3 = fileInputStream;
                    c(fileInputStream3);
                    c(fileOutputStream);
                    throw th4;
                }
                try {
                    e(fileInputStream, fileOutputStream);
                    c(fileInputStream);
                    c(fileOutputStream);
                    try {
                        FileInputStream fileInputStream4 = new FileInputStream(createTempFile);
                        if (this.f66342a != null) {
                            fileOutputStream2 = new FileOutputStream(this.f66342a);
                        } else {
                            Os.lseek(this.f66343b, 0, OsConstants.SEEK_SET);
                            fileOutputStream2 = new FileOutputStream(this.f66343b);
                        }
                        inputStream = new BufferedInputStream(fileInputStream4);
                        try {
                            outputStream = new BufferedOutputStream(fileOutputStream2);
                        } catch (Exception e18) {
                            e15 = e18;
                            outputStream = null;
                            fileInputStream3 = fileInputStream4;
                            try {
                                fileInputStream2 = new FileInputStream(createTempFile);
                                try {
                                    if (this.f66342a == null) {
                                    }
                                    e(fileInputStream2, fileOutputStream3);
                                    try {
                                        c(fileInputStream2);
                                        c(fileOutputStream3);
                                        throw new IOException("Failed to save new file", e15);
                                    } catch (Throwable th9) {
                                        th5 = th9;
                                        fileInputStream3 = inputStream;
                                        c(fileInputStream3);
                                        c(outputStream);
                                        if (0 == 0) {
                                        }
                                        throw th5;
                                    }
                                } catch (Exception e19) {
                                    e16 = e19;
                                    fileInputStream3 = fileInputStream2;
                                    try {
                                        throw new IOException("Failed to save new file. Original file is stored in " + createTempFile.getAbsolutePath(), e16);
                                    } catch (Throwable th10) {
                                        th6 = th10;
                                        c(fileInputStream3);
                                        c(fileOutputStream2);
                                        throw th6;
                                    }
                                } catch (Throwable th11) {
                                    th6 = th11;
                                    fileInputStream3 = fileInputStream2;
                                    c(fileInputStream3);
                                    c(fileOutputStream2);
                                    throw th6;
                                }
                            } catch (Exception e24) {
                                e16 = e24;
                                throw new IOException("Failed to save new file. Original file is stored in " + createTempFile.getAbsolutePath(), e16);
                            } catch (Throwable th12) {
                                th6 = th12;
                                c(fileInputStream3);
                                c(fileOutputStream2);
                                throw th6;
                            }
                        } catch (Throwable th13) {
                            th5 = th13;
                            outputStream = null;
                            fileInputStream3 = inputStream;
                            c(fileInputStream3);
                            c(outputStream);
                            if (0 == 0) {
                            }
                            throw th5;
                        }
                        try {
                            int i16 = this.f66345d;
                            if (i16 == 4) {
                                J(inputStream, outputStream);
                            } else if (i16 == 13) {
                                K(inputStream, outputStream);
                            } else if (i16 == 14) {
                                L(inputStream, outputStream);
                            }
                            c(inputStream);
                            c(outputStream);
                            createTempFile.delete();
                            this.f66354m = null;
                        } catch (Exception e25) {
                            e15 = e25;
                            fileInputStream3 = fileInputStream4;
                            fileInputStream2 = new FileInputStream(createTempFile);
                            if (this.f66342a == null) {
                                Os.lseek(this.f66343b, 0, OsConstants.SEEK_SET);
                                fileOutputStream3 = new FileOutputStream(this.f66343b);
                            } else {
                                fileOutputStream3 = new FileOutputStream(this.f66342a);
                            }
                            e(fileInputStream2, fileOutputStream3);
                            c(fileInputStream2);
                            c(fileOutputStream3);
                            throw new IOException("Failed to save new file", e15);
                        }
                    } catch (Exception e26) {
                        e15 = e26;
                        fileOutputStream2 = null;
                        inputStream = null;
                        outputStream = null;
                        fileInputStream2 = new FileInputStream(createTempFile);
                        if (this.f66342a == null) {
                        }
                        e(fileInputStream2, fileOutputStream3);
                        c(fileInputStream2);
                        c(fileOutputStream3);
                        throw new IOException("Failed to save new file", e15);
                    } catch (Throwable th14) {
                    }
                } catch (Exception e27) {
                    e14 = e27;
                    fileInputStream3 = fileInputStream;
                    throw new IOException("Failed to copy original file to temp file", e14);
                } catch (Throwable th15) {
                    th4 = th15;
                    fileInputStream3 = fileInputStream;
                    c(fileInputStream3);
                    c(fileOutputStream);
                    throw th4;
                }
            } catch (Exception e28) {
                e14 = e28;
                fileOutputStream = null;
                throw new IOException("Failed to copy original file to temp file", e14);
            } catch (Throwable th16) {
                th4 = th16;
                fileOutputStream = null;
                c(fileInputStream3);
                c(fileOutputStream);
                throw th4;
            }
        }
    }

    public final void J(InputStream inputStream, OutputStream outputStream) throws IOException {
        if (f66335t) {
            Objects.toString(inputStream);
            Objects.toString(outputStream);
        }
        DataInputStream dataInputStream = new DataInputStream(inputStream);
        c cVar = new c(outputStream, ByteOrder.BIG_ENDIAN);
        if (dataInputStream.readByte() == -1) {
            cVar.f66369b.write(-1);
            if (dataInputStream.readByte() == -40) {
                cVar.f66369b.write(-40);
                d dVar = null;
                if (i("Xmp") != null && this.f66360s) {
                    dVar = this.f66347f[0].remove("Xmp");
                }
                cVar.f66369b.write(-1);
                cVar.f66369b.write(-31);
                S(cVar);
                if (dVar != null) {
                    this.f66347f[0].put("Xmp", dVar);
                }
                byte[] bArr = new byte[4096];
                while (dataInputStream.readByte() == -1) {
                    byte readByte = dataInputStream.readByte();
                    if (readByte == -39 || readByte == -38) {
                        cVar.f66369b.write(-1);
                        cVar.f66369b.write(readByte);
                        e(dataInputStream, cVar);
                        return;
                    } else if (readByte != -31) {
                        cVar.f66369b.write(-1);
                        cVar.f66369b.write(readByte);
                        int readUnsignedShort = dataInputStream.readUnsignedShort();
                        cVar.b((short) readUnsignedShort);
                        int i14 = readUnsignedShort - 2;
                        if (i14 >= 0) {
                            while (i14 > 0) {
                                int read = dataInputStream.read(bArr, 0, Math.min(i14, 4096));
                                if (read < 0) {
                                    break;
                                }
                                cVar.f66369b.write(bArr, 0, read);
                                i14 -= read;
                            }
                        } else {
                            throw new IOException("Invalid length");
                        }
                    } else {
                        int readUnsignedShort2 = dataInputStream.readUnsignedShort() - 2;
                        if (readUnsignedShort2 >= 0) {
                            byte[] bArr2 = new byte[6];
                            if (readUnsignedShort2 >= 6) {
                                if (dataInputStream.read(bArr2) != 6) {
                                    throw new IOException("Invalid exif");
                                } else if (Arrays.equals(bArr2, f66330e0)) {
                                    int i15 = readUnsignedShort2 - 6;
                                    if (dataInputStream.skipBytes(i15) != i15) {
                                        throw new IOException("Invalid length");
                                    }
                                }
                            }
                            cVar.f66369b.write(-1);
                            cVar.f66369b.write(readByte);
                            cVar.b((short) (readUnsignedShort2 + 2));
                            if (readUnsignedShort2 >= 6) {
                                readUnsignedShort2 -= 6;
                                cVar.f66369b.write(bArr2);
                            }
                            while (readUnsignedShort2 > 0) {
                                int read2 = dataInputStream.read(bArr, 0, Math.min(readUnsignedShort2, 4096));
                                if (read2 < 0) {
                                    break;
                                }
                                cVar.f66369b.write(bArr, 0, read2);
                                readUnsignedShort2 -= read2;
                            }
                        } else {
                            throw new IOException("Invalid length");
                        }
                    }
                }
                throw new IOException("Invalid marker");
            }
            throw new IOException("Invalid marker");
        }
        throw new IOException("Invalid marker");
    }

    public final void K(InputStream inputStream, OutputStream outputStream) throws IOException {
        Throwable th4;
        if (f66335t) {
            Objects.toString(inputStream);
            Objects.toString(outputStream);
        }
        DataInputStream dataInputStream = new DataInputStream(inputStream);
        ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
        c cVar = new c(outputStream, byteOrder);
        byte[] bArr = E;
        f(dataInputStream, cVar, bArr.length);
        int i14 = this.f66356o;
        if (i14 == 0) {
            int readInt = dataInputStream.readInt();
            cVar.a(readInt);
            f(dataInputStream, cVar, readInt + 4 + 4);
        } else {
            f(dataInputStream, cVar, ((i14 - bArr.length) - 4) - 4);
            dataInputStream.skipBytes(dataInputStream.readInt() + 4 + 4);
        }
        ByteArrayOutputStream byteArrayOutputStream = null;
        try {
            ByteArrayOutputStream byteArrayOutputStream2 = new ByteArrayOutputStream();
            try {
                c cVar2 = new c(byteArrayOutputStream2, byteOrder);
                S(cVar2);
                byte[] byteArray = ((ByteArrayOutputStream) cVar2.f66369b).toByteArray();
                cVar.f66369b.write(byteArray);
                CRC32 crc32 = new CRC32();
                crc32.update(byteArray, 4, byteArray.length - 4);
                cVar.a((int) crc32.getValue());
                c(byteArrayOutputStream2);
                e(dataInputStream, cVar);
            } catch (Throwable th5) {
                th4 = th5;
                byteArrayOutputStream = byteArrayOutputStream2;
                c(byteArrayOutputStream);
                throw th4;
            }
        } catch (Throwable th6) {
            th4 = th6;
            c(byteArrayOutputStream);
            throw th4;
        }
    }

    public final void L(InputStream inputStream, OutputStream outputStream) throws IOException {
        Throwable th4;
        Exception e14;
        int i14;
        int i15;
        int i16;
        int i17;
        if (f66335t) {
            Objects.toString(inputStream);
            Objects.toString(outputStream);
        }
        ByteOrder byteOrder = ByteOrder.LITTLE_ENDIAN;
        b bVar = new b(inputStream, byteOrder);
        c cVar = new c(outputStream, byteOrder);
        byte[] bArr = I;
        f(bVar, cVar, bArr.length);
        byte[] bArr2 = J;
        bVar.skipBytes(bArr2.length + 4);
        ByteArrayOutputStream byteArrayOutputStream = null;
        try {
            ByteArrayOutputStream byteArrayOutputStream2 = new ByteArrayOutputStream();
            try {
                c cVar2 = new c(byteArrayOutputStream2, byteOrder);
                int i18 = this.f66356o;
                if (i18 != 0) {
                    f(bVar, cVar2, ((i18 - ((bArr.length + 4) + bArr2.length)) - 4) - 4);
                    bVar.skipBytes(4);
                    bVar.skipBytes(bVar.readInt());
                    S(cVar2);
                } else {
                    byte[] bArr3 = new byte[4];
                    if (bVar.read(bArr3) == 4) {
                        byte[] bArr4 = M;
                        boolean z14 = false;
                        if (Arrays.equals(bArr3, bArr4)) {
                            int readInt = bVar.readInt();
                            byte[] bArr5 = new byte[(readInt % 2 == 1 ? readInt + 1 : readInt)];
                            bVar.read(bArr5);
                            bArr5[0] = (byte) (8 | bArr5[0]);
                            if (((bArr5[0] >> 1) & 1) == 1) {
                                z14 = true;
                            }
                            cVar2.f66369b.write(bArr4);
                            cVar2.a(readInt);
                            cVar2.f66369b.write(bArr5);
                            if (z14) {
                                g(bVar, cVar2, P, null);
                                while (true) {
                                    byte[] bArr6 = new byte[4];
                                    inputStream.read(bArr6);
                                    if (!Arrays.equals(bArr6, Q)) {
                                        break;
                                    }
                                    h(bVar, cVar2, bArr6);
                                }
                                S(cVar2);
                            } else {
                                g(bVar, cVar2, O, N);
                                S(cVar2);
                            }
                        } else {
                            byte[] bArr7 = O;
                            if (Arrays.equals(bArr3, bArr7) || Arrays.equals(bArr3, N)) {
                                int readInt2 = bVar.readInt();
                                int i19 = readInt2 % 2 == 1 ? readInt2 + 1 : readInt2;
                                byte[] bArr8 = new byte[3];
                                if (Arrays.equals(bArr3, bArr7)) {
                                    bVar.read(bArr8);
                                    byte[] bArr9 = new byte[3];
                                    if (bVar.read(bArr9) != 3 || !Arrays.equals(L, bArr9)) {
                                        throw new IOException("Encountered error while checking VP8 signature");
                                    }
                                    i17 = bVar.readInt();
                                    i16 = (i17 << 18) >> 18;
                                    i15 = (i17 << 2) >> 18;
                                    i19 -= 10;
                                    i14 = 0;
                                } else if (!Arrays.equals(bArr3, N)) {
                                    i17 = 0;
                                    i16 = 0;
                                    i15 = 0;
                                    i14 = 0;
                                } else if (bVar.readByte() == 47) {
                                    int readInt3 = bVar.readInt();
                                    i14 = readInt3 & 8;
                                    i19 -= 5;
                                    i15 = ((readInt3 << 4) >> 18) + 1;
                                    i17 = readInt3;
                                    i16 = ((readInt3 << 18) >> 18) + 1;
                                } else {
                                    throw new IOException("Encountered error while checking VP8L signature");
                                }
                                cVar2.f66369b.write(bArr4);
                                cVar2.a(10);
                                byte[] bArr10 = new byte[10];
                                bArr10[0] = (byte) (bArr10[0] | 8);
                                bArr10[0] = (byte) (bArr10[0] | (i14 << 4));
                                int i24 = i16 - 1;
                                int i25 = i15 - 1;
                                bArr10[4] = (byte) i24;
                                bArr10[5] = (byte) (i24 >> 8);
                                bArr10[6] = (byte) (i24 >> 16);
                                bArr10[7] = (byte) i25;
                                bArr10[8] = (byte) (i25 >> 8);
                                bArr10[9] = (byte) (i25 >> 16);
                                cVar2.f66369b.write(bArr10);
                                cVar2.f66369b.write(bArr3);
                                cVar2.a(readInt2);
                                if (Arrays.equals(bArr3, bArr7)) {
                                    cVar2.f66369b.write(bArr8);
                                    cVar2.f66369b.write(L);
                                    cVar2.a(i17);
                                } else if (Arrays.equals(bArr3, N)) {
                                    cVar2.write(47);
                                    cVar2.a(i17);
                                }
                                f(bVar, cVar2, i19);
                                S(cVar2);
                            }
                        }
                    } else {
                        throw new IOException("Encountered invalid length while parsing WebP chunk type");
                    }
                }
                e(bVar, cVar2);
                int size = byteArrayOutputStream2.size();
                byte[] bArr11 = J;
                cVar.a(size + bArr11.length);
                cVar.f66369b.write(bArr11);
                byteArrayOutputStream2.writeTo(cVar);
                c(byteArrayOutputStream2);
            } catch (Exception e15) {
                e14 = e15;
                byteArrayOutputStream = byteArrayOutputStream2;
                try {
                    throw new IOException("Failed to save WebP file", e14);
                } catch (Throwable th5) {
                    th4 = th5;
                    byteArrayOutputStream2 = byteArrayOutputStream;
                    c(byteArrayOutputStream2);
                    throw th4;
                }
            } catch (Throwable th6) {
                th4 = th6;
                c(byteArrayOutputStream2);
                throw th4;
            }
        } catch (Exception e16) {
            e14 = e16;
            throw new IOException("Failed to save WebP file", e14);
        }
    }

    /* JADX INFO: Can't fix incorrect switch cases order, some code will duplicate */
    public void M(String str, String str2) {
        String str3;
        int i14;
        e eVar;
        int i15;
        d dVar;
        String str4;
        String str5 = str;
        String str6 = str2;
        Objects.requireNonNull(str5, "tag shouldn't be null");
        if (("DateTime".equals(str5) || "DateTimeOriginal".equals(str5) || "DateTimeDigitized".equals(str5)) && str6 != null) {
            boolean find = f66333h0.matcher(str6).find();
            boolean find2 = f66334i0.matcher(str6).find();
            if (str2.length() != 19) {
                return;
            }
            if (!(find || find2)) {
                return;
            }
            if (find2) {
                str6 = str6.replaceAll("-", ":");
            }
        }
        if ("ISOSpeedRatings".equals(str5)) {
            str5 = "PhotographicSensitivity";
        }
        int i16 = 2;
        String str7 = "/";
        int i17 = 1;
        if (str6 != null && f66327b0.contains(str5)) {
            if (str5.equals("GPSTimeStamp")) {
                Matcher matcher = f66332g0.matcher(str6);
                if (matcher.find()) {
                    str6 = Integer.parseInt(matcher.group(1)) + "/1," + Integer.parseInt(matcher.group(2)) + "/1," + Integer.parseInt(matcher.group(3)) + "/1";
                } else {
                    return;
                }
            } else {
                try {
                    long parseDouble = (long) (Double.parseDouble(str6) * 10000.0d);
                    long j14 = 10000;
                    if (10000 == 0) {
                        j14 = 1;
                        parseDouble = 0;
                    }
                    str6 = parseDouble + str7 + j14;
                } catch (NumberFormatException unused) {
                    return;
                }
            }
        }
        int i18 = 0;
        int i19 = 0;
        while (i19 < V.length) {
            if ((i19 != 4 || this.f66350i) && (eVar = f66326a0[i19].get(str5)) != null) {
                if (str6 == null) {
                    this.f66347f[i19].remove(str5);
                } else {
                    Pair<Integer, Integer> x14 = x(str6);
                    if (eVar.f66377c == ((Integer) x14.first).intValue() || eVar.f66377c == ((Integer) x14.second).intValue()) {
                        i15 = eVar.f66377c;
                    } else {
                        int i24 = eVar.f66378d;
                        if (i24 == -1 || !(i24 == ((Integer) x14.first).intValue() || eVar.f66378d == ((Integer) x14.second).intValue())) {
                            int i25 = eVar.f66377c;
                            if (i25 == i17 || i25 == 7 || i25 == i16) {
                                i15 = i25;
                            } else if (f66335t) {
                                String[] strArr = R;
                                String str8 = strArr[eVar.f66377c];
                                int i26 = eVar.f66378d;
                                if (i26 != -1) {
                                    String str9 = strArr[i26];
                                }
                                String str10 = strArr[((Integer) x14.first).intValue()];
                                if (((Integer) x14.second).intValue() != -1) {
                                    String str11 = strArr[((Integer) x14.second).intValue()];
                                }
                            }
                        } else {
                            i15 = eVar.f66378d;
                        }
                    }
                    switch (i15) {
                        case 1:
                            str3 = str7;
                            HashMap<String, d> hashMap = this.f66347f[i19];
                            i17 = 1;
                            if (str6.length() == 1) {
                                i14 = 0;
                                if (str6.charAt(0) >= '0' && str6.charAt(0) <= '1') {
                                    dVar = new d(1, 1, new byte[]{(byte) (str6.charAt(0) - '0')});
                                    hashMap.put(str5, dVar);
                                    break;
                                }
                            } else {
                                i14 = 0;
                            }
                            byte[] bytes = str6.getBytes(f66329d0);
                            dVar = new d(1, bytes.length, bytes);
                            hashMap.put(str5, dVar);
                        case 2:
                        case 7:
                            str3 = str7;
                            this.f66347f[i19].put(str5, d.a(str6));
                            i14 = 0;
                            i17 = 1;
                            break;
                        case 3:
                            str3 = str7;
                            String[] split = str6.split(",", -1);
                            int[] iArr = new int[split.length];
                            for (int i27 = 0; i27 < split.length; i27++) {
                                iArr[i27] = Integer.parseInt(split[i27]);
                            }
                            this.f66347f[i19].put(str5, d.f(iArr, this.f66349h));
                            i14 = 0;
                            i17 = 1;
                            break;
                        case 4:
                            str3 = str7;
                            String[] split2 = str6.split(",", -1);
                            long[] jArr = new long[split2.length];
                            for (int i28 = 0; i28 < split2.length; i28++) {
                                jArr[i28] = Long.parseLong(split2[i28]);
                            }
                            this.f66347f[i19].put(str5, d.c(jArr, this.f66349h));
                            i14 = 0;
                            i17 = 1;
                            break;
                        case 5:
                            String[] split3 = str6.split(",", -1);
                            f[] fVarArr = new f[split3.length];
                            for (int i29 = 0; i29 < split3.length; i29++) {
                                String[] split4 = split3[i29].split(str7, -1);
                                fVarArr[i29] = new f((long) Double.parseDouble(split4[0]), (long) Double.parseDouble(split4[1]));
                            }
                            str3 = str7;
                            this.f66347f[i19].put(str5, d.d(fVarArr, this.f66349h));
                            i14 = 0;
                            i17 = 1;
                            break;
                        case 9:
                            str4 = str7;
                            String[] split5 = str6.split(",", -1);
                            int length = split5.length;
                            int[] iArr2 = new int[length];
                            for (int i34 = 0; i34 < split5.length; i34++) {
                                iArr2[i34] = Integer.parseInt(split5[i34]);
                            }
                            HashMap<String, d> hashMap2 = this.f66347f[i19];
                            ByteOrder byteOrder = this.f66349h;
                            ByteBuffer wrap = ByteBuffer.wrap(new byte[(S[9] * length)]);
                            wrap.order(byteOrder);
                            for (int i35 = 0; i35 < length; i35++) {
                                wrap.putInt(iArr2[i35]);
                            }
                            hashMap2.put(str5, new d(9, length, wrap.array()));
                            str3 = str4;
                            i14 = 0;
                            i17 = 1;
                            break;
                        case 10:
                            String[] split6 = str6.split(",", -1);
                            int length2 = split6.length;
                            f[] fVarArr2 = new f[length2];
                            int i36 = i18;
                            while (i36 < split6.length) {
                                String[] split7 = split6[i36].split(str7, -1);
                                fVarArr2[i36] = new f((long) Double.parseDouble(split7[i18]), (long) Double.parseDouble(split7[i17]));
                                i36++;
                                str7 = str7;
                                i17 = 1;
                                i18 = 0;
                            }
                            str4 = str7;
                            HashMap<String, d> hashMap3 = this.f66347f[i19];
                            ByteOrder byteOrder2 = this.f66349h;
                            ByteBuffer wrap2 = ByteBuffer.wrap(new byte[(S[10] * length2)]);
                            wrap2.order(byteOrder2);
                            for (int i37 = 0; i37 < length2; i37++) {
                                f fVar = fVarArr2[i37];
                                wrap2.putInt((int) fVar.f66379a);
                                wrap2.putInt((int) fVar.f66380b);
                            }
                            hashMap3.put(str5, new d(10, length2, wrap2.array()));
                            str3 = str4;
                            i14 = 0;
                            i17 = 1;
                            break;
                        case 12:
                            String[] split8 = str6.split(",", -1);
                            int length3 = split8.length;
                            double[] dArr = new double[length3];
                            for (int i38 = i18; i38 < split8.length; i38++) {
                                dArr[i38] = Double.parseDouble(split8[i38]);
                            }
                            HashMap<String, d> hashMap4 = this.f66347f[i19];
                            ByteOrder byteOrder3 = this.f66349h;
                            ByteBuffer wrap3 = ByteBuffer.wrap(new byte[(S[12] * length3)]);
                            wrap3.order(byteOrder3);
                            for (int i39 = i18; i39 < length3; i39++) {
                                wrap3.putDouble(dArr[i39]);
                            }
                            hashMap4.put(str5, new d(12, length3, wrap3.array()));
                            break;
                    }
                    i19++;
                    i18 = i14;
                    str7 = str3;
                    i16 = 2;
                }
            }
            str3 = str7;
            i14 = i18;
            i19++;
            i18 = i14;
            str7 = str3;
            i16 = 2;
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:26:0x0073  */
    /* JADX WARNING: Removed duplicated region for block: B:67:? A[RETURN, SYNTHETIC] */
    public final void N(b bVar) throws IOException {
        boolean z14;
        d dVar;
        int h14;
        HashMap<String, d> hashMap = this.f66347f[4];
        d dVar2 = hashMap.get("Compression");
        if (dVar2 != null) {
            int h15 = dVar2.h(this.f66349h);
            this.f66355n = h15;
            if (h15 != 1) {
                if (h15 == 6) {
                    y(bVar, hashMap);
                    return;
                } else if (h15 != 7) {
                    return;
                }
            }
            d dVar3 = hashMap.get("BitsPerSample");
            if (dVar3 != null) {
                int[] iArr = (int[]) dVar3.j(this.f66349h);
                int[] iArr2 = f66338w;
                if (Arrays.equals(iArr2, iArr) || (this.f66345d == 3 && (dVar = hashMap.get("PhotometricInterpretation")) != null && (((h14 = dVar.h(this.f66349h)) == 1 && Arrays.equals(iArr, f66339x)) || (h14 == 6 && Arrays.equals(iArr, iArr2))))) {
                    z14 = true;
                    if (!z14) {
                        d dVar4 = hashMap.get("StripOffsets");
                        d dVar5 = hashMap.get("StripByteCounts");
                        if (!(dVar4 == null || dVar5 == null)) {
                            long[] d14 = d(dVar4.j(this.f66349h));
                            long[] d15 = d(dVar5.j(this.f66349h));
                            if (!(d14 == null || d14.length == 0 || d15 == null || d15.length == 0 || d14.length != d15.length)) {
                                long j14 = 0;
                                for (long j15 : d15) {
                                    j14 += j15;
                                }
                                int i14 = (int) j14;
                                byte[] bArr = new byte[i14];
                                this.f66351j = true;
                                this.f66350i = true;
                                int i15 = 0;
                                int i16 = 0;
                                for (int i17 = 0; i17 < d14.length; i17++) {
                                    int i18 = (int) d14[i17];
                                    int i19 = (int) d15[i17];
                                    if (i17 < d14.length - 1 && ((long) (i18 + i19)) != d14[i17 + 1]) {
                                        this.f66351j = false;
                                    }
                                    int i24 = i18 - i15;
                                    if (i24 >= 0) {
                                        long j16 = (long) i24;
                                        if (bVar.skip(j16) == j16) {
                                            int i25 = i15 + i24;
                                            byte[] bArr2 = new byte[i19];
                                            if (bVar.read(bArr2) == i19) {
                                                i15 = i25 + i19;
                                                System.arraycopy(bArr2, 0, bArr, i16, i19);
                                                i16 += i19;
                                            } else {
                                                return;
                                            }
                                        } else {
                                            return;
                                        }
                                    } else {
                                        return;
                                    }
                                }
                                this.f66354m = bArr;
                                if (this.f66351j) {
                                    this.f66352k = (int) d14[0];
                                    this.f66353l = i14;
                                    return;
                                }
                                return;
                            }
                            return;
                        }
                        return;
                    }
                    return;
                }
            }
            z14 = false;
            if (!z14) {
            }
        } else {
            this.f66355n = 6;
            y(bVar, hashMap);
        }
    }

    public final void P(int i14, int i15) throws IOException {
        if (!this.f66347f[i14].isEmpty() && !this.f66347f[i15].isEmpty()) {
            d dVar = this.f66347f[i14].get("ImageLength");
            d dVar2 = this.f66347f[i14].get("ImageWidth");
            d dVar3 = this.f66347f[i15].get("ImageLength");
            d dVar4 = this.f66347f[i15].get("ImageWidth");
            if (dVar != null && dVar2 != null && dVar3 != null && dVar4 != null) {
                int h14 = dVar.h(this.f66349h);
                int h15 = dVar2.h(this.f66349h);
                int h16 = dVar3.h(this.f66349h);
                int h17 = dVar4.h(this.f66349h);
                if (h14 < h16 && h15 < h17) {
                    HashMap<String, d>[] hashMapArr = this.f66347f;
                    HashMap<String, d> hashMap = hashMapArr[i14];
                    hashMapArr[i14] = hashMapArr[i15];
                    hashMapArr[i15] = hashMap;
                }
            }
        }
    }

    public final void Q(b bVar, int i14) throws IOException {
        d dVar;
        d dVar2;
        d dVar3 = this.f66347f[i14].get("DefaultCropSize");
        d dVar4 = this.f66347f[i14].get("SensorTopBorder");
        d dVar5 = this.f66347f[i14].get("SensorLeftBorder");
        d dVar6 = this.f66347f[i14].get("SensorBottomBorder");
        d dVar7 = this.f66347f[i14].get("SensorRightBorder");
        if (dVar3 != null) {
            if (dVar3.f66371a == 5) {
                f[] fVarArr = (f[]) dVar3.j(this.f66349h);
                if (fVarArr == null || fVarArr.length != 2) {
                    Arrays.toString(fVarArr);
                    return;
                }
                f fVar = fVarArr[0];
                f[] fVarArr2 = {fVar};
                dVar2 = d.d(fVarArr2, this.f66349h);
                f fVar2 = fVarArr[1];
                f[] fVarArr3 = {fVar2};
                dVar = d.d(fVarArr3, this.f66349h);
            } else {
                int[] iArr = (int[]) dVar3.j(this.f66349h);
                if (iArr == null || iArr.length != 2) {
                    Arrays.toString(iArr);
                    return;
                } else {
                    dVar2 = d.e(iArr[0], this.f66349h);
                    dVar = d.e(iArr[1], this.f66349h);
                }
            }
            this.f66347f[i14].put("ImageWidth", dVar2);
            this.f66347f[i14].put("ImageLength", dVar);
        } else if (dVar4 == null || dVar5 == null || dVar6 == null || dVar7 == null) {
            d dVar8 = this.f66347f[i14].get("ImageLength");
            d dVar9 = this.f66347f[i14].get("ImageWidth");
            if (dVar8 == null || dVar9 == null) {
                d dVar10 = this.f66347f[i14].get("JPEGInterchangeFormat");
                d dVar11 = this.f66347f[i14].get("JPEGInterchangeFormatLength");
                if (dVar10 != null && dVar11 != null) {
                    int h14 = dVar10.h(this.f66349h);
                    int h15 = dVar10.h(this.f66349h);
                    bVar.b((long) h14);
                    byte[] bArr = new byte[h15];
                    bVar.read(bArr);
                    m(new b(bArr), h14, i14);
                }
            }
        } else {
            int h16 = dVar4.h(this.f66349h);
            int h17 = dVar6.h(this.f66349h);
            int h18 = dVar7.h(this.f66349h);
            int h19 = dVar5.h(this.f66349h);
            if (h17 > h16 && h18 > h19) {
                d e14 = d.e(h17 - h16, this.f66349h);
                d e15 = d.e(h18 - h19, this.f66349h);
                this.f66347f[i14].put("ImageLength", e14);
                this.f66347f[i14].put("ImageWidth", e15);
            }
        }
    }

    public final void R() throws IOException {
        P(0, 5);
        P(0, 4);
        P(5, 4);
        d dVar = this.f66347f[1].get("PixelXDimension");
        d dVar2 = this.f66347f[1].get("PixelYDimension");
        if (!(dVar == null || dVar2 == null)) {
            this.f66347f[0].put("ImageWidth", dVar);
            this.f66347f[0].put("ImageLength", dVar2);
        }
        if (this.f66347f[4].isEmpty() && A(this.f66347f[5])) {
            HashMap<String, d>[] hashMapArr = this.f66347f;
            hashMapArr[4] = hashMapArr[5];
            hashMapArr[5] = new HashMap<>();
        }
        A(this.f66347f[4]);
    }

    public final int S(c cVar) throws IOException {
        e[][] eVarArr = V;
        int[] iArr = new int[eVarArr.length];
        int[] iArr2 = new int[eVarArr.length];
        for (e eVar : W) {
            H(eVar.f66376b);
        }
        H(X.f66376b);
        H(Y.f66376b);
        for (int i14 = 0; i14 < V.length; i14++) {
            for (Object obj : this.f66347f[i14].entrySet().toArray()) {
                Map.Entry entry = (Map.Entry) obj;
                if (entry.getValue() == null) {
                    this.f66347f[i14].remove(entry.getKey());
                }
            }
        }
        if (!this.f66347f[1].isEmpty()) {
            this.f66347f[0].put(W[1].f66376b, d.b(0, this.f66349h));
        }
        if (!this.f66347f[2].isEmpty()) {
            this.f66347f[0].put(W[2].f66376b, d.b(0, this.f66349h));
        }
        if (!this.f66347f[3].isEmpty()) {
            this.f66347f[1].put(W[3].f66376b, d.b(0, this.f66349h));
        }
        if (this.f66350i) {
            this.f66347f[4].put(X.f66376b, d.b(0, this.f66349h));
            this.f66347f[4].put(Y.f66376b, d.b((long) this.f66353l, this.f66349h));
        }
        for (int i15 = 0; i15 < V.length; i15++) {
            int i16 = 0;
            for (Map.Entry<String, d> entry2 : this.f66347f[i15].entrySet()) {
                d value = entry2.getValue();
                Objects.requireNonNull(value);
                int i17 = S[value.f66371a] * value.f66372b;
                if (i17 > 4) {
                    i16 += i17;
                }
            }
            iArr2[i15] = iArr2[i15] + i16;
        }
        int i18 = 8;
        for (int i19 = 0; i19 < V.length; i19++) {
            if (!this.f66347f[i19].isEmpty()) {
                iArr[i19] = i18;
                i18 = (this.f66347f[i19].size() * 12) + 2 + 4 + iArr2[i19] + i18;
            }
        }
        if (this.f66350i) {
            this.f66347f[4].put(X.f66376b, d.b((long) i18, this.f66349h));
            this.f66352k = i18;
            i18 += this.f66353l;
        }
        if (this.f66345d == 4) {
            i18 += 8;
        }
        if (f66335t) {
            for (int i24 = 0; i24 < V.length; i24++) {
                String.format("index: %d, offsets: %d, tag count: %d, data sizes: %d, total size: %d", Integer.valueOf(i24), Integer.valueOf(iArr[i24]), Integer.valueOf(this.f66347f[i24].size()), Integer.valueOf(iArr2[i24]), Integer.valueOf(i18));
            }
        }
        if (!this.f66347f[1].isEmpty()) {
            this.f66347f[0].put(W[1].f66376b, d.b((long) iArr[1], this.f66349h));
        }
        if (!this.f66347f[2].isEmpty()) {
            this.f66347f[0].put(W[2].f66376b, d.b((long) iArr[2], this.f66349h));
        }
        if (!this.f66347f[3].isEmpty()) {
            this.f66347f[1].put(W[3].f66376b, d.b((long) iArr[3], this.f66349h));
        }
        int i25 = this.f66345d;
        if (i25 == 4) {
            cVar.b((short) i18);
            cVar.f66369b.write(f66330e0);
        } else if (i25 == 13) {
            cVar.a(i18);
            cVar.f66369b.write(F);
        } else if (i25 == 14) {
            cVar.f66369b.write(K);
            cVar.a(i18);
        }
        cVar.b(this.f66349h == ByteOrder.BIG_ENDIAN ? (short) 19789 : 18761);
        cVar.f66370c = this.f66349h;
        cVar.b((short) 42);
        cVar.a((int) 8);
        for (int i26 = 0; i26 < V.length; i26++) {
            if (!this.f66347f[i26].isEmpty()) {
                cVar.b((short) this.f66347f[i26].size());
                int size = (this.f66347f[i26].size() * 12) + iArr[i26] + 2 + 4;
                for (Map.Entry<String, d> entry3 : this.f66347f[i26].entrySet()) {
                    int i27 = f66326a0[i26].get(entry3.getKey()).f66375a;
                    d value2 = entry3.getValue();
                    Objects.requireNonNull(value2);
                    int i28 = S[value2.f66371a] * value2.f66372b;
                    cVar.b((short) i27);
                    cVar.b((short) value2.f66371a);
                    cVar.a(value2.f66372b);
                    if (i28 > 4) {
                        cVar.a((int) ((long) size));
                        size += i28;
                    } else {
                        cVar.f66369b.write(value2.f66374d);
                        if (i28 < 4) {
                            while (i28 < 4) {
                                cVar.f66369b.write(0);
                                i28++;
                            }
                        }
                    }
                }
                if (i26 != 0 || this.f66347f[4].isEmpty()) {
                    cVar.a((int) 0);
                } else {
                    cVar.a((int) ((long) iArr[4]));
                }
                for (Map.Entry<String, d> entry4 : this.f66347f[i26].entrySet()) {
                    byte[] bArr = entry4.getValue().f66374d;
                    if (bArr.length > 4) {
                        cVar.f66369b.write(bArr, 0, bArr.length);
                    }
                }
            }
        }
        if (this.f66350i) {
            cVar.f66369b.write(v());
        }
        if (this.f66345d == 14 && i18 % 2 == 1) {
            cVar.f66369b.write(0);
        }
        cVar.f66370c = ByteOrder.BIG_ENDIAN;
        return i18;
    }

    public final void a() {
        String i14 = i("DateTimeOriginal");
        if (i14 != null && i("DateTime") == null) {
            this.f66347f[0].put("DateTime", d.a(i14));
        }
        if (i("ImageWidth") == null) {
            this.f66347f[0].put("ImageWidth", d.b(0, this.f66349h));
        }
        if (i("ImageLength") == null) {
            this.f66347f[0].put("ImageLength", d.b(0, this.f66349h));
        }
        if (i("Orientation") == null) {
            this.f66347f[0].put("Orientation", d.b(0, this.f66349h));
        }
        if (i("LightSource") == null) {
            this.f66347f[1].put("LightSource", d.b(0, this.f66349h));
        }
    }

    public final void g(b bVar, c cVar, byte[] bArr, byte[] bArr2) throws IOException {
        String str;
        while (true) {
            byte[] bArr3 = new byte[4];
            if (bVar.read(bArr3) != 4) {
                StringBuilder a14 = b.d.a("Encountered invalid length while copying WebP chunks up tochunk type ");
                Charset charset = f66329d0;
                a14.append(new String(bArr, charset));
                if (bArr2 == null) {
                    str = "";
                } else {
                    StringBuilder a15 = b.d.a(" or ");
                    a15.append(new String(bArr2, charset));
                    str = a15.toString();
                }
                a14.append(str);
                throw new IOException(a14.toString());
            }
            h(bVar, cVar, bArr3);
            if (Arrays.equals(bArr3, bArr)) {
                return;
            }
            if (bArr2 != null && Arrays.equals(bArr3, bArr2)) {
                return;
            }
        }
    }

    public final void h(b bVar, c cVar, byte[] bArr) throws IOException {
        int readInt = bVar.readInt();
        cVar.f66369b.write(bArr);
        cVar.a(readInt);
        if (readInt % 2 == 1) {
            readInt++;
        }
        f(bVar, cVar, readInt);
    }

    public String i(String str) {
        Objects.requireNonNull(str, "tag shouldn't be null");
        d k14 = k(str);
        if (k14 != null) {
            if (!f66327b0.contains(str)) {
                return k14.i(this.f66349h);
            }
            if (str.equals("GPSTimeStamp")) {
                int i14 = k14.f66371a;
                if (i14 != 5 && i14 != 10) {
                    return null;
                }
                f[] fVarArr = (f[]) k14.j(this.f66349h);
                if (fVarArr == null || fVarArr.length != 3) {
                    Arrays.toString(fVarArr);
                    return null;
                }
                return String.format("%02d:%02d:%02d", Integer.valueOf((int) (((float) fVarArr[0].f66379a) / ((float) fVarArr[0].f66380b))), Integer.valueOf((int) (((float) fVarArr[1].f66379a) / ((float) fVarArr[1].f66380b))), Integer.valueOf((int) (((float) fVarArr[2].f66379a) / ((float) fVarArr[2].f66380b))));
            }
            try {
                return Double.toString(k14.g(this.f66349h));
            } catch (NumberFormatException unused) {
            }
        }
        return null;
    }

    public int j(String str, int i14) {
        d k14 = k(str);
        if (k14 == null) {
            return i14;
        }
        try {
            return k14.h(this.f66349h);
        } catch (NumberFormatException unused) {
            return i14;
        }
    }

    public final d k(String str) {
        if ("ISOSpeedRatings".equals(str)) {
            str = "PhotographicSensitivity";
        }
        for (int i14 = 0; i14 < V.length; i14++) {
            d dVar = this.f66347f[i14].get(str);
            if (dVar != null) {
                return dVar;
            }
        }
        return null;
    }

    public final void l(b bVar) throws IOException {
        String str;
        String str2;
        MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
        try {
            mediaMetadataRetriever.setDataSource(new C0748a(this, bVar));
            String extractMetadata = mediaMetadataRetriever.extractMetadata(33);
            String extractMetadata2 = mediaMetadataRetriever.extractMetadata(34);
            String extractMetadata3 = mediaMetadataRetriever.extractMetadata(26);
            String extractMetadata4 = mediaMetadataRetriever.extractMetadata(17);
            String str3 = null;
            if ("yes".equals(extractMetadata3)) {
                str3 = mediaMetadataRetriever.extractMetadata(29);
                str2 = mediaMetadataRetriever.extractMetadata(30);
                str = mediaMetadataRetriever.extractMetadata(31);
            } else if ("yes".equals(extractMetadata4)) {
                str3 = mediaMetadataRetriever.extractMetadata(18);
                str2 = mediaMetadataRetriever.extractMetadata(19);
                str = mediaMetadataRetriever.extractMetadata(24);
            } else {
                str2 = null;
                str = null;
            }
            if (str3 != null) {
                this.f66347f[0].put("ImageWidth", d.e(Integer.parseInt(str3), this.f66349h));
            }
            if (str2 != null) {
                this.f66347f[0].put("ImageLength", d.e(Integer.parseInt(str2), this.f66349h));
            }
            if (str != null) {
                int i14 = 1;
                int parseInt = Integer.parseInt(str);
                if (parseInt == 90) {
                    i14 = 6;
                } else if (parseInt == 180) {
                    i14 = 3;
                } else if (parseInt == 270) {
                    i14 = 8;
                }
                this.f66347f[0].put("Orientation", d.e(i14, this.f66349h));
            }
            if (!(extractMetadata == null || extractMetadata2 == null)) {
                int parseInt2 = Integer.parseInt(extractMetadata);
                int parseInt3 = Integer.parseInt(extractMetadata2);
                if (parseInt3 > 6) {
                    bVar.b((long) parseInt2);
                    byte[] bArr = new byte[6];
                    if (bVar.read(bArr) == 6) {
                        int i15 = parseInt2 + 6;
                        int i16 = parseInt3 - 6;
                        if (Arrays.equals(bArr, f66330e0)) {
                            byte[] bArr2 = new byte[i16];
                            if (bVar.read(bArr2) == i16) {
                                this.f66356o = i15;
                                F(bArr2, 0);
                            } else {
                                throw new IOException("Can't read exif");
                            }
                        } else {
                            throw new IOException("Invalid identifier");
                        }
                    } else {
                        throw new IOException("Can't read identifier");
                    }
                } else {
                    throw new IOException("Invalid exif length");
                }
            }
        } finally {
            mediaMetadataRetriever.release();
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:31:0x006f A[FALL_THROUGH] */
    public final void m(b bVar, int i14, int i15) throws IOException {
        if (f66335t) {
            Objects.toString(bVar);
        }
        int i16 = 0;
        bVar.mark(0);
        bVar.f66366c = ByteOrder.BIG_ENDIAN;
        byte readByte = bVar.readByte();
        byte b14 = -1;
        if (readByte != -1) {
            StringBuilder a14 = b.d.a("Invalid marker: ");
            a14.append(Integer.toHexString(readByte & UByte.MAX_VALUE));
            throw new IOException(a14.toString());
        } else if (bVar.readByte() == -40) {
            int i17 = 2;
            int i18 = 2;
            while (true) {
                byte readByte2 = bVar.readByte();
                if (readByte2 == b14) {
                    int i19 = i17 + 1;
                    byte readByte3 = bVar.readByte();
                    boolean z14 = f66335t;
                    if (z14) {
                        Integer.toHexString(readByte3 & UByte.MAX_VALUE);
                    }
                    int i24 = i19 + 1;
                    if (readByte3 == -39 || readByte3 == -38) {
                        bVar.f66366c = this.f66349h;
                    } else {
                        int readUnsignedShort = bVar.readUnsignedShort() - i18;
                        int i25 = i24 + i18;
                        if (z14) {
                            Integer.toHexString(readByte3 & UByte.MAX_VALUE);
                        }
                        if (readUnsignedShort >= 0) {
                            if (readByte3 == -31) {
                                byte[] bArr = new byte[readUnsignedShort];
                                bVar.readFully(bArr);
                                int i26 = i25 + readUnsignedShort;
                                byte[] bArr2 = f66330e0;
                                if (O(bArr, bArr2)) {
                                    byte[] copyOfRange = Arrays.copyOfRange(bArr, bArr2.length, readUnsignedShort);
                                    this.f66356o = i14 + i25 + bArr2.length;
                                    F(copyOfRange, i15);
                                    N(new b(copyOfRange));
                                } else {
                                    byte[] bArr3 = f66331f0;
                                    if (O(bArr, bArr3)) {
                                        int length = i25 + bArr3.length;
                                        byte[] copyOfRange2 = Arrays.copyOfRange(bArr, bArr3.length, readUnsignedShort);
                                        if (i("Xmp") == null) {
                                            this.f66347f[i16].put("Xmp", new d(1, copyOfRange2.length, (long) length, copyOfRange2));
                                            this.f66360s = true;
                                        }
                                    }
                                }
                                i16 = 0;
                                i25 = i26;
                            } else if (readByte3 != -2) {
                                switch (readByte3) {
                                    default:
                                        switch (readByte3) {
                                            default:
                                                switch (readByte3) {
                                                    default:
                                                        switch (readByte3) {
                                                            case -51:
                                                            case -50:
                                                            case -49:
                                                                break;
                                                            default:
                                                                i16 = readUnsignedShort;
                                                                break;
                                                        }
                                                    case -55:
                                                    case -54:
                                                    case -53:
                                                        if (bVar.skipBytes(1) == 1) {
                                                            this.f66347f[i15].put("ImageLength", d.b((long) bVar.readUnsignedShort(), this.f66349h));
                                                            this.f66347f[i15].put("ImageWidth", d.b((long) bVar.readUnsignedShort(), this.f66349h));
                                                            i16 = readUnsignedShort - 5;
                                                            break;
                                                        } else {
                                                            throw new IOException("Invalid SOFx");
                                                        }
                                                }
                                            case -59:
                                            case -58:
                                            case -57:
                                                break;
                                        }
                                    case -64:
                                    case -63:
                                    case -62:
                                    case -61:
                                        break;
                                }
                            } else {
                                byte[] bArr4 = new byte[readUnsignedShort];
                                if (bVar.read(bArr4) != readUnsignedShort) {
                                    throw new IOException("Invalid exif");
                                } else if (i("UserComment") == null) {
                                    this.f66347f[1].put("UserComment", d.a(new String(bArr4, f66329d0)));
                                }
                            }
                            if (i16 < 0) {
                                throw new IOException("Invalid length");
                            } else if (bVar.skipBytes(i16) == i16) {
                                i17 = i25 + i16;
                                i16 = 0;
                                i18 = 2;
                                b14 = -1;
                            } else {
                                throw new IOException("Invalid JPEG segment");
                            }
                        } else {
                            throw new IOException("Invalid length");
                        }
                    }
                } else {
                    StringBuilder a15 = b.d.a("Invalid marker:");
                    a15.append(Integer.toHexString(readByte2 & UByte.MAX_VALUE));
                    throw new IOException(a15.toString());
                }
            }
            bVar.f66366c = this.f66349h;
        } else {
            StringBuilder a16 = b.d.a("Invalid marker: ");
            a16.append(Integer.toHexString(readByte & UByte.MAX_VALUE));
            throw new IOException(a16.toString());
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:67:0x00c4, code lost:
        if (r6 != null) goto L_0x00c6;
     */
    /* JADX WARNING: Removed duplicated region for block: B:100:0x010b A[SYNTHETIC, Splitter:B:100:0x010b] */
    /* JADX WARNING: Removed duplicated region for block: B:115:0x012f  */
    /* JADX WARNING: Removed duplicated region for block: B:119:0x0135  */
    /* JADX WARNING: Removed duplicated region for block: B:122:0x013b A[RETURN] */
    /* JADX WARNING: Removed duplicated region for block: B:123:0x013e  */
    /* JADX WARNING: Removed duplicated region for block: B:63:0x00bf  */
    /* JADX WARNING: Removed duplicated region for block: B:90:0x00fa  */
    /* JADX WARNING: Removed duplicated region for block: B:96:0x0103  */
    /* JADX WARNING: Removed duplicated region for block: B:99:0x0109 A[RETURN] */
    public final int n(BufferedInputStream bufferedInputStream) throws IOException {
        boolean z14;
        boolean z15;
        boolean z16;
        boolean z17;
        a aVar;
        boolean z18;
        boolean z19;
        boolean z24;
        Throwable th4;
        b bVar;
        Throwable th5;
        b bVar2;
        Throwable th6;
        bufferedInputStream.mark(5000);
        byte[] bArr = new byte[5000];
        bufferedInputStream.read(bArr);
        bufferedInputStream.reset();
        int i14 = 0;
        while (true) {
            byte[] bArr2 = f66340y;
            z14 = true;
            if (i14 >= bArr2.length) {
                z15 = true;
                break;
            } else if (bArr[i14] != bArr2[i14]) {
                z15 = false;
                break;
            } else {
                i14++;
            }
        }
        if (z15) {
            return 4;
        }
        byte[] bytes = "FUJIFILMCCD-RAW".getBytes(Charset.defaultCharset());
        int i15 = 0;
        while (true) {
            if (i15 >= bytes.length) {
                z16 = true;
                break;
            } else if (bArr[i15] != bytes[i15]) {
                z16 = false;
                break;
            } else {
                i15++;
            }
        }
        if (z16) {
            return 9;
        }
        b bVar3 = null;
        try {
            bVar2 = new b(bArr);
            try {
                long readInt = (long) bVar2.readInt();
                byte[] bArr3 = new byte[4];
                bVar2.read(bArr3);
                if (Arrays.equals(bArr3, f66341z)) {
                    long j14 = 16;
                    if (readInt == 1) {
                        readInt = bVar2.readLong();
                        if (readInt < 16) {
                        }
                    } else {
                        j14 = 8;
                    }
                    long j15 = (long) 5000;
                    if (readInt > j15) {
                        readInt = j15;
                    }
                    long j16 = readInt - j14;
                    if (j16 >= 8) {
                        byte[] bArr4 = new byte[4];
                        long j17 = 0;
                        boolean z25 = false;
                        boolean z26 = false;
                        while (true) {
                            if (j17 >= j16 / 4) {
                                break;
                            } else if (bVar2.read(bArr4) != 4) {
                                break;
                            } else {
                                if (j17 != 1) {
                                    if (Arrays.equals(bArr4, A)) {
                                        z25 = true;
                                    } else if (Arrays.equals(bArr4, B)) {
                                        z26 = true;
                                    }
                                    if (z25 && z26) {
                                        bVar2.close();
                                        z17 = true;
                                        break;
                                    }
                                }
                                j17++;
                            }
                        }
                    }
                }
            } catch (Exception unused) {
            } catch (Throwable th7) {
                th6 = th7;
                bVar3 = bVar2;
                if (bVar3 != null) {
                    bVar3.close();
                }
                throw th6;
            }
        } catch (Exception unused2) {
            bVar2 = null;
        } catch (Throwable th8) {
            th6 = th8;
            if (bVar3 != null) {
            }
            throw th6;
        }
        bVar2.close();
        z17 = false;
        if (z17) {
            return 12;
        }
        try {
            bVar = new b(bArr);
            aVar = this;
            try {
                ByteOrder E2 = aVar.E(bVar);
                aVar.f66349h = E2;
                bVar.f66366c = E2;
                short readShort = bVar.readShort();
                z18 = readShort == 20306 || readShort == 21330;
                bVar.close();
            } catch (Exception unused3) {
                if (bVar != null) {
                }
                z18 = false;
                if (z18) {
                }
            } catch (Throwable th9) {
                th5 = th9;
                bVar3 = bVar;
                if (bVar3 != null) {
                }
                throw th5;
            }
        } catch (Exception unused4) {
            aVar = this;
            bVar = null;
            if (bVar != null) {
                bVar.close();
            }
            z18 = false;
            if (z18) {
            }
        } catch (Throwable th10) {
            th5 = th10;
            if (bVar3 != null) {
                bVar3.close();
            }
            throw th5;
        }
        if (z18) {
            return 7;
        }
        try {
            b bVar4 = new b(bArr);
            try {
                ByteOrder E3 = aVar.E(bVar4);
                aVar.f66349h = E3;
                bVar4.f66366c = E3;
                z19 = bVar4.readShort() == 85;
                bVar4.close();
            } catch (Exception unused5) {
                bVar3 = bVar4;
                if (bVar3 != null) {
                }
                z19 = false;
                if (z19) {
                }
            } catch (Throwable th11) {
                th4 = th11;
                bVar3 = bVar4;
                if (bVar3 != null) {
                }
                throw th4;
            }
        } catch (Exception unused6) {
            if (bVar3 != null) {
                bVar3.close();
            }
            z19 = false;
            if (z19) {
            }
        } catch (Throwable th12) {
            th4 = th12;
            if (bVar3 != null) {
                bVar3.close();
            }
            throw th4;
        }
        if (z19) {
            return 10;
        }
        int i16 = 0;
        while (true) {
            byte[] bArr5 = E;
            if (i16 >= bArr5.length) {
                z24 = true;
                break;
            } else if (bArr[i16] != bArr5[i16]) {
                z24 = false;
                break;
            } else {
                i16++;
            }
        }
        if (z24) {
            return 13;
        }
        int i17 = 0;
        while (true) {
            byte[] bArr6 = I;
            if (i17 >= bArr6.length) {
                int i18 = 0;
                while (true) {
                    byte[] bArr7 = J;
                    if (i18 >= bArr7.length) {
                        break;
                    } else if (bArr[I.length + i18 + 4] != bArr7[i18]) {
                        break;
                    } else {
                        i18++;
                    }
                }
            } else if (bArr[i17] != bArr6[i17]) {
                break;
            } else {
                i17++;
            }
        }
        z14 = false;
        return z14 ? 14 : 0;
    }

    public final void o(b bVar) throws IOException {
        r(bVar);
        d dVar = this.f66347f[1].get("MakerNote");
        if (dVar != null) {
            b bVar2 = new b(dVar.f66374d);
            bVar2.f66366c = this.f66349h;
            byte[] bArr = C;
            byte[] bArr2 = new byte[bArr.length];
            bVar2.readFully(bArr2);
            bVar2.b(0);
            byte[] bArr3 = D;
            byte[] bArr4 = new byte[bArr3.length];
            bVar2.readFully(bArr4);
            if (Arrays.equals(bArr2, bArr)) {
                bVar2.b(8);
            } else if (Arrays.equals(bArr4, bArr3)) {
                bVar2.b(12);
            }
            G(bVar2, 6);
            d dVar2 = this.f66347f[7].get("PreviewImageStart");
            d dVar3 = this.f66347f[7].get("PreviewImageLength");
            if (!(dVar2 == null || dVar3 == null)) {
                this.f66347f[5].put("JPEGInterchangeFormat", dVar2);
                this.f66347f[5].put("JPEGInterchangeFormatLength", dVar3);
            }
            d dVar4 = this.f66347f[8].get("AspectFrame");
            if (dVar4 != null) {
                int[] iArr = (int[]) dVar4.j(this.f66349h);
                if (iArr == null || iArr.length != 4) {
                    Arrays.toString(iArr);
                } else if (iArr[2] > iArr[0] && iArr[3] > iArr[1]) {
                    int i14 = (iArr[2] - iArr[0]) + 1;
                    int i15 = (iArr[3] - iArr[1]) + 1;
                    if (i14 < i15) {
                        int i16 = i14 + i15;
                        i15 = i16 - i15;
                        i14 = i16 - i15;
                    }
                    d e14 = d.e(i14, this.f66349h);
                    d e15 = d.e(i15, this.f66349h);
                    this.f66347f[0].put("ImageWidth", e14);
                    this.f66347f[0].put("ImageLength", e15);
                }
            }
        }
    }

    public final void p(b bVar) throws IOException {
        if (f66335t) {
            Objects.toString(bVar);
        }
        bVar.mark(0);
        bVar.f66366c = ByteOrder.BIG_ENDIAN;
        byte[] bArr = E;
        bVar.skipBytes(bArr.length);
        int length = bArr.length + 0;
        while (true) {
            try {
                int readInt = bVar.readInt();
                int i14 = length + 4;
                byte[] bArr2 = new byte[4];
                if (bVar.read(bArr2) == 4) {
                    int i15 = i14 + 4;
                    if (i15 == 16) {
                        if (!Arrays.equals(bArr2, G)) {
                            throw new IOException("Encountered invalid PNG file--IHDR chunk should appearas the first chunk");
                        }
                    }
                    if (!Arrays.equals(bArr2, H)) {
                        if (Arrays.equals(bArr2, F)) {
                            byte[] bArr3 = new byte[readInt];
                            if (bVar.read(bArr3) == readInt) {
                                int readInt2 = bVar.readInt();
                                CRC32 crc32 = new CRC32();
                                crc32.update(bArr2);
                                crc32.update(bArr3);
                                if (((int) crc32.getValue()) == readInt2) {
                                    this.f66356o = i15;
                                    F(bArr3, 0);
                                    R();
                                    N(new b(bArr3));
                                    return;
                                }
                                throw new IOException("Encountered invalid CRC value for PNG-EXIF chunk.\n recorded CRC value: " + readInt2 + ", calculated CRC value: " + crc32.getValue());
                            }
                            throw new IOException("Failed to read given length for given PNG chunk type: " + b(bArr2));
                        }
                        int i16 = readInt + 4;
                        bVar.skipBytes(i16);
                        length = i15 + i16;
                    } else {
                        return;
                    }
                } else {
                    throw new IOException("Encountered invalid length while parsing PNG chunktype");
                }
            } catch (EOFException unused) {
                throw new IOException("Encountered corrupt PNG file.");
            }
        }
    }

    public final void q(b bVar) throws IOException {
        if (f66335t) {
            Objects.toString(bVar);
        }
        bVar.mark(0);
        bVar.skipBytes(84);
        byte[] bArr = new byte[4];
        byte[] bArr2 = new byte[4];
        byte[] bArr3 = new byte[4];
        bVar.read(bArr);
        bVar.read(bArr2);
        bVar.read(bArr3);
        int i14 = ByteBuffer.wrap(bArr).getInt();
        int i15 = ByteBuffer.wrap(bArr2).getInt();
        int i16 = ByteBuffer.wrap(bArr3).getInt();
        byte[] bArr4 = new byte[i15];
        bVar.b((long) i14);
        bVar.read(bArr4);
        m(new b(bArr4), i14, 5);
        bVar.b((long) i16);
        bVar.f66366c = ByteOrder.BIG_ENDIAN;
        int readInt = bVar.readInt();
        for (int i17 = 0; i17 < readInt; i17++) {
            int readUnsignedShort = bVar.readUnsignedShort();
            int readUnsignedShort2 = bVar.readUnsignedShort();
            if (readUnsignedShort == U.f66375a) {
                short readShort = bVar.readShort();
                short readShort2 = bVar.readShort();
                d e14 = d.e(readShort, this.f66349h);
                d e15 = d.e(readShort2, this.f66349h);
                this.f66347f[0].put("ImageLength", e14);
                this.f66347f[0].put("ImageWidth", e15);
                return;
            }
            bVar.skipBytes(readUnsignedShort2);
        }
    }

    public final void r(b bVar) throws IOException {
        d dVar;
        C(bVar, bVar.available());
        G(bVar, 0);
        Q(bVar, 0);
        Q(bVar, 5);
        Q(bVar, 4);
        R();
        if (this.f66345d == 8 && (dVar = this.f66347f[1].get("MakerNote")) != null) {
            b bVar2 = new b(dVar.f66374d);
            bVar2.f66366c = this.f66349h;
            bVar2.b(6);
            G(bVar2, 9);
            d dVar2 = this.f66347f[9].get("ColorSpace");
            if (dVar2 != null) {
                this.f66347f[1].put("ColorSpace", dVar2);
            }
        }
    }

    public int s() {
        switch (j("Orientation", 1)) {
            case 3:
            case 4:
                return 180;
            case 5:
            case 8:
                return CardScanner.CREDIT_CARD_TARGET_HEIGHT;
            case 6:
            case 7:
                return 90;
            default:
                return 0;
        }
    }

    public final void t(b bVar) throws IOException {
        if (f66335t) {
            Objects.toString(bVar);
        }
        r(bVar);
        d dVar = this.f66347f[0].get("JpgFromRaw");
        if (dVar != null) {
            m(new b(dVar.f66374d), (int) dVar.f66373c, 5);
        }
        d dVar2 = this.f66347f[0].get("ISO");
        d dVar3 = this.f66347f[1].get("PhotographicSensitivity");
        if (dVar2 != null && dVar3 == null) {
            this.f66347f[1].put("PhotographicSensitivity", dVar2);
        }
    }

    public final void u(b bVar) throws IOException {
        byte[] bArr = f66330e0;
        bVar.skipBytes(bArr.length);
        byte[] bArr2 = new byte[bVar.available()];
        bVar.readFully(bArr2);
        this.f66356o = bArr.length;
        F(bArr2, 0);
    }

    /* JADX WARNING: Removed duplicated region for block: B:31:0x005f  */
    /* JADX WARNING: Removed duplicated region for block: B:41:0x007c  */
    /* JADX WARNING: Removed duplicated region for block: B:54:0x0096 A[SYNTHETIC, Splitter:B:54:0x0096] */
    /* JADX WARNING: Removed duplicated region for block: B:63:0x00a1 A[SYNTHETIC, Splitter:B:63:0x00a1] */
    public byte[] v() {
        FileDescriptor fileDescriptor;
        InputStream inputStream;
        Throwable th4;
        Throwable th5;
        InputStream inputStream2 = null;
        if (!this.f66350i) {
            return null;
        }
        byte[] bArr = this.f66354m;
        if (bArr != null) {
            return bArr;
        }
        try {
            inputStream = this.f66344c;
            if (inputStream != null) {
                try {
                    if (inputStream.markSupported()) {
                        inputStream.reset();
                    } else {
                        c(inputStream);
                        return null;
                    }
                } catch (Exception unused) {
                    fileDescriptor = null;
                    c(inputStream);
                    if (fileDescriptor != null) {
                    }
                    return null;
                } catch (Throwable th6) {
                    inputStream2 = inputStream;
                    th4 = th6;
                    fileDescriptor = null;
                    c(inputStream2);
                    if (fileDescriptor != null) {
                    }
                    throw th4;
                }
            } else if (this.f66342a != null) {
                inputStream = new FileInputStream(this.f66342a);
            } else {
                FileDescriptor dup = Os.dup(this.f66343b);
                try {
                    Os.lseek(dup, 0, OsConstants.SEEK_SET);
                    fileDescriptor = dup;
                    inputStream = new FileInputStream(dup);
                    if (inputStream.skip((long) (this.f66352k + this.f66356o)) != ((long) (this.f66352k + this.f66356o))) {
                        byte[] bArr2 = new byte[this.f66353l];
                        if (inputStream.read(bArr2) == this.f66353l) {
                            this.f66354m = bArr2;
                            c(inputStream);
                            if (fileDescriptor != null) {
                                try {
                                    Os.close(fileDescriptor);
                                } catch (Exception unused2) {
                                }
                            }
                            return bArr2;
                        }
                        throw new IOException("Corrupted image");
                    }
                    throw new IOException("Corrupted image");
                } catch (Exception unused3) {
                    fileDescriptor = dup;
                    inputStream = null;
                    c(inputStream);
                    if (fileDescriptor != null) {
                    }
                    return null;
                } catch (Throwable th7) {
                    th5 = th7;
                    fileDescriptor = dup;
                    th4 = th5;
                    c(inputStream2);
                    if (fileDescriptor != null) {
                    }
                    throw th4;
                }
            }
            fileDescriptor = null;
            try {
                if (inputStream.skip((long) (this.f66352k + this.f66356o)) != ((long) (this.f66352k + this.f66356o))) {
                }
            } catch (Exception unused4) {
                c(inputStream);
                if (fileDescriptor != null) {
                }
                return null;
            } catch (Throwable th8) {
                th5 = th8;
                inputStream2 = inputStream;
                th4 = th5;
                c(inputStream2);
                if (fileDescriptor != null) {
                }
                throw th4;
            }
        } catch (Exception unused5) {
            inputStream = null;
            fileDescriptor = null;
            c(inputStream);
            if (fileDescriptor != null) {
                try {
                    Os.close(fileDescriptor);
                } catch (Exception unused6) {
                }
            }
            return null;
        } catch (Throwable th9) {
            th4 = th9;
            fileDescriptor = null;
            c(inputStream2);
            if (fileDescriptor != null) {
                try {
                    Os.close(fileDescriptor);
                } catch (Exception unused7) {
                }
            }
            throw th4;
        }
    }

    public final void w(b bVar) throws IOException {
        if (f66335t) {
            Objects.toString(bVar);
        }
        bVar.mark(0);
        bVar.f66366c = ByteOrder.LITTLE_ENDIAN;
        bVar.skipBytes(I.length);
        int readInt = bVar.readInt() + 8;
        int skipBytes = bVar.skipBytes(J.length) + 8;
        while (true) {
            try {
                byte[] bArr = new byte[4];
                if (bVar.read(bArr) == 4) {
                    int readInt2 = bVar.readInt();
                    int i14 = skipBytes + 4 + 4;
                    if (Arrays.equals(K, bArr)) {
                        byte[] bArr2 = new byte[readInt2];
                        if (bVar.read(bArr2) == readInt2) {
                            this.f66356o = i14;
                            F(bArr2, 0);
                            N(new b(bArr2));
                            return;
                        }
                        throw new IOException("Failed to read given length for given PNG chunk type: " + b(bArr));
                    }
                    if (readInt2 % 2 == 1) {
                        readInt2++;
                    }
                    int i15 = i14 + readInt2;
                    if (i15 != readInt) {
                        if (i15 <= readInt) {
                            int skipBytes2 = bVar.skipBytes(readInt2);
                            if (skipBytes2 == readInt2) {
                                skipBytes = i14 + skipBytes2;
                            } else {
                                throw new IOException("Encountered WebP file with invalid chunk size");
                            }
                        } else {
                            throw new IOException("Encountered WebP file with invalid chunk size");
                        }
                    } else {
                        return;
                    }
                } else {
                    throw new IOException("Encountered invalid length while parsing WebP chunktype");
                }
            } catch (EOFException unused) {
                throw new IOException("Encountered corrupt WebP file.");
            }
        }
    }

    public final void y(b bVar, HashMap hashMap) throws IOException {
        d dVar = (d) hashMap.get("JPEGInterchangeFormat");
        d dVar2 = (d) hashMap.get("JPEGInterchangeFormatLength");
        if (dVar != null && dVar2 != null) {
            int h14 = dVar.h(this.f66349h);
            int h15 = dVar2.h(this.f66349h);
            if (this.f66345d == 7) {
                h14 += this.f66357p;
            }
            int min = Math.min(h15, bVar.f66367d - h14);
            if (h14 > 0 && min > 0) {
                this.f66350i = true;
                if (this.f66342a == null && this.f66344c == null && this.f66343b == null) {
                    byte[] bArr = new byte[min];
                    bVar.skip((long) h14);
                    bVar.read(bArr);
                    this.f66354m = bArr;
                }
                this.f66352k = h14;
                this.f66353l = min;
            }
        }
    }

    public final void z(String str) throws IOException {
        Throwable th4;
        boolean z14;
        Objects.requireNonNull(str, "filename cannot be null");
        FileInputStream fileInputStream = null;
        this.f66344c = null;
        this.f66342a = str;
        try {
            FileInputStream fileInputStream2 = new FileInputStream(str);
            try {
                try {
                    Os.lseek(fileInputStream2.getFD(), 0, OsConstants.SEEK_CUR);
                    z14 = true;
                } catch (Exception unused) {
                    z14 = false;
                }
                if (z14) {
                    this.f66343b = fileInputStream2.getFD();
                } else {
                    this.f66343b = null;
                }
                B(fileInputStream2);
                c(fileInputStream2);
            } catch (Throwable th5) {
                th4 = th5;
                fileInputStream = fileInputStream2;
                c(fileInputStream);
                throw th4;
            }
        } catch (Throwable th6) {
            th4 = th6;
            c(fileInputStream);
            throw th4;
        }
    }

    public static class b extends InputStream implements DataInput {

        /* renamed from: f  reason: collision with root package name */
        public static final ByteOrder f66363f = ByteOrder.LITTLE_ENDIAN;

        /* renamed from: g  reason: collision with root package name */
        public static final ByteOrder f66364g = ByteOrder.BIG_ENDIAN;

        /* renamed from: b  reason: collision with root package name */
        public DataInputStream f66365b;

        /* renamed from: c  reason: collision with root package name */
        public ByteOrder f66366c;

        /* renamed from: d  reason: collision with root package name */
        public final int f66367d;

        /* renamed from: e  reason: collision with root package name */
        public int f66368e;

        public b(InputStream inputStream, ByteOrder byteOrder) throws IOException {
            this.f66366c = ByteOrder.BIG_ENDIAN;
            DataInputStream dataInputStream = new DataInputStream(inputStream);
            this.f66365b = dataInputStream;
            int available = dataInputStream.available();
            this.f66367d = available;
            this.f66368e = 0;
            this.f66365b.mark(available);
            this.f66366c = byteOrder;
        }

        public long a() throws IOException {
            return ((long) readInt()) & 4294967295L;
        }

        @Override // java.io.InputStream
        public int available() throws IOException {
            return this.f66365b.available();
        }

        public void b(long j14) throws IOException {
            int i14 = this.f66368e;
            if (((long) i14) > j14) {
                this.f66368e = 0;
                this.f66365b.reset();
                this.f66365b.mark(this.f66367d);
            } else {
                j14 -= (long) i14;
            }
            int i15 = (int) j14;
            if (skipBytes(i15) != i15) {
                throw new IOException("Couldn't seek up to the byteCount");
            }
        }

        public synchronized void mark(int i14) {
            this.f66365b.mark(i14);
        }

        @Override // java.io.InputStream
        public int read() throws IOException {
            this.f66368e++;
            return this.f66365b.read();
        }

        @Override // java.io.DataInput
        public boolean readBoolean() throws IOException {
            this.f66368e++;
            return this.f66365b.readBoolean();
        }

        @Override // java.io.DataInput
        public byte readByte() throws IOException {
            int i14 = this.f66368e + 1;
            this.f66368e = i14;
            if (i14 <= this.f66367d) {
                int read = this.f66365b.read();
                if (read >= 0) {
                    return (byte) read;
                }
                throw new EOFException();
            }
            throw new EOFException();
        }

        @Override // java.io.DataInput
        public char readChar() throws IOException {
            this.f66368e += 2;
            return this.f66365b.readChar();
        }

        @Override // java.io.DataInput
        public double readDouble() throws IOException {
            return Double.longBitsToDouble(readLong());
        }

        @Override // java.io.DataInput
        public float readFloat() throws IOException {
            return Float.intBitsToFloat(readInt());
        }

        @Override // java.io.DataInput
        public void readFully(byte[] bArr, int i14, int i15) throws IOException {
            int i16 = this.f66368e + i15;
            this.f66368e = i16;
            if (i16 > this.f66367d) {
                throw new EOFException();
            } else if (this.f66365b.read(bArr, i14, i15) != i15) {
                throw new IOException("Couldn't read up to the length of buffer");
            }
        }

        @Override // java.io.DataInput
        public int readInt() throws IOException {
            int i14 = this.f66368e + 4;
            this.f66368e = i14;
            if (i14 <= this.f66367d) {
                int read = this.f66365b.read();
                int read2 = this.f66365b.read();
                int read3 = this.f66365b.read();
                int read4 = this.f66365b.read();
                if ((read | read2 | read3 | read4) >= 0) {
                    ByteOrder byteOrder = this.f66366c;
                    if (byteOrder == f66363f) {
                        return (read4 << 24) + (read3 << 16) + (read2 << 8) + read;
                    }
                    if (byteOrder == f66364g) {
                        return (read << 24) + (read2 << 16) + (read3 << 8) + read4;
                    }
                    StringBuilder a14 = b.d.a("Invalid byte order: ");
                    a14.append(this.f66366c);
                    throw new IOException(a14.toString());
                }
                throw new EOFException();
            }
            throw new EOFException();
        }

        @Override // java.io.DataInput
        public String readLine() throws IOException {
            return null;
        }

        @Override // java.io.DataInput
        public long readLong() throws IOException {
            int i14 = this.f66368e + 8;
            this.f66368e = i14;
            if (i14 <= this.f66367d) {
                int read = this.f66365b.read();
                int read2 = this.f66365b.read();
                int read3 = this.f66365b.read();
                int read4 = this.f66365b.read();
                int read5 = this.f66365b.read();
                int read6 = this.f66365b.read();
                int read7 = this.f66365b.read();
                int read8 = this.f66365b.read();
                if ((read | read2 | read3 | read4 | read5 | read6 | read7 | read8) >= 0) {
                    ByteOrder byteOrder = this.f66366c;
                    if (byteOrder == f66363f) {
                        return (((long) read8) << 56) + (((long) read7) << 48) + (((long) read6) << 40) + (((long) read5) << 32) + (((long) read4) << 24) + (((long) read3) << 16) + (((long) read2) << 8) + ((long) read);
                    }
                    if (byteOrder == f66364g) {
                        return (((long) read) << 56) + (((long) read2) << 48) + (((long) read3) << 40) + (((long) read4) << 32) + (((long) read5) << 24) + (((long) read6) << 16) + (((long) read7) << 8) + ((long) read8);
                    }
                    StringBuilder a14 = b.d.a("Invalid byte order: ");
                    a14.append(this.f66366c);
                    throw new IOException(a14.toString());
                }
                throw new EOFException();
            }
            throw new EOFException();
        }

        @Override // java.io.DataInput
        public short readShort() throws IOException {
            int i14 = this.f66368e + 2;
            this.f66368e = i14;
            if (i14 <= this.f66367d) {
                int read = this.f66365b.read();
                int read2 = this.f66365b.read();
                if ((read | read2) >= 0) {
                    ByteOrder byteOrder = this.f66366c;
                    if (byteOrder == f66363f) {
                        return (short) ((read2 << 8) + read);
                    }
                    if (byteOrder == f66364g) {
                        return (short) ((read << 8) + read2);
                    }
                    StringBuilder a14 = b.d.a("Invalid byte order: ");
                    a14.append(this.f66366c);
                    throw new IOException(a14.toString());
                }
                throw new EOFException();
            }
            throw new EOFException();
        }

        @Override // java.io.DataInput
        public String readUTF() throws IOException {
            this.f66368e += 2;
            return this.f66365b.readUTF();
        }

        @Override // java.io.DataInput
        public int readUnsignedByte() throws IOException {
            this.f66368e++;
            return this.f66365b.readUnsignedByte();
        }

        @Override // java.io.DataInput
        public int readUnsignedShort() throws IOException {
            int i14 = this.f66368e + 2;
            this.f66368e = i14;
            if (i14 <= this.f66367d) {
                int read = this.f66365b.read();
                int read2 = this.f66365b.read();
                if ((read | read2) >= 0) {
                    ByteOrder byteOrder = this.f66366c;
                    if (byteOrder == f66363f) {
                        return (read2 << 8) + read;
                    }
                    if (byteOrder == f66364g) {
                        return (read << 8) + read2;
                    }
                    StringBuilder a14 = b.d.a("Invalid byte order: ");
                    a14.append(this.f66366c);
                    throw new IOException(a14.toString());
                }
                throw new EOFException();
            }
            throw new EOFException();
        }

        @Override // java.io.DataInput
        public int skipBytes(int i14) throws IOException {
            int min = Math.min(i14, this.f66367d - this.f66368e);
            int i15 = 0;
            while (i15 < min) {
                i15 += this.f66365b.skipBytes(min - i15);
            }
            this.f66368e += i15;
            return i15;
        }

        @Override // java.io.InputStream
        public int read(byte[] bArr, int i14, int i15) throws IOException {
            int read = this.f66365b.read(bArr, i14, i15);
            this.f66368e += read;
            return read;
        }

        @Override // java.io.DataInput
        public void readFully(byte[] bArr) throws IOException {
            int length = this.f66368e + bArr.length;
            this.f66368e = length;
            if (length > this.f66367d) {
                throw new EOFException();
            } else if (this.f66365b.read(bArr, 0, bArr.length) != bArr.length) {
                throw new IOException("Couldn't read up to the length of buffer");
            }
        }

        public b(byte[] bArr) throws IOException {
            this(new ByteArrayInputStream(bArr), ByteOrder.BIG_ENDIAN);
        }
    }

    public static class d {

        /* renamed from: a  reason: collision with root package name */
        public final int f66371a;

        /* renamed from: b  reason: collision with root package name */
        public final int f66372b;

        /* renamed from: c  reason: collision with root package name */
        public final long f66373c;

        /* renamed from: d  reason: collision with root package name */
        public final byte[] f66374d;

        public d(int i14, int i15, long j14, byte[] bArr) {
            this.f66371a = i14;
            this.f66372b = i15;
            this.f66373c = j14;
            this.f66374d = bArr;
        }

        public static d a(String str) {
            byte[] bytes = b.a(str, 0).getBytes(a.f66329d0);
            return new d(2, bytes.length, bytes);
        }

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

        public static d c(long[] jArr, ByteOrder byteOrder) {
            ByteBuffer wrap = ByteBuffer.wrap(new byte[(a.S[4] * jArr.length)]);
            wrap.order(byteOrder);
            for (long j14 : jArr) {
                wrap.putInt((int) j14);
            }
            return new d(4, jArr.length, wrap.array());
        }

        public static d d(f[] fVarArr, ByteOrder byteOrder) {
            ByteBuffer wrap = ByteBuffer.wrap(new byte[(a.S[5] * fVarArr.length)]);
            wrap.order(byteOrder);
            for (f fVar : fVarArr) {
                wrap.putInt((int) fVar.f66379a);
                wrap.putInt((int) fVar.f66380b);
            }
            return new d(5, fVarArr.length, wrap.array());
        }

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

        public static d f(int[] iArr, ByteOrder byteOrder) {
            ByteBuffer wrap = ByteBuffer.wrap(new byte[(a.S[3] * iArr.length)]);
            wrap.order(byteOrder);
            for (int i14 : iArr) {
                wrap.putShort((short) i14);
            }
            return new d(3, iArr.length, wrap.array());
        }

        public double g(ByteOrder byteOrder) {
            Object j14 = j(byteOrder);
            if (j14 == null) {
                throw new NumberFormatException("NULL can't be converted to a double value");
            } else if (j14 instanceof String) {
                return Double.parseDouble((String) j14);
            } else {
                if (j14 instanceof long[]) {
                    long[] jArr = (long[]) j14;
                    if (jArr.length == 1) {
                        return (double) jArr[0];
                    }
                    throw new NumberFormatException("There are more than one component");
                } else if (j14 instanceof int[]) {
                    int[] iArr = (int[]) j14;
                    if (iArr.length == 1) {
                        return (double) iArr[0];
                    }
                    throw new NumberFormatException("There are more than one component");
                } else if (j14 instanceof double[]) {
                    double[] dArr = (double[]) j14;
                    if (dArr.length == 1) {
                        return dArr[0];
                    }
                    throw new NumberFormatException("There are more than one component");
                } else if (j14 instanceof f[]) {
                    f[] fVarArr = (f[]) j14;
                    if (fVarArr.length == 1) {
                        f fVar = fVarArr[0];
                        return ((double) fVar.f66379a) / ((double) fVar.f66380b);
                    }
                    throw new NumberFormatException("There are more than one component");
                } else {
                    throw new NumberFormatException("Couldn't find a double value");
                }
            }
        }

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

        public String i(ByteOrder byteOrder) {
            Object j14 = j(byteOrder);
            if (j14 == null) {
                return null;
            }
            if (j14 instanceof String) {
                return (String) j14;
            }
            StringBuilder sb4 = new StringBuilder();
            int i14 = 0;
            if (j14 instanceof long[]) {
                long[] jArr = (long[]) j14;
                while (i14 < jArr.length) {
                    sb4.append(jArr[i14]);
                    i14++;
                    if (i14 != jArr.length) {
                        sb4.append(",");
                    }
                }
                return sb4.toString();
            } else if (j14 instanceof int[]) {
                int[] iArr = (int[]) j14;
                while (i14 < iArr.length) {
                    sb4.append(iArr[i14]);
                    i14++;
                    if (i14 != iArr.length) {
                        sb4.append(",");
                    }
                }
                return sb4.toString();
            } else if (j14 instanceof double[]) {
                double[] dArr = (double[]) j14;
                while (i14 < dArr.length) {
                    sb4.append(dArr[i14]);
                    i14++;
                    if (i14 != dArr.length) {
                        sb4.append(",");
                    }
                }
                return sb4.toString();
            } else if (!(j14 instanceof f[])) {
                return null;
            } else {
                f[] fVarArr = (f[]) j14;
                while (i14 < fVarArr.length) {
                    sb4.append(fVarArr[i14].f66379a);
                    sb4.append('/');
                    sb4.append(fVarArr[i14].f66380b);
                    i14++;
                    if (i14 != fVarArr.length) {
                        sb4.append(",");
                    }
                }
                return sb4.toString();
            }
        }

        /* JADX WARNING: Removed duplicated region for block: B:122:0x014a A[SYNTHETIC, Splitter:B:122:0x014a] */
        /* JADX WARNING: Removed duplicated region for block: B:130:0x0151 A[SYNTHETIC, Splitter:B:130:0x0151] */
        public Object j(ByteOrder byteOrder) {
            b bVar;
            Throwable th4;
            byte b14;
            byte[] bArr;
            b bVar2 = null;
            try {
                bVar = new b(this.f66374d);
                try {
                    bVar.f66366c = byteOrder;
                    boolean z14 = true;
                    int i14 = 0;
                    switch (this.f66371a) {
                        case 1:
                        case 6:
                            byte[] bArr2 = this.f66374d;
                            if (bArr2.length != 1 || bArr2[0] < 0 || bArr2[0] > 1) {
                                String str = new String(bArr2, a.f66329d0);
                                try {
                                    bVar.close();
                                } catch (IOException unused) {
                                }
                                return str;
                            }
                            String str2 = new String(new char[]{(char) (bArr2[0] + 48)});
                            try {
                                bVar.close();
                            } catch (IOException unused2) {
                            }
                            return str2;
                        case 2:
                        case 7:
                            if (this.f66372b >= a.T.length) {
                                int i15 = 0;
                                while (true) {
                                    bArr = a.T;
                                    if (i15 < bArr.length) {
                                        if (this.f66374d[i15] != bArr[i15]) {
                                            z14 = false;
                                        } else {
                                            i15++;
                                        }
                                    }
                                }
                                if (z14) {
                                    i14 = bArr.length;
                                }
                            }
                            StringBuilder sb4 = new StringBuilder();
                            while (i14 < this.f66372b && (b14 = this.f66374d[i14]) != 0) {
                                if (b14 >= 32) {
                                    sb4.append((char) b14);
                                } else {
                                    sb4.append('?');
                                }
                                i14++;
                            }
                            String sb5 = sb4.toString();
                            try {
                                bVar.close();
                            } catch (IOException unused3) {
                            }
                            return sb5;
                        case 3:
                            int[] iArr = new int[this.f66372b];
                            while (i14 < this.f66372b) {
                                iArr[i14] = bVar.readUnsignedShort();
                                i14++;
                            }
                            try {
                                bVar.close();
                            } catch (IOException unused4) {
                            }
                            return iArr;
                        case 4:
                            long[] jArr = new long[this.f66372b];
                            while (i14 < this.f66372b) {
                                jArr[i14] = bVar.a();
                                i14++;
                            }
                            try {
                                bVar.close();
                            } catch (IOException unused5) {
                            }
                            return jArr;
                        case 5:
                            f[] fVarArr = new f[this.f66372b];
                            while (i14 < this.f66372b) {
                                fVarArr[i14] = new f(bVar.a(), bVar.a());
                                i14++;
                            }
                            try {
                                bVar.close();
                            } catch (IOException unused6) {
                            }
                            return fVarArr;
                        case 8:
                            int[] iArr2 = new int[this.f66372b];
                            while (i14 < this.f66372b) {
                                iArr2[i14] = bVar.readShort();
                                i14++;
                            }
                            try {
                                bVar.close();
                            } catch (IOException unused7) {
                            }
                            return iArr2;
                        case 9:
                            int[] iArr3 = new int[this.f66372b];
                            while (i14 < this.f66372b) {
                                iArr3[i14] = bVar.readInt();
                                i14++;
                            }
                            try {
                                bVar.close();
                            } catch (IOException unused8) {
                            }
                            return iArr3;
                        case 10:
                            f[] fVarArr2 = new f[this.f66372b];
                            while (i14 < this.f66372b) {
                                fVarArr2[i14] = new f((long) bVar.readInt(), (long) bVar.readInt());
                                i14++;
                            }
                            try {
                                bVar.close();
                            } catch (IOException unused9) {
                            }
                            return fVarArr2;
                        case 11:
                            double[] dArr = new double[this.f66372b];
                            while (i14 < this.f66372b) {
                                dArr[i14] = (double) bVar.readFloat();
                                i14++;
                            }
                            try {
                                bVar.close();
                            } catch (IOException unused10) {
                            }
                            return dArr;
                        case 12:
                            double[] dArr2 = new double[this.f66372b];
                            while (i14 < this.f66372b) {
                                dArr2[i14] = bVar.readDouble();
                                i14++;
                            }
                            try {
                                bVar.close();
                            } catch (IOException unused11) {
                            }
                            return dArr2;
                        default:
                            try {
                                bVar.close();
                            } catch (IOException unused12) {
                            }
                            return null;
                    }
                } catch (IOException unused13) {
                    if (bVar != null) {
                    }
                    return null;
                } catch (Throwable th5) {
                    th4 = th5;
                    bVar2 = bVar;
                    if (bVar2 != null) {
                    }
                    throw th4;
                }
            } catch (IOException unused14) {
                bVar = null;
                if (bVar != null) {
                    try {
                        bVar.close();
                    } catch (IOException unused15) {
                    }
                }
                return null;
            } catch (Throwable th6) {
                th4 = th6;
                if (bVar2 != null) {
                    try {
                        bVar2.close();
                    } catch (IOException unused16) {
                    }
                }
                throw th4;
            }
        }

        public String toString() {
            StringBuilder a14 = b.d.a("(");
            a14.append(a.R[this.f66371a]);
            a14.append(", data length:");
            return ie0.d.a(a14, this.f66374d.length, ")");
        }

        public d(int i14, int i15, byte[] bArr) {
            this.f66371a = i14;
            this.f66372b = i15;
            this.f66373c = -1;
            this.f66374d = bArr;
        }
    }

    public static class e {

        /* renamed from: a  reason: collision with root package name */
        public final int f66375a;

        /* renamed from: b  reason: collision with root package name */
        public final String f66376b;

        /* renamed from: c  reason: collision with root package name */
        public final int f66377c;

        /* renamed from: d  reason: collision with root package name */
        public final int f66378d;

        public e(String str, int i14, int i15) {
            this.f66376b = str;
            this.f66375a = i14;
            this.f66377c = i15;
            this.f66378d = -1;
        }

        public e(String str, int i14, int i15, int i16) {
            this.f66376b = str;
            this.f66375a = i14;
            this.f66377c = i15;
            this.f66378d = i16;
        }
    }

    public a(String str) throws IOException {
        e[][] eVarArr = V;
        this.f66347f = new HashMap[eVarArr.length];
        this.f66348g = new HashSet(eVarArr.length);
        Objects.requireNonNull(str, "filename cannot be null");
        z(str);
    }

    public a(InputStream inputStream) throws IOException {
        e[][] eVarArr = V;
        this.f66347f = new HashMap[eVarArr.length];
        this.f66348g = new HashSet(eVarArr.length);
        Objects.requireNonNull(inputStream, "inputStream cannot be null");
        this.f66342a = null;
        boolean z14 = false;
        if (inputStream instanceof AssetManager.AssetInputStream) {
            this.f66344c = (AssetManager.AssetInputStream) inputStream;
            this.f66343b = null;
        } else {
            if (inputStream instanceof FileInputStream) {
                FileInputStream fileInputStream = (FileInputStream) inputStream;
                try {
                    Os.lseek(fileInputStream.getFD(), 0, OsConstants.SEEK_CUR);
                    z14 = true;
                } catch (Exception unused) {
                }
                if (z14) {
                    this.f66344c = null;
                    this.f66343b = fileInputStream.getFD();
                }
            }
            this.f66344c = null;
            this.f66343b = null;
        }
        B(inputStream);
    }
}