钱能钱包 v3.10.2版本的 MD5 值为:339a4b585ef2aa3bfaf7e4baeb254647

以下内容为反编译后的 a.java 源代码,内容仅作参考


package b.o.a;

import android.content.res.AssetManager;
import android.location.Location;
import android.media.MediaDataSource;
import android.media.MediaMetadataRetriever;
import android.os.Build;
import android.system.OsConstants;
import android.util.Log;
import android.util.Pair;
import androidx.recyclerview.widget.RecyclerView;
import b.o.a.b;
import cn.jpush.android.service.WakedResultReceiver;
import com.alibaba.fastjson.parser.JSONLexer;
import com.luck.picture.lib.camera.CustomCameraType;
import com.luck.picture.lib.widget.longimage.SubsamplingScaleImageView;
import com.netease.cloud.nos.yidun.constants.Code;
import j$.util.DesugarTimeZone;
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.FileNotFoundException;
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.Date;
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.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.CRC32;
import okhttp3.internal.ws.WebSocketProtocol;
public class a {
    public static SimpleDateFormat A;
    public static final e[] E;
    public static final e[] F;
    public static final e[] G;
    public static final e[] H;
    public static final e[] I;
    public static final e J;
    public static final e[] K;
    public static final e[] L;
    public static final e[] M;
    public static final e[] N;
    public static final e[][] O;
    public static final e[] P;
    public static final HashMap<Integer, e>[] Q;
    public static final HashMap<String, e>[] R;
    public static final HashSet<String> S;
    public static final HashMap<Integer, Integer> T;
    public static final Charset U;
    public static final byte[] V;
    public static final byte[] W;
    public static final Pattern X;
    public static final Pattern Y;
    public static final Pattern Z;
    public static final Pattern a0;
    public static SimpleDateFormat z;
    public String b0;
    public FileDescriptor c0;
    public AssetManager.AssetInputStream d0;
    public int e0;
    public boolean f0;
    public final HashMap<String, d>[] g0;
    public Set<Integer> h0;
    public ByteOrder i0;
    public boolean j0;
    public boolean k0;
    public boolean l0;
    public int m0;
    public int n0;
    public byte[] o0;
    public int p0;
    public int q0;
    public int r0;
    public int s0;
    public int t0;
    public boolean u0;
    public boolean v0;
    public static final boolean a = Log.isLoggable("ExifInterface", 3);
    public static final List<Integer> f3177b = Arrays.asList(1, 6, 3, 8);
    public static final List<Integer> f3178c = Arrays.asList(2, 7, 4, 5);
    public static final int[] f3179d = {8, 8, 8};
    public static final int[] f3180e = {4};
    public static final int[] f3181f = {8};
    public static final byte[] f3182g = {-1, -40, -1};
    public static final byte[] f3183h = {102, 116, 121, 112};
    public static final byte[] f3184i = {109, 105, 102, 49};
    public static final byte[] f3185j = {104, 101, 105, 99};
    public static final byte[] f3186k = {79, 76, 89, 77, 80, 0};
    public static final byte[] f3187l = {79, 76, 89, 77, 80, 85, 83, 0, 73, 73};
    public static final byte[] m = {-119, 80, 78, 71, 13, 10, JSONLexer.EOI, 10};
    public static final byte[] n = {101, 88, 73, 102};
    public static final byte[] o = {73, 72, 68, 82};
    public static final byte[] p = {73, 69, 78, 68};
    public static final byte[] q = {82, 73, 70, 70};
    public static final byte[] r = {87, 69, 66, 80};
    public static final byte[] s = {69, 88, 73, 70};
    public static final byte[] t = {-99, 1, 42};
    public static final byte[] u = "VP8X".getBytes(Charset.defaultCharset());
    public static final byte[] v = "VP8L".getBytes(Charset.defaultCharset());
    public static final byte[] w = "VP8 ".getBytes(Charset.defaultCharset());
    public static final byte[] x = "ANIM".getBytes(Charset.defaultCharset());
    public static final byte[] y = "ANMF".getBytes(Charset.defaultCharset());
    public static final String[] B = {"", "BYTE", "STRING", "USHORT", "ULONG", "URATIONAL", "SBYTE", "UNDEFINED", "SSHORT", "SLONG", "SRATIONAL", "SINGLE", "DOUBLE", "IFD"};
    public static final int[] C = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 1};
    public static final byte[] D = {65, 83, 67, 73, 73, 0, 0, 0};

    public class C0068a extends MediaDataSource {
        public long a;
        public final g f3188b;

        public C0068a(g gVar) {
            this.f3188b = gVar;
        }

        @Override
        public void close() {
        }

        @Override
        public long getSize() {
            return -1L;
        }

        @Override
        public int readAt(long j2, byte[] bArr, int i2, int i3) {
            if (i3 == 0) {
                return 0;
            }
            if (j2 < 0) {
                return -1;
            }
            try {
                long j3 = this.a;
                if (j3 != j2) {
                    if (j3 >= 0 && j2 >= j3 + this.f3188b.available()) {
                        return -1;
                    }
                    this.f3188b.z(j2);
                    this.a = j2;
                }
                if (i3 > this.f3188b.available()) {
                    i3 = this.f3188b.available();
                }
                int read = this.f3188b.read(bArr, i2, i3);
                if (read >= 0) {
                    this.a += read;
                    return read;
                }
            } catch (IOException unused) {
            }
            this.a = -1L;
            return -1;
        }
    }

    public static class b extends InputStream implements DataInput {
        public static final ByteOrder a = ByteOrder.LITTLE_ENDIAN;
        public static final ByteOrder f3190b = ByteOrder.BIG_ENDIAN;
        public final DataInputStream f3191c;
        public ByteOrder f3192d;
        public int f3193i;
        public byte[] f3194j;

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

        @Override
        public int available() {
            return this.f3191c.available();
        }

        public int b() {
            return this.f3193i;
        }

        public long j() {
            return readInt() & 4294967295L;
        }

        @Override
        public void mark(int i2) {
            throw new UnsupportedOperationException("Mark is currently unsupported");
        }

        public void p(ByteOrder byteOrder) {
            this.f3192d = byteOrder;
        }

        @Override
        public int read() {
            this.f3193i++;
            return this.f3191c.read();
        }

        @Override
        public boolean readBoolean() {
            this.f3193i++;
            return this.f3191c.readBoolean();
        }

        @Override
        public byte readByte() {
            this.f3193i++;
            int read = this.f3191c.read();
            if (read >= 0) {
                return (byte) read;
            }
            throw new EOFException();
        }

        @Override
        public char readChar() {
            this.f3193i += 2;
            return this.f3191c.readChar();
        }

        @Override
        public double readDouble() {
            return Double.longBitsToDouble(readLong());
        }

        @Override
        public float readFloat() {
            return Float.intBitsToFloat(readInt());
        }

        @Override
        public void readFully(byte[] bArr, int i2, int i3) {
            this.f3193i += i3;
            this.f3191c.readFully(bArr, i2, i3);
        }

        @Override
        public int readInt() {
            this.f3193i += 4;
            int read = this.f3191c.read();
            int read2 = this.f3191c.read();
            int read3 = this.f3191c.read();
            int read4 = this.f3191c.read();
            if ((read | read2 | read3 | read4) >= 0) {
                ByteOrder byteOrder = this.f3192d;
                if (byteOrder == a) {
                    return (read4 << 24) + (read3 << 16) + (read2 << 8) + read;
                }
                if (byteOrder == f3190b) {
                    return (read << 24) + (read2 << 16) + (read3 << 8) + read4;
                }
                throw new IOException("Invalid byte order: " + this.f3192d);
            }
            throw new EOFException();
        }

        @Override
        public String readLine() {
            Log.d("ExifInterface", "Currently unsupported");
            return null;
        }

        @Override
        public long readLong() {
            this.f3193i += 8;
            int read = this.f3191c.read();
            int read2 = this.f3191c.read();
            int read3 = this.f3191c.read();
            int read4 = this.f3191c.read();
            int read5 = this.f3191c.read();
            int read6 = this.f3191c.read();
            int read7 = this.f3191c.read();
            int read8 = this.f3191c.read();
            if ((read | read2 | read3 | read4 | read5 | read6 | read7 | read8) >= 0) {
                ByteOrder byteOrder = this.f3192d;
                if (byteOrder == a) {
                    return (read8 << 56) + (read7 << 48) + (read6 << 40) + (read5 << 32) + (read4 << 24) + (read3 << 16) + (read2 << 8) + read;
                }
                if (byteOrder == f3190b) {
                    return (read << 56) + (read2 << 48) + (read3 << 40) + (read4 << 32) + (read5 << 24) + (read6 << 16) + (read7 << 8) + read8;
                }
                throw new IOException("Invalid byte order: " + this.f3192d);
            }
            throw new EOFException();
        }

        @Override
        public short readShort() {
            this.f3193i += 2;
            int read = this.f3191c.read();
            int read2 = this.f3191c.read();
            if ((read | read2) >= 0) {
                ByteOrder byteOrder = this.f3192d;
                if (byteOrder == a) {
                    return (short) ((read2 << 8) + read);
                }
                if (byteOrder == f3190b) {
                    return (short) ((read << 8) + read2);
                }
                throw new IOException("Invalid byte order: " + this.f3192d);
            }
            throw new EOFException();
        }

        @Override
        public String readUTF() {
            this.f3193i += 2;
            return this.f3191c.readUTF();
        }

        @Override
        public int readUnsignedByte() {
            this.f3193i++;
            return this.f3191c.readUnsignedByte();
        }

        @Override
        public int readUnsignedShort() {
            this.f3193i += 2;
            int read = this.f3191c.read();
            int read2 = this.f3191c.read();
            if ((read | read2) >= 0) {
                ByteOrder byteOrder = this.f3192d;
                if (byteOrder == a) {
                    return (read2 << 8) + read;
                }
                if (byteOrder == f3190b) {
                    return (read << 8) + read2;
                }
                throw new IOException("Invalid byte order: " + this.f3192d);
            }
            throw new EOFException();
        }

        @Override
        public void reset() {
            throw new UnsupportedOperationException("Reset is currently unsupported");
        }

        @Override
        public int skipBytes(int i2) {
            throw new UnsupportedOperationException("skipBytes is currently unsupported");
        }

        public void v(int i2) {
            int i3 = 0;
            while (i3 < i2) {
                int i4 = i2 - i3;
                int skip = (int) this.f3191c.skip(i4);
                if (skip <= 0) {
                    if (this.f3194j == null) {
                        this.f3194j = new byte[RecyclerView.c0.FLAG_BOUNCED_FROM_HIDDEN_LIST];
                    }
                    skip = this.f3191c.read(this.f3194j, 0, Math.min((int) RecyclerView.c0.FLAG_BOUNCED_FROM_HIDDEN_LIST, i4));
                    if (skip == -1) {
                        throw new EOFException("Reached EOF while skipping " + i2 + " bytes.");
                    }
                }
                i3 += skip;
            }
            this.f3193i += i3;
        }

        public b(InputStream inputStream) {
            this(inputStream, ByteOrder.BIG_ENDIAN);
        }

        public b(InputStream inputStream, ByteOrder byteOrder) {
            this.f3192d = ByteOrder.BIG_ENDIAN;
            DataInputStream dataInputStream = new DataInputStream(inputStream);
            this.f3191c = dataInputStream;
            dataInputStream.mark(0);
            this.f3193i = 0;
            this.f3192d = byteOrder;
        }

        @Override
        public int read(byte[] bArr, int i2, int i3) {
            int read = this.f3191c.read(bArr, i2, i3);
            this.f3193i += read;
            return read;
        }

        @Override
        public void readFully(byte[] bArr) {
            this.f3193i += bArr.length;
            this.f3191c.readFully(bArr);
        }
    }

    public static class c extends FilterOutputStream {
        public final OutputStream a;
        public ByteOrder f3195b;

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

        public void A(int i2) {
            v((short) i2);
        }

        public void b(ByteOrder byteOrder) {
            this.f3195b = byteOrder;
        }

        public void j(int i2) {
            this.a.write(i2);
        }

        public void p(int i2) {
            ByteOrder byteOrder = this.f3195b;
            if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
                this.a.write((i2 >>> 0) & 255);
                this.a.write((i2 >>> 8) & 255);
                this.a.write((i2 >>> 16) & 255);
                this.a.write((i2 >>> 24) & 255);
            } else if (byteOrder == ByteOrder.BIG_ENDIAN) {
                this.a.write((i2 >>> 24) & 255);
                this.a.write((i2 >>> 16) & 255);
                this.a.write((i2 >>> 8) & 255);
                this.a.write((i2 >>> 0) & 255);
            }
        }

        public void v(short s) {
            ByteOrder byteOrder = this.f3195b;
            if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
                this.a.write((s >>> 0) & 255);
                this.a.write((s >>> 8) & 255);
            } else if (byteOrder == ByteOrder.BIG_ENDIAN) {
                this.a.write((s >>> 8) & 255);
                this.a.write((s >>> 0) & 255);
            }
        }

        @Override
        public void write(byte[] bArr) {
            this.a.write(bArr);
        }

        public void z(long j2) {
            p((int) j2);
        }

        @Override
        public void write(byte[] bArr, int i2, int i3) {
            this.a.write(bArr, i2, i3);
        }
    }

    public static class d {
        public final int a;
        public final int f3196b;
        public final long f3197c;
        public final byte[] f3198d;

        public d(int i2, int i3, byte[] bArr) {
            this(i2, i3, -1L, bArr);
        }

        public static d a(String str) {
            if (str.length() == 1 && str.charAt(0) >= '0' && str.charAt(0) <= '1') {
                return new d(1, 1, new byte[]{(byte) (str.charAt(0) - '0')});
            }
            byte[] bytes = str.getBytes(a.U);
            return new d(1, bytes.length, bytes);
        }

        public static d b(double[] dArr, ByteOrder byteOrder) {
            ByteBuffer wrap = ByteBuffer.wrap(new byte[a.C[12] * dArr.length]);
            wrap.order(byteOrder);
            for (double d2 : dArr) {
                wrap.putDouble(d2);
            }
            return new d(12, dArr.length, wrap.array());
        }

        public static d c(int[] iArr, ByteOrder byteOrder) {
            ByteBuffer wrap = ByteBuffer.wrap(new byte[a.C[9] * iArr.length]);
            wrap.order(byteOrder);
            for (int i2 : iArr) {
                wrap.putInt(i2);
            }
            return new d(9, iArr.length, wrap.array());
        }

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

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

        public static d f(long j2, ByteOrder byteOrder) {
            return g(new long[]{j2}, byteOrder);
        }

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

        public static d h(f fVar, ByteOrder byteOrder) {
            return i(new f[]{fVar}, byteOrder);
        }

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

        public static d j(int i2, ByteOrder byteOrder) {
            return k(new int[]{i2}, byteOrder);
        }

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

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

        public int m(ByteOrder byteOrder) {
            Object o = o(byteOrder);
            if (o != null) {
                if (o instanceof String) {
                    return Integer.parseInt((String) o);
                }
                if (o instanceof long[]) {
                    long[] jArr = (long[]) o;
                    if (jArr.length == 1) {
                        return (int) jArr[0];
                    }
                    throw new NumberFormatException("There are more than one component");
                } else if (o instanceof int[]) {
                    int[] iArr = (int[]) o;
                    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");
                }
            }
            throw new NumberFormatException("NULL can't be converted to a integer value");
        }

        public String n(ByteOrder byteOrder) {
            Object o = o(byteOrder);
            if (o == null) {
                return null;
            }
            if (o instanceof String) {
                return (String) o;
            }
            StringBuilder sb = new StringBuilder();
            int i2 = 0;
            if (o instanceof long[]) {
                long[] jArr = (long[]) o;
                while (i2 < jArr.length) {
                    sb.append(jArr[i2]);
                    i2++;
                    if (i2 != jArr.length) {
                        sb.append(",");
                    }
                }
                return sb.toString();
            } else if (o instanceof int[]) {
                int[] iArr = (int[]) o;
                while (i2 < iArr.length) {
                    sb.append(iArr[i2]);
                    i2++;
                    if (i2 != iArr.length) {
                        sb.append(",");
                    }
                }
                return sb.toString();
            } else if (o instanceof double[]) {
                double[] dArr = (double[]) o;
                while (i2 < dArr.length) {
                    sb.append(dArr[i2]);
                    i2++;
                    if (i2 != dArr.length) {
                        sb.append(",");
                    }
                }
                return sb.toString();
            } else if (o instanceof f[]) {
                f[] fVarArr = (f[]) o;
                while (i2 < fVarArr.length) {
                    sb.append(fVarArr[i2].a);
                    sb.append('/');
                    sb.append(fVarArr[i2].f3202b);
                    i2++;
                    if (i2 != fVarArr.length) {
                        sb.append(",");
                    }
                }
                return sb.toString();
            } else {
                return null;
            }
        }

        public Object o(ByteOrder byteOrder) {
            b bVar;
            InputStream inputStream;
            byte b2;
            byte[] bArr;
            InputStream inputStream2 = null;
            try {
                try {
                    bVar = new b(this.f3198d);
                    try {
                        bVar.p(byteOrder);
                        boolean z = true;
                        int i2 = 0;
                        switch (this.a) {
                            case 1:
                            case 6:
                                byte[] bArr2 = this.f3198d;
                                if (bArr2.length == 1 && bArr2[0] >= 0 && bArr2[0] <= 1) {
                                    String str = new String(new char[]{(char) (this.f3198d[0] + 48)});
                                    try {
                                        bVar.close();
                                    } catch (IOException e2) {
                                        Log.e("ExifInterface", "IOException occurred while closing InputStream", e2);
                                    }
                                    return str;
                                }
                                String str2 = new String(this.f3198d, a.U);
                                try {
                                    bVar.close();
                                } catch (IOException e3) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e3);
                                }
                                return str2;
                            case 2:
                            case 7:
                                if (this.f3196b >= a.D.length) {
                                    int i3 = 0;
                                    while (true) {
                                        bArr = a.D;
                                        if (i3 < bArr.length) {
                                            if (this.f3198d[i3] != bArr[i3]) {
                                                z = false;
                                            } else {
                                                i3++;
                                            }
                                        }
                                    }
                                    if (z) {
                                        i2 = bArr.length;
                                    }
                                }
                                StringBuilder sb = new StringBuilder();
                                while (i2 < this.f3196b && (b2 = this.f3198d[i2]) != 0) {
                                    if (b2 >= 32) {
                                        sb.append((char) b2);
                                    } else {
                                        sb.append('?');
                                    }
                                    i2++;
                                }
                                String sb2 = sb.toString();
                                try {
                                    bVar.close();
                                } catch (IOException e4) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e4);
                                }
                                return sb2;
                            case 3:
                                int[] iArr = new int[this.f3196b];
                                while (i2 < this.f3196b) {
                                    iArr[i2] = bVar.readUnsignedShort();
                                    i2++;
                                }
                                try {
                                    bVar.close();
                                } catch (IOException e5) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e5);
                                }
                                return iArr;
                            case 4:
                                long[] jArr = new long[this.f3196b];
                                while (i2 < this.f3196b) {
                                    jArr[i2] = bVar.j();
                                    i2++;
                                }
                                try {
                                    bVar.close();
                                } catch (IOException e6) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e6);
                                }
                                return jArr;
                            case 5:
                                f[] fVarArr = new f[this.f3196b];
                                while (i2 < this.f3196b) {
                                    fVarArr[i2] = new f(bVar.j(), bVar.j());
                                    i2++;
                                }
                                try {
                                    bVar.close();
                                } catch (IOException e7) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e7);
                                }
                                return fVarArr;
                            case 8:
                                int[] iArr2 = new int[this.f3196b];
                                while (i2 < this.f3196b) {
                                    iArr2[i2] = bVar.readShort();
                                    i2++;
                                }
                                try {
                                    bVar.close();
                                } catch (IOException e8) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e8);
                                }
                                return iArr2;
                            case 9:
                                int[] iArr3 = new int[this.f3196b];
                                while (i2 < this.f3196b) {
                                    iArr3[i2] = bVar.readInt();
                                    i2++;
                                }
                                try {
                                    bVar.close();
                                } catch (IOException e9) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e9);
                                }
                                return iArr3;
                            case 10:
                                f[] fVarArr2 = new f[this.f3196b];
                                while (i2 < this.f3196b) {
                                    fVarArr2[i2] = new f(bVar.readInt(), bVar.readInt());
                                    i2++;
                                }
                                try {
                                    bVar.close();
                                } catch (IOException e10) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e10);
                                }
                                return fVarArr2;
                            case 11:
                                double[] dArr = new double[this.f3196b];
                                while (i2 < this.f3196b) {
                                    dArr[i2] = bVar.readFloat();
                                    i2++;
                                }
                                try {
                                    bVar.close();
                                } catch (IOException e11) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e11);
                                }
                                return dArr;
                            case 12:
                                double[] dArr2 = new double[this.f3196b];
                                while (i2 < this.f3196b) {
                                    dArr2[i2] = bVar.readDouble();
                                    i2++;
                                }
                                try {
                                    bVar.close();
                                } catch (IOException e12) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e12);
                                }
                                return dArr2;
                            default:
                                try {
                                    bVar.close();
                                } catch (IOException e13) {
                                    Log.e("ExifInterface", "IOException occurred while closing InputStream", e13);
                                }
                                return null;
                        }
                    } catch (IOException e14) {
                        e = e14;
                        Log.w("ExifInterface", "IOException occurred during reading a value", e);
                        if (bVar != null) {
                            try {
                                bVar.close();
                            } catch (IOException e15) {
                                Log.e("ExifInterface", "IOException occurred while closing InputStream", e15);
                            }
                        }
                        return null;
                    }
                } catch (Throwable th) {
                    th = th;
                    inputStream2 = inputStream;
                    if (inputStream2 != null) {
                        try {
                            inputStream2.close();
                        } catch (IOException e16) {
                            Log.e("ExifInterface", "IOException occurred while closing InputStream", e16);
                        }
                    }
                    throw th;
                }
            } catch (IOException e17) {
                e = e17;
                bVar = null;
            } catch (Throwable th2) {
                th = th2;
                if (inputStream2 != null) {
                }
                throw th;
            }
        }

        public int p() {
            return a.C[this.a] * this.f3196b;
        }

        public String toString() {
            return "(" + a.B[this.a] + ", data length:" + this.f3198d.length + ")";
        }

        public d(int i2, int i3, long j2, byte[] bArr) {
            this.a = i2;
            this.f3196b = i3;
            this.f3197c = j2;
            this.f3198d = bArr;
        }
    }

    public static class f {
        public final long a;
        public final long f3202b;

        public f(double d2) {
            this((long) (d2 * 10000.0d), 10000L);
        }

        public double a() {
            return this.a / this.f3202b;
        }

        public String toString() {
            return this.a + "/" + this.f3202b;
        }

        public f(long j2, long j3) {
            if (j3 == 0) {
                this.a = 0L;
                this.f3202b = 1L;
                return;
            }
            this.a = j2;
            this.f3202b = j3;
        }
    }

    static {
        e[] eVarArr;
        e[] eVarArr2 = {new e("NewSubfileType", 254, 4), new e("SubfileType", 255, 4), new e("ImageWidth", RecyclerView.c0.FLAG_TMP_DETACHED, 3, 4), new e("ImageLength", CustomCameraType.BUTTON_STATE_ONLY_CAPTURE, 3, 4), new e("BitsPerSample", CustomCameraType.BUTTON_STATE_ONLY_RECORDER, 3), new e("Compression", CustomCameraType.BUTTON_STATE_BOTH, 3), new e("PhotometricInterpretation", 262, 3), new e("ImageDescription", SubsamplingScaleImageView.ORIENTATION_270, 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", Code.INVALID_LBS_DATA, 1)};
        E = eVarArr2;
        e[] eVarArr3 = {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)};
        F = eVarArr3;
        e[] eVarArr4 = {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)};
        G = eVarArr4;
        e[] eVarArr5 = {new e("InteroperabilityIndex", 1, 2)};
        H = eVarArr5;
        e[] eVarArr6 = {new e("NewSubfileType", 254, 4), new e("SubfileType", 255, 4), new e("ThumbnailImageWidth", RecyclerView.c0.FLAG_TMP_DETACHED, 3, 4), new e("ThumbnailImageLength", CustomCameraType.BUTTON_STATE_ONLY_CAPTURE, 3, 4), new e("BitsPerSample", CustomCameraType.BUTTON_STATE_ONLY_RECORDER, 3), new e("Compression", CustomCameraType.BUTTON_STATE_BOTH, 3), new e("PhotometricInterpretation", 262, 3), new e("ImageDescription", SubsamplingScaleImageView.ORIENTATION_270, 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("Xmp", Code.INVALID_LBS_DATA, 1), 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)};
        I = eVarArr6;
        J = new e("StripOffsets", 273, 3);
        e[] eVarArr7 = {new e("ThumbnailImage", RecyclerView.c0.FLAG_TMP_DETACHED, 7), new e("CameraSettingsIFDPointer", 8224, 4), new e("ImageProcessingIFDPointer", 8256, 4)};
        K = eVarArr7;
        e[] eVarArr8 = {new e("PreviewImageStart", CustomCameraType.BUTTON_STATE_ONLY_CAPTURE, 4), new e("PreviewImageLength", CustomCameraType.BUTTON_STATE_ONLY_RECORDER, 4)};
        L = eVarArr8;
        e[] eVarArr9 = {new e("AspectFrame", 4371, 3)};
        M = eVarArr9;
        e[] eVarArr10 = {new e("ColorSpace", 55, 3)};
        N = eVarArr10;
        e[][] eVarArr11 = {eVarArr2, eVarArr3, eVarArr4, eVarArr5, eVarArr6, eVarArr2, eVarArr7, eVarArr8, eVarArr9, eVarArr10};
        O = eVarArr11;
        P = new e[]{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)};
        Q = new HashMap[eVarArr11.length];
        R = new HashMap[eVarArr11.length];
        S = new HashSet<>(Arrays.asList("FNumber", "DigitalZoomRatio", "ExposureTime", "SubjectDistance", "GPSTimeStamp"));
        T = new HashMap<>();
        Charset forName = Charset.forName("US-ASCII");
        U = forName;
        V = "Exif\u0000\u0000".getBytes(forName);
        W = "http://ns.adobe.com/xap/1.0/\u0000".getBytes(forName);
        Locale locale = Locale.US;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss", locale);
        z = simpleDateFormat;
        simpleDateFormat.setTimeZone(DesugarTimeZone.getTimeZone("UTC"));
        SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", locale);
        A = simpleDateFormat2;
        simpleDateFormat2.setTimeZone(DesugarTimeZone.getTimeZone("UTC"));
        int i2 = 0;
        while (true) {
            e[][] eVarArr12 = O;
            if (i2 < eVarArr12.length) {
                Q[i2] = new HashMap<>();
                R[i2] = new HashMap<>();
                for (e eVar : eVarArr12[i2]) {
                    Q[i2].put(Integer.valueOf(eVar.a), eVar);
                    R[i2].put(eVar.f3199b, eVar);
                }
                i2++;
            } else {
                HashMap<Integer, Integer> hashMap = T;
                e[] eVarArr13 = P;
                hashMap.put(Integer.valueOf(eVarArr13[0].a), 5);
                hashMap.put(Integer.valueOf(eVarArr13[1].a), 1);
                hashMap.put(Integer.valueOf(eVarArr13[2].a), 2);
                hashMap.put(Integer.valueOf(eVarArr13[3].a), 3);
                hashMap.put(Integer.valueOf(eVarArr13[4].a), 7);
                hashMap.put(Integer.valueOf(eVarArr13[5].a), 8);
                X = Pattern.compile(".*[1-9].*");
                Y = Pattern.compile("^(\\d{2}):(\\d{2}):(\\d{2})$");
                Z = Pattern.compile("^(\\d{4}):(\\d{2}):(\\d{2})\\s(\\d{2}):(\\d{2}):(\\d{2})$");
                a0 = Pattern.compile("^(\\d{4})-(\\d{2})-(\\d{2})\\s(\\d{2}):(\\d{2}):(\\d{2})$");
                return;
            }
        }
    }

    public a(String str) {
        e[][] eVarArr = O;
        this.g0 = new HashMap[eVarArr.length];
        this.h0 = new HashSet(eVarArr.length);
        this.i0 = ByteOrder.BIG_ENDIAN;
        Objects.requireNonNull(str, "filename cannot be null");
        A(str);
    }

    public static boolean B(BufferedInputStream bufferedInputStream) {
        byte[] bArr = V;
        bufferedInputStream.mark(bArr.length);
        byte[] bArr2 = new byte[bArr.length];
        bufferedInputStream.read(bArr2);
        bufferedInputStream.reset();
        int i2 = 0;
        while (true) {
            byte[] bArr3 = V;
            if (i2 >= bArr3.length) {
                return true;
            }
            if (bArr2[i2] != bArr3[i2]) {
                return false;
            }
            i2++;
        }
    }

    public static boolean D(byte[] bArr) {
        int i2 = 0;
        while (true) {
            byte[] bArr2 = f3182g;
            if (i2 >= bArr2.length) {
                return true;
            }
            if (bArr[i2] != bArr2[i2]) {
                return false;
            }
            i2++;
        }
    }

    public static boolean I(FileDescriptor fileDescriptor) {
        if (Build.VERSION.SDK_INT >= 21) {
            try {
                b.a.c(fileDescriptor, 0L, OsConstants.SEEK_CUR);
                return true;
            } catch (Exception unused) {
                if (a) {
                    Log.d("ExifInterface", "The file descriptor for the given input is not seekable");
                }
            }
        }
        return false;
    }

    public static boolean K(int i2) {
        return i2 == 4 || i2 == 13 || i2 == 14 || i2 == 3 || i2 == 0;
    }

    public static double c(String str, String str2) {
        try {
            String[] split = str.split(",", -1);
            String[] split2 = split[0].split("/", -1);
            String[] split3 = split[1].split("/", -1);
            String[] split4 = split[2].split("/", -1);
            double parseDouble = (Double.parseDouble(split2[0].trim()) / Double.parseDouble(split2[1].trim())) + ((Double.parseDouble(split3[0].trim()) / Double.parseDouble(split3[1].trim())) / 60.0d) + ((Double.parseDouble(split4[0].trim()) / Double.parseDouble(split4[1].trim())) / 3600.0d);
            if (!str2.equals("S") && !str2.equals("W")) {
                if (!str2.equals("N") && !str2.equals("E")) {
                    throw new IllegalArgumentException();
                }
                return parseDouble;
            }
            return -parseDouble;
        } catch (ArrayIndexOutOfBoundsException | NumberFormatException unused) {
            throw new IllegalArgumentException();
        }
    }

    public static boolean f0(int i2) {
        return (i2 == 4 || i2 == 9 || i2 == 13 || i2 == 14) ? false : true;
    }

    public static Pair<Integer, Integer> x(String str) {
        if (str.contains(",")) {
            String[] split = str.split(",", -1);
            Pair<Integer, Integer> x2 = x(split[0]);
            if (((Integer) x2.first).intValue() == 2) {
                return x2;
            }
            for (int i2 = 1; i2 < split.length; i2++) {
                Pair<Integer, Integer> x3 = x(split[i2]);
                int intValue = (((Integer) x3.first).equals(x2.first) || ((Integer) x3.second).equals(x2.first)) ? ((Integer) x2.first).intValue() : -1;
                int intValue2 = (((Integer) x2.second).intValue() == -1 || !(((Integer) x3.first).equals(x2.second) || ((Integer) x3.second).equals(x2.second))) ? -1 : ((Integer) x2.second).intValue();
                if (intValue == -1 && intValue2 == -1) {
                    return new Pair<>(2, -1);
                }
                if (intValue == -1) {
                    x2 = new Pair<>(Integer.valueOf(intValue2), -1);
                } else if (intValue2 == -1) {
                    x2 = new Pair<>(Integer.valueOf(intValue), -1);
                }
            }
            return x2;
        } 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 && parseDouble2 >= 0) {
                        if (parseDouble <= 2147483647L && 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 {
            try {
                try {
                    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);
                } catch (NumberFormatException unused2) {
                    return new Pair<>(2, -1);
                }
            } catch (NumberFormatException unused3) {
                Double.parseDouble(str);
                return new Pair<>(12, -1);
            }
        }
    }

    public final void A(String str) {
        Objects.requireNonNull(str, "filename cannot be null");
        FileInputStream fileInputStream = null;
        this.d0 = null;
        this.b0 = str;
        try {
            FileInputStream fileInputStream2 = new FileInputStream(str);
            try {
                if (I(fileInputStream2.getFD())) {
                    this.c0 = fileInputStream2.getFD();
                } else {
                    this.c0 = null;
                }
                N(fileInputStream2);
                b.o.a.b.c(fileInputStream2);
            } catch (Throwable th) {
                th = th;
                fileInputStream = fileInputStream2;
                b.o.a.b.c(fileInputStream);
                throw th;
            }
        } catch (Throwable th2) {
            th = th2;
        }
    }

    public final boolean C(byte[] bArr) {
        b bVar;
        long readInt;
        byte[] bArr2;
        b bVar2 = null;
        try {
            try {
                bVar = new b(bArr);
            } catch (Exception e2) {
                e = e2;
            }
        } catch (Throwable th) {
            th = th;
        }
        try {
            readInt = bVar.readInt();
            bArr2 = new byte[4];
            bVar.read(bArr2);
        } catch (Exception e3) {
            e = e3;
            bVar2 = bVar;
            if (a) {
                Log.d("ExifInterface", "Exception parsing HEIF file type box.", e);
            }
            if (bVar2 != null) {
                bVar2.close();
            }
            return false;
        } catch (Throwable th2) {
            th = th2;
            bVar2 = bVar;
            if (bVar2 != null) {
                bVar2.close();
            }
            throw th;
        }
        if (!Arrays.equals(bArr2, f3183h)) {
            bVar.close();
            return false;
        }
        long j2 = 16;
        if (readInt == 1) {
            readInt = bVar.readLong();
            if (readInt < 16) {
                bVar.close();
                return false;
            }
        } else {
            j2 = 8;
        }
        if (readInt > bArr.length) {
            readInt = bArr.length;
        }
        long j3 = readInt - j2;
        if (j3 < 8) {
            bVar.close();
            return false;
        }
        byte[] bArr3 = new byte[4];
        boolean z2 = false;
        boolean z3 = false;
        for (long j4 = 0; j4 < j3 / 4; j4++) {
            if (bVar.read(bArr3) != 4) {
                bVar.close();
                return false;
            }
            if (j4 != 1) {
                if (Arrays.equals(bArr3, f3184i)) {
                    z2 = true;
                } else if (Arrays.equals(bArr3, f3185j)) {
                    z3 = true;
                }
                if (z2 && z3) {
                    bVar.close();
                    return true;
                }
            }
        }
        bVar.close();
        return false;
    }

    public final boolean E(byte[] bArr) {
        boolean z2 = false;
        b bVar = null;
        try {
            b bVar2 = new b(bArr);
            try {
                ByteOrder Q2 = Q(bVar2);
                this.i0 = Q2;
                bVar2.p(Q2);
                short readShort = bVar2.readShort();
                z2 = (readShort == 20306 || readShort == 21330) ? true : true;
                bVar2.close();
                return z2;
            } catch (Exception unused) {
                bVar = bVar2;
                if (bVar != null) {
                    bVar.close();
                }
                return false;
            } catch (Throwable th) {
                th = th;
                bVar = bVar2;
                if (bVar != null) {
                    bVar.close();
                }
                throw th;
            }
        } catch (Exception unused2) {
        } catch (Throwable th2) {
            th = th2;
        }
    }

    public final boolean F(byte[] bArr) {
        int i2 = 0;
        while (true) {
            byte[] bArr2 = m;
            if (i2 >= bArr2.length) {
                return true;
            }
            if (bArr[i2] != bArr2[i2]) {
                return false;
            }
            i2++;
        }
    }

    public final boolean G(byte[] bArr) {
        byte[] bytes = "FUJIFILMCCD-RAW".getBytes(Charset.defaultCharset());
        for (int i2 = 0; i2 < bytes.length; i2++) {
            if (bArr[i2] != bytes[i2]) {
                return false;
            }
        }
        return true;
    }

    public final boolean H(byte[] bArr) {
        b bVar = null;
        try {
            b bVar2 = new b(bArr);
            try {
                ByteOrder Q2 = Q(bVar2);
                this.i0 = Q2;
                bVar2.p(Q2);
                boolean z2 = bVar2.readShort() == 85;
                bVar2.close();
                return z2;
            } catch (Exception unused) {
                bVar = bVar2;
                if (bVar != null) {
                    bVar.close();
                }
                return false;
            } catch (Throwable th) {
                th = th;
                bVar = bVar2;
                if (bVar != null) {
                    bVar.close();
                }
                throw th;
            }
        } catch (Exception unused2) {
        } catch (Throwable th2) {
            th = th2;
        }
    }

    public final boolean J(HashMap hashMap) {
        d dVar;
        int m2;
        d dVar2 = (d) hashMap.get("BitsPerSample");
        if (dVar2 != null) {
            int[] iArr = (int[]) dVar2.o(this.i0);
            int[] iArr2 = f3179d;
            if (Arrays.equals(iArr2, iArr)) {
                return true;
            }
            if (this.e0 == 3 && (dVar = (d) hashMap.get("PhotometricInterpretation")) != null && (((m2 = dVar.m(this.i0)) == 1 && Arrays.equals(iArr, f3181f)) || (m2 == 6 && Arrays.equals(iArr, iArr2)))) {
                return true;
            }
        }
        if (a) {
            Log.d("ExifInterface", "Unsupported data type value");
            return false;
        }
        return false;
    }

    public final boolean L(HashMap hashMap) {
        d dVar = (d) hashMap.get("ImageLength");
        d dVar2 = (d) hashMap.get("ImageWidth");
        if (dVar == null || dVar2 == null) {
            return false;
        }
        return dVar.m(this.i0) <= 512 && dVar2.m(this.i0) <= 512;
    }

    public final boolean M(byte[] bArr) {
        int i2 = 0;
        while (true) {
            byte[] bArr2 = q;
            if (i2 >= bArr2.length) {
                int i3 = 0;
                while (true) {
                    byte[] bArr3 = r;
                    if (i3 >= bArr3.length) {
                        return true;
                    }
                    if (bArr[q.length + i3 + 4] != bArr3[i3]) {
                        return false;
                    }
                    i3++;
                }
            } else if (bArr[i2] != bArr2[i2]) {
                return false;
            } else {
                i2++;
            }
        }
    }

    public final void N(InputStream inputStream) {
        Objects.requireNonNull(inputStream, "inputstream shouldn't be null");
        for (int i2 = 0; i2 < O.length; i2++) {
            try {
                try {
                    this.g0[i2] = new HashMap<>();
                } finally {
                    a();
                    if (a) {
                        P();
                    }
                }
            } catch (IOException | UnsupportedOperationException e2) {
                boolean z2 = a;
                if (z2) {
                    Log.w("ExifInterface", "Invalid image: ExifInterface got an unsupported image format file(ExifInterface supports JPEG and some RAW image formats only) or a corrupted JPEG file to ExifInterface.", e2);
                }
                a();
                if (!z2) {
                    return;
                }
            }
        }
        if (!this.f0) {
            BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream, 5000);
            this.e0 = n(bufferedInputStream);
            inputStream = bufferedInputStream;
        }
        if (f0(this.e0)) {
            g gVar = new g(inputStream);
            if (this.f0) {
                t(gVar);
            } else {
                int i3 = this.e0;
                if (i3 == 12) {
                    k(gVar);
                } else if (i3 == 7) {
                    o(gVar);
                } else if (i3 == 10) {
                    s(gVar);
                } else {
                    r(gVar);
                }
            }
            gVar.z(this.q0);
            e0(gVar);
        } else {
            b bVar = new b(inputStream);
            int i4 = this.e0;
            if (i4 == 4) {
                l(bVar, 0, 0);
            } else if (i4 == 13) {
                p(bVar);
            } else if (i4 == 9) {
                q(bVar);
            } else if (i4 == 14) {
                w(bVar);
            }
        }
    }

    public final void O(b bVar) {
        ByteOrder Q2 = Q(bVar);
        this.i0 = Q2;
        bVar.p(Q2);
        int readUnsignedShort = bVar.readUnsignedShort();
        int i2 = this.e0;
        if (i2 != 7 && i2 != 10 && readUnsignedShort != 42) {
            throw new IOException("Invalid start code: " + Integer.toHexString(readUnsignedShort));
        }
        int readInt = bVar.readInt();
        if (readInt < 8) {
            throw new IOException("Invalid first Ifd offset: " + readInt);
        }
        int i3 = readInt - 8;
        if (i3 > 0) {
            bVar.v(i3);
        }
    }

    public final void P() {
        for (int i2 = 0; i2 < this.g0.length; i2++) {
            Log.d("ExifInterface", "The size of tag group[" + i2 + "]: " + this.g0[i2].size());
            for (Map.Entry<String, d> entry : this.g0[i2].entrySet()) {
                d value = entry.getValue();
                Log.d("ExifInterface", "tagName: " + entry.getKey() + ", tagType: " + value.toString() + ", tagValue: '" + value.n(this.i0) + "'");
            }
        }
    }

    public final ByteOrder Q(b bVar) {
        short readShort = bVar.readShort();
        if (readShort == 18761) {
            if (a) {
                Log.d("ExifInterface", "readExifSegment: Byte Align II");
            }
            return ByteOrder.LITTLE_ENDIAN;
        } else if (readShort == 19789) {
            if (a) {
                Log.d("ExifInterface", "readExifSegment: Byte Align MM");
            }
            return ByteOrder.BIG_ENDIAN;
        } else {
            throw new IOException("Invalid byte order: " + Integer.toHexString(readShort));
        }
    }

    public final void R(byte[] bArr, int i2) {
        g gVar = new g(bArr);
        O(gVar);
        S(gVar, i2);
    }

    public final void S(g gVar, int i2) {
        String str;
        short s2;
        int[] iArr;
        long j2;
        boolean z2;
        short s3;
        long j3;
        String str2;
        int i3;
        String str3;
        int readUnsignedShort;
        this.h0.add(Integer.valueOf(gVar.f3193i));
        short readShort = gVar.readShort();
        String str4 = "ExifInterface";
        if (a) {
            Log.d("ExifInterface", "numberOfDirectoryEntry: " + ((int) readShort));
        }
        if (readShort <= 0) {
            return;
        }
        char c2 = 0;
        short s4 = 0;
        while (s4 < readShort) {
            int readUnsignedShort2 = gVar.readUnsignedShort();
            int readUnsignedShort3 = gVar.readUnsignedShort();
            int readInt = gVar.readInt();
            long b2 = gVar.b() + 4;
            e eVar = Q[i2].get(Integer.valueOf(readUnsignedShort2));
            boolean z3 = a;
            if (z3) {
                Object[] objArr = new Object[5];
                objArr[c2] = Integer.valueOf(i2);
                objArr[1] = Integer.valueOf(readUnsignedShort2);
                objArr[2] = eVar != null ? eVar.f3199b : null;
                objArr[3] = Integer.valueOf(readUnsignedShort3);
                objArr[4] = Integer.valueOf(readInt);
                Log.d(str4, String.format("ifdType: %d, tagNumber: %d, tagName: %s, dataFormat: %d, numberOfComponents: %d", objArr));
            }
            if (eVar != null) {
                if (readUnsignedShort3 > 0) {
                    if (readUnsignedShort3 < C.length) {
                        if (eVar.a(readUnsignedShort3)) {
                            if (readUnsignedShort3 == 7) {
                                readUnsignedShort3 = eVar.f3200c;
                            }
                            str = str4;
                            s2 = s4;
                            j2 = readInt * iArr[readUnsignedShort3];
                            if (j2 < 0 || j2 > 2147483647L) {
                                if (z3) {
                                    Log.d(str, "Skip the tag entry since the number of components is invalid: " + readInt);
                                }
                                z2 = false;
                                if (z2) {
                                    gVar.z(b2);
                                    s3 = readShort;
                                    str3 = str;
                                } else {
                                    if (j2 > 4) {
                                        int readInt2 = gVar.readInt();
                                        s3 = readShort;
                                        if (z3) {
                                            StringBuilder sb = new StringBuilder();
                                            j3 = b2;
                                            sb.append("seek to data offset: ");
                                            sb.append(readInt2);
                                            Log.d(str, sb.toString());
                                        } else {
                                            j3 = b2;
                                        }
                                        if (this.e0 == 7) {
                                            if ("MakerNote".equals(eVar.f3199b)) {
                                                this.r0 = readInt2;
                                            } else if (i2 == 6 && "ThumbnailImage".equals(eVar.f3199b)) {
                                                this.s0 = readInt2;
                                                this.t0 = readInt;
                                                d j4 = d.j(6, this.i0);
                                                i3 = readInt;
                                                d f2 = d.f(this.s0, this.i0);
                                                str2 = str;
                                                d f3 = d.f(this.t0, this.i0);
                                                this.g0[4].put("Compression", j4);
                                                this.g0[4].put("JPEGInterchangeFormat", f2);
                                                this.g0[4].put("JPEGInterchangeFormatLength", f3);
                                                gVar.z(readInt2);
                                            }
                                        }
                                        str2 = str;
                                        i3 = readInt;
                                        gVar.z(readInt2);
                                    } else {
                                        s3 = readShort;
                                        j3 = b2;
                                        str2 = str;
                                        i3 = readInt;
                                    }
                                    Integer num = T.get(Integer.valueOf(readUnsignedShort2));
                                    if (z3) {
                                        str3 = str2;
                                        Log.d(str3, "nextIfdType: " + num + " byteCount: " + j2);
                                    } else {
                                        str3 = str2;
                                    }
                                    if (num != null) {
                                        long j5 = -1;
                                        if (readUnsignedShort3 == 3) {
                                            readUnsignedShort = gVar.readUnsignedShort();
                                        } else {
                                            if (readUnsignedShort3 == 4) {
                                                j5 = gVar.j();
                                            } else if (readUnsignedShort3 == 8) {
                                                readUnsignedShort = gVar.readShort();
                                            } else if (readUnsignedShort3 == 9 || readUnsignedShort3 == 13) {
                                                readUnsignedShort = gVar.readInt();
                                            }
                                            if (z3) {
                                                Log.d(str3, String.format("Offset: %d, tagName: %s", Long.valueOf(j5), eVar.f3199b));
                                            }
                                            if (j5 <= 0) {
                                                if (!this.h0.contains(Integer.valueOf((int) j5))) {
                                                    gVar.z(j5);
                                                    S(gVar, num.intValue());
                                                } else if (z3) {
                                                    Log.d(str3, "Skip jump into the IFD since it has already been read: IfdType " + num + " (at " + j5 + ")");
                                                }
                                            } else if (z3) {
                                                Log.d(str3, "Skip jump into the IFD since its offset is invalid: " + j5);
                                            }
                                            gVar.z(j3);
                                        }
                                        j5 = readUnsignedShort;
                                        if (z3) {
                                        }
                                        if (j5 <= 0) {
                                        }
                                        gVar.z(j3);
                                    } else {
                                        long j6 = j3;
                                        byte[] bArr = new byte[(int) j2];
                                        gVar.readFully(bArr);
                                        d dVar = new d(readUnsignedShort3, i3, gVar.b() + this.q0, bArr);
                                        this.g0[i2].put(eVar.f3199b, dVar);
                                        if ("DNGVersion".equals(eVar.f3199b)) {
                                            this.e0 = 3;
                                        }
                                        if ((("Make".equals(eVar.f3199b) || "Model".equals(eVar.f3199b)) && dVar.n(this.i0).contains("PENTAX")) || ("Compression".equals(eVar.f3199b) && dVar.m(this.i0) == 65535)) {
                                            this.e0 = 8;
                                        }
                                        if (gVar.b() != j6) {
                                            gVar.z(j6);
                                        }
                                    }
                                }
                                s4 = (short) (s2 + 1);
                                str4 = str3;
                                readShort = s3;
                                c2 = 0;
                            } else {
                                z2 = true;
                                if (z2) {
                                }
                                s4 = (short) (s2 + 1);
                                str4 = str3;
                                readShort = s3;
                                c2 = 0;
                            }
                        } else if (z3) {
                            Log.d(str4, "Skip the tag entry since data format (" + B[readUnsignedShort3] + ") is unexpected for tag: " + eVar.f3199b);
                        }
                    }
                }
                str = str4;
                s2 = s4;
                if (z3) {
                    Log.d(str, "Skip the tag entry since data format is invalid: " + readUnsignedShort3);
                }
                j2 = 0;
                z2 = false;
                if (z2) {
                }
                s4 = (short) (s2 + 1);
                str4 = str3;
                readShort = s3;
                c2 = 0;
            } else if (z3) {
                Log.d(str4, "Skip the tag entry since tag number is not defined: " + readUnsignedShort2);
            }
            str = str4;
            s2 = s4;
            j2 = 0;
            z2 = false;
            if (z2) {
            }
            s4 = (short) (s2 + 1);
            str4 = str3;
            readShort = s3;
            c2 = 0;
        }
        String str5 = str4;
        int readInt3 = gVar.readInt();
        boolean z4 = a;
        if (z4) {
            Log.d(str5, String.format("nextIfdOffset: %d", Integer.valueOf(readInt3)));
        }
        long j7 = readInt3;
        if (j7 <= 0) {
            if (z4) {
                Log.d(str5, "Stop reading file since a wrong offset may cause an infinite loop: " + readInt3);
            }
        } else if (this.h0.contains(Integer.valueOf(readInt3))) {
            if (z4) {
                Log.d(str5, "Stop reading file since re-reading an IFD may cause an infinite loop: " + readInt3);
            }
        } else {
            gVar.z(j7);
            if (this.g0[4].isEmpty()) {
                S(gVar, 4);
            } else if (this.g0[5].isEmpty()) {
                S(gVar, 5);
            }
        }
    }

    public final void T(String str) {
        for (int i2 = 0; i2 < O.length; i2++) {
            this.g0[i2].remove(str);
        }
    }

    public final void U(int i2, String str, String str2) {
        if (this.g0[i2].isEmpty() || this.g0[i2].get(str) == null) {
            return;
        }
        HashMap<String, d>[] hashMapArr = this.g0;
        hashMapArr[i2].put(str2, hashMapArr[i2].get(str));
        this.g0[i2].remove(str);
    }

    public final void V(g gVar, int i2) {
        d dVar = this.g0[i2].get("ImageLength");
        d dVar2 = this.g0[i2].get("ImageWidth");
        if (dVar == null || dVar2 == null) {
            d dVar3 = this.g0[i2].get("JPEGInterchangeFormat");
            d dVar4 = this.g0[i2].get("JPEGInterchangeFormatLength");
            if (dVar3 == null || dVar4 == null) {
                return;
            }
            int m2 = dVar3.m(this.i0);
            int m3 = dVar3.m(this.i0);
            gVar.z(m2);
            byte[] bArr = new byte[m3];
            gVar.read(bArr);
            l(new b(bArr), m2, i2);
        }
    }

    public void W() {
        FileOutputStream fileOutputStream;
        FileInputStream fileInputStream;
        Closeable closeable;
        FileOutputStream fileOutputStream2;
        Exception exc;
        FileOutputStream fileOutputStream3;
        FileInputStream fileInputStream2;
        Exception e2;
        FileOutputStream fileOutputStream4;
        FileInputStream fileInputStream3;
        BufferedInputStream bufferedInputStream;
        if (K(this.e0)) {
            if (this.c0 == null && this.b0 == null) {
                throw new IOException("ExifInterface does not support saving attributes for the current input.");
            }
            if (this.j0 && this.k0 && !this.l0) {
                throw new IOException("ExifInterface does not support saving attributes when the image file has non-consecutive thumbnail strips");
            }
            this.u0 = true;
            this.o0 = u();
            BufferedInputStream bufferedInputStream2 = null;
            try {
                File createTempFile = File.createTempFile("temp", "tmp");
                if (this.b0 != null) {
                    fileInputStream = new FileInputStream(this.b0);
                } else if (Build.VERSION.SDK_INT >= 21) {
                    b.a.c(this.c0, 0L, OsConstants.SEEK_SET);
                    fileInputStream = new FileInputStream(this.c0);
                } else {
                    fileInputStream = null;
                }
                try {
                    fileOutputStream = new FileOutputStream(createTempFile);
                    try {
                        b.o.a.b.e(fileInputStream, fileOutputStream);
                        b.o.a.b.c(fileInputStream);
                        b.o.a.b.c(fileOutputStream);
                        try {
                            try {
                                try {
                                    fileInputStream3 = new FileInputStream(createTempFile);
                                    try {
                                        if (this.b0 != null) {
                                            fileOutputStream3 = new FileOutputStream(this.b0);
                                        } else if (Build.VERSION.SDK_INT >= 21) {
                                            b.a.c(this.c0, 0L, OsConstants.SEEK_SET);
                                            fileOutputStream3 = new FileOutputStream(this.c0);
                                        } else {
                                            fileOutputStream3 = null;
                                        }
                                        try {
                                            bufferedInputStream = new BufferedInputStream(fileInputStream3);
                                        } catch (Exception e3) {
                                            bufferedInputStream2 = fileInputStream3;
                                            exc = e3;
                                        }
                                    } catch (Exception e4) {
                                        e = e4;
                                        fileOutputStream2 = null;
                                        bufferedInputStream2 = fileInputStream3;
                                        exc = e;
                                        fileOutputStream3 = fileOutputStream2;
                                        try {
                                            fileInputStream2 = new FileInputStream(createTempFile);
                                        } catch (Exception e5) {
                                            fileInputStream2 = bufferedInputStream2;
                                            e2 = e5;
                                        } catch (Throwable th) {
                                            th = th;
                                        }
                                        try {
                                            if (this.b0 != null) {
                                                if (Build.VERSION.SDK_INT >= 21) {
                                                    b.a.c(this.c0, 0L, OsConstants.SEEK_SET);
                                                    fileOutputStream4 = new FileOutputStream(this.c0);
                                                }
                                                b.o.a.b.e(fileInputStream2, fileOutputStream3);
                                                b.o.a.b.c(fileInputStream2);
                                                b.o.a.b.c(fileOutputStream3);
                                                throw new IOException("Failed to save new file", exc);
                                            }
                                            fileOutputStream4 = new FileOutputStream(this.b0);
                                            fileOutputStream3 = fileOutputStream4;
                                            b.o.a.b.e(fileInputStream2, fileOutputStream3);
                                            b.o.a.b.c(fileInputStream2);
                                            b.o.a.b.c(fileOutputStream3);
                                            throw new IOException("Failed to save new file", exc);
                                        } catch (Exception e6) {
                                            e2 = e6;
                                            try {
                                                throw new IOException("Failed to save new file. Original file is stored in " + createTempFile.getAbsolutePath(), e2);
                                            } catch (Throwable th2) {
                                                th = th2;
                                                bufferedInputStream2 = fileInputStream2;
                                                b.o.a.b.c(bufferedInputStream2);
                                                b.o.a.b.c(fileOutputStream3);
                                                throw th;
                                            }
                                        } catch (Throwable th3) {
                                            th = th3;
                                            bufferedInputStream2 = fileInputStream2;
                                            b.o.a.b.c(bufferedInputStream2);
                                            b.o.a.b.c(fileOutputStream3);
                                            throw th;
                                        }
                                    }
                                } catch (Exception e7) {
                                    e = e7;
                                    fileOutputStream2 = null;
                                }
                            } catch (Throwable th4) {
                                th = th4;
                                closeable = null;
                                b.o.a.b.c(bufferedInputStream2);
                                b.o.a.b.c(closeable);
                                if (0 == 0) {
                                    createTempFile.delete();
                                }
                                throw th;
                            }
                        } catch (Throwable th5) {
                            th = th5;
                        }
                        try {
                            BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream3);
                            try {
                                int i2 = this.e0;
                                if (i2 == 4) {
                                    X(bufferedInputStream, bufferedOutputStream);
                                } else if (i2 == 13) {
                                    Y(bufferedInputStream, bufferedOutputStream);
                                } else if (i2 == 14) {
                                    Z(bufferedInputStream, bufferedOutputStream);
                                } else if (i2 == 3 || i2 == 0) {
                                    j0(new c(bufferedOutputStream, ByteOrder.BIG_ENDIAN));
                                }
                                b.o.a.b.c(bufferedInputStream);
                                b.o.a.b.c(bufferedOutputStream);
                                createTempFile.delete();
                                this.o0 = null;
                            } catch (Exception e8) {
                                exc = e8;
                                bufferedInputStream2 = fileInputStream3;
                                fileInputStream2 = new FileInputStream(createTempFile);
                                if (this.b0 != null) {
                                }
                                fileOutputStream3 = fileOutputStream4;
                                b.o.a.b.e(fileInputStream2, fileOutputStream3);
                                b.o.a.b.c(fileInputStream2);
                                b.o.a.b.c(fileOutputStream3);
                                throw new IOException("Failed to save new file", exc);
                            }
                        } catch (Exception e9) {
                            bufferedInputStream2 = fileInputStream3;
                            exc = e9;
                        } catch (Throwable th6) {
                            th = th6;
                            closeable = null;
                            bufferedInputStream2 = bufferedInputStream;
                            b.o.a.b.c(bufferedInputStream2);
                            b.o.a.b.c(closeable);
                            if (0 == 0) {
                            }
                            throw th;
                        }
                    } catch (Exception e10) {
                        e = e10;
                        bufferedInputStream2 = fileInputStream;
                        try {
                            throw new IOException("Failed to copy original file to temp file", e);
                        } catch (Throwable th7) {
                            th = th7;
                            b.o.a.b.c(bufferedInputStream2);
                            b.o.a.b.c(fileOutputStream);
                            throw th;
                        }
                    } catch (Throwable th8) {
                        th = th8;
                        bufferedInputStream2 = fileInputStream;
                        b.o.a.b.c(bufferedInputStream2);
                        b.o.a.b.c(fileOutputStream);
                        throw th;
                    }
                } catch (Exception e11) {
                    e = e11;
                    fileOutputStream = null;
                } catch (Throwable th9) {
                    th = th9;
                    fileOutputStream = null;
                }
            } catch (Exception e12) {
                e = e12;
                fileOutputStream = null;
            } catch (Throwable th10) {
                th = th10;
                fileOutputStream = null;
            }
        } else {
            throw new IOException("ExifInterface only supports saving attributes for JPEG, PNG, WebP, and DNG formats.");
        }
    }

    public final void X(InputStream inputStream, OutputStream outputStream) {
        if (a) {
            Log.d("ExifInterface", "saveJpegAttributes starting with (inputStream: " + inputStream + ", outputStream: " + outputStream + ")");
        }
        b bVar = new b(inputStream);
        c cVar = new c(outputStream, ByteOrder.BIG_ENDIAN);
        if (bVar.readByte() == -1) {
            cVar.j(-1);
            if (bVar.readByte() == -40) {
                cVar.j(-40);
                d dVar = null;
                if (g("Xmp") != null && this.v0) {
                    dVar = this.g0[0].remove("Xmp");
                }
                cVar.j(-1);
                cVar.j(-31);
                j0(cVar);
                if (dVar != null) {
                    this.g0[0].put("Xmp", dVar);
                }
                byte[] bArr = new byte[4096];
                while (bVar.readByte() == -1) {
                    byte readByte = bVar.readByte();
                    if (readByte == -39 || readByte == -38) {
                        cVar.j(-1);
                        cVar.j(readByte);
                        b.o.a.b.e(bVar, cVar);
                        return;
                    } else if (readByte != -31) {
                        cVar.j(-1);
                        cVar.j(readByte);
                        int readUnsignedShort = bVar.readUnsignedShort();
                        cVar.A(readUnsignedShort);
                        int i2 = readUnsignedShort - 2;
                        if (i2 < 0) {
                            throw new IOException("Invalid length");
                        }
                        while (i2 > 0) {
                            int read = bVar.read(bArr, 0, Math.min(i2, 4096));
                            if (read >= 0) {
                                cVar.write(bArr, 0, read);
                                i2 -= read;
                            }
                        }
                    } else {
                        int readUnsignedShort2 = bVar.readUnsignedShort() - 2;
                        if (readUnsignedShort2 >= 0) {
                            byte[] bArr2 = new byte[6];
                            if (readUnsignedShort2 >= 6) {
                                if (bVar.read(bArr2) == 6) {
                                    if (Arrays.equals(bArr2, V)) {
                                        bVar.v(readUnsignedShort2 - 6);
                                    }
                                } else {
                                    throw new IOException("Invalid exif");
                                }
                            }
                            cVar.j(-1);
                            cVar.j(readByte);
                            cVar.A(readUnsignedShort2 + 2);
                            if (readUnsignedShort2 >= 6) {
                                readUnsignedShort2 -= 6;
                                cVar.write(bArr2);
                            }
                            while (readUnsignedShort2 > 0) {
                                int read2 = bVar.read(bArr, 0, Math.min(readUnsignedShort2, 4096));
                                if (read2 >= 0) {
                                    cVar.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 Y(InputStream inputStream, OutputStream outputStream) {
        ByteArrayOutputStream byteArrayOutputStream;
        if (a) {
            Log.d("ExifInterface", "savePngAttributes starting with (inputStream: " + inputStream + ", outputStream: " + outputStream + ")");
        }
        b bVar = new b(inputStream);
        ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
        c cVar = new c(outputStream, byteOrder);
        byte[] bArr = m;
        b.o.a.b.f(bVar, cVar, bArr.length);
        int i2 = this.q0;
        if (i2 == 0) {
            int readInt = bVar.readInt();
            cVar.p(readInt);
            b.o.a.b.f(bVar, cVar, readInt + 4 + 4);
        } else {
            b.o.a.b.f(bVar, cVar, ((i2 - bArr.length) - 4) - 4);
            bVar.v(bVar.readInt() + 4 + 4);
        }
        ByteArrayOutputStream byteArrayOutputStream2 = null;
        try {
            byteArrayOutputStream = new ByteArrayOutputStream();
        } catch (Throwable th) {
            th = th;
        }
        try {
            c cVar2 = new c(byteArrayOutputStream, byteOrder);
            j0(cVar2);
            byte[] byteArray = ((ByteArrayOutputStream) cVar2.a).toByteArray();
            cVar.write(byteArray);
            CRC32 crc32 = new CRC32();
            crc32.update(byteArray, 4, byteArray.length - 4);
            cVar.p((int) crc32.getValue());
            b.o.a.b.c(byteArrayOutputStream);
            b.o.a.b.e(bVar, cVar);
        } catch (Throwable th2) {
            th = th2;
            byteArrayOutputStream2 = byteArrayOutputStream;
            b.o.a.b.c(byteArrayOutputStream2);
            throw th;
        }
    }

    public final void Z(InputStream inputStream, OutputStream outputStream) {
        ByteArrayOutputStream byteArrayOutputStream;
        int i2;
        int i3;
        int i4;
        int i5;
        if (a) {
            Log.d("ExifInterface", "saveWebpAttributes starting with (inputStream: " + inputStream + ", outputStream: " + outputStream + ")");
        }
        ByteOrder byteOrder = ByteOrder.LITTLE_ENDIAN;
        b bVar = new b(inputStream, byteOrder);
        c cVar = new c(outputStream, byteOrder);
        byte[] bArr = q;
        b.o.a.b.f(bVar, cVar, bArr.length);
        byte[] bArr2 = r;
        bVar.v(bArr2.length + 4);
        ByteArrayOutputStream byteArrayOutputStream2 = null;
        try {
            try {
                byteArrayOutputStream = new ByteArrayOutputStream();
            } catch (Throwable th) {
                th = th;
            }
        } catch (Exception e2) {
            e = e2;
        }
        try {
            c cVar2 = new c(byteArrayOutputStream, byteOrder);
            int i6 = this.q0;
            if (i6 != 0) {
                b.o.a.b.f(bVar, cVar2, ((i6 - ((bArr.length + 4) + bArr2.length)) - 4) - 4);
                bVar.v(4);
                bVar.v(bVar.readInt());
                j0(cVar2);
            } else {
                byte[] bArr3 = new byte[4];
                if (bVar.read(bArr3) == 4) {
                    byte[] bArr4 = u;
                    boolean z2 = true;
                    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) {
                            z2 = false;
                        }
                        cVar2.write(bArr4);
                        cVar2.p(readInt);
                        cVar2.write(bArr5);
                        if (z2) {
                            d(bVar, cVar2, x, null);
                            while (true) {
                                byte[] bArr6 = new byte[4];
                                inputStream.read(bArr6);
                                if (!Arrays.equals(bArr6, y)) {
                                    break;
                                }
                                e(bVar, cVar2, bArr6);
                            }
                            j0(cVar2);
                        } else {
                            d(bVar, cVar2, w, v);
                            j0(cVar2);
                        }
                    } else {
                        byte[] bArr7 = w;
                        if (Arrays.equals(bArr3, bArr7) || Arrays.equals(bArr3, v)) {
                            int readInt2 = bVar.readInt();
                            int i7 = 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(t, bArr9)) {
                                    i2 = bVar.readInt();
                                    i3 = (i2 << 18) >> 18;
                                    i4 = (i2 << 2) >> 18;
                                    i7 -= 10;
                                } else {
                                    throw new IOException("Encountered error while checking VP8 signature");
                                }
                            } else if (!Arrays.equals(bArr3, v)) {
                                i2 = 0;
                                i3 = 0;
                                i4 = 0;
                            } else if (bVar.readByte() == 47) {
                                i2 = bVar.readInt();
                                i5 = i2 & 8;
                                i7 -= 5;
                                i4 = ((i2 << 4) >> 18) + 1;
                                i3 = ((i2 << 18) >> 18) + 1;
                                cVar2.write(bArr4);
                                cVar2.p(10);
                                byte[] bArr10 = new byte[10];
                                bArr10[0] = (byte) (bArr10[0] | 8);
                                bArr10[0] = (byte) (bArr10[0] | (i5 << 4));
                                int i8 = i3 - 1;
                                int i9 = i4 - 1;
                                bArr10[4] = (byte) i8;
                                bArr10[5] = (byte) (i8 >> 8);
                                bArr10[6] = (byte) (i8 >> 16);
                                bArr10[7] = (byte) i9;
                                bArr10[8] = (byte) (i9 >> 8);
                                bArr10[9] = (byte) (i9 >> 16);
                                cVar2.write(bArr10);
                                cVar2.write(bArr3);
                                cVar2.p(readInt2);
                                if (!Arrays.equals(bArr3, bArr7)) {
                                    cVar2.write(bArr8);
                                    cVar2.write(t);
                                    cVar2.p(i2);
                                } else if (Arrays.equals(bArr3, v)) {
                                    cVar2.write(47);
                                    cVar2.p(i2);
                                }
                                b.o.a.b.f(bVar, cVar2, i7);
                                j0(cVar2);
                            } else {
                                throw new IOException("Encountered error while checking VP8L signature");
                            }
                            i5 = 0;
                            cVar2.write(bArr4);
                            cVar2.p(10);
                            byte[] bArr102 = new byte[10];
                            bArr102[0] = (byte) (bArr102[0] | 8);
                            bArr102[0] = (byte) (bArr102[0] | (i5 << 4));
                            int i82 = i3 - 1;
                            int i92 = i4 - 1;
                            bArr102[4] = (byte) i82;
                            bArr102[5] = (byte) (i82 >> 8);
                            bArr102[6] = (byte) (i82 >> 16);
                            bArr102[7] = (byte) i92;
                            bArr102[8] = (byte) (i92 >> 8);
                            bArr102[9] = (byte) (i92 >> 16);
                            cVar2.write(bArr102);
                            cVar2.write(bArr3);
                            cVar2.p(readInt2);
                            if (!Arrays.equals(bArr3, bArr7)) {
                            }
                            b.o.a.b.f(bVar, cVar2, i7);
                            j0(cVar2);
                        }
                    }
                } else {
                    throw new IOException("Encountered invalid length while parsing WebP chunk type");
                }
            }
            b.o.a.b.e(bVar, cVar2);
            int size = byteArrayOutputStream.size();
            byte[] bArr11 = r;
            cVar.p(size + bArr11.length);
            cVar.write(bArr11);
            byteArrayOutputStream.writeTo(cVar);
            b.o.a.b.c(byteArrayOutputStream);
        } catch (Exception e3) {
            e = e3;
            throw new IOException("Failed to save WebP file", e);
        } catch (Throwable th2) {
            th = th2;
            byteArrayOutputStream2 = byteArrayOutputStream;
            b.o.a.b.c(byteArrayOutputStream2);
            throw th;
        }
    }

    public final void a() {
        String g2 = g("DateTimeOriginal");
        if (g2 != null && g("DateTime") == null) {
            this.g0[0].put("DateTime", d.e(g2));
        }
        if (g("ImageWidth") == null) {
            this.g0[0].put("ImageWidth", d.f(0L, this.i0));
        }
        if (g("ImageLength") == null) {
            this.g0[0].put("ImageLength", d.f(0L, this.i0));
        }
        if (g("Orientation") == null) {
            this.g0[0].put("Orientation", d.f(0L, this.i0));
        }
        if (g("LightSource") == null) {
            this.g0[1].put("LightSource", d.f(0L, this.i0));
        }
    }

    public void a0(double d2) {
        String str = d2 >= 0.0d ? "0" : WakedResultReceiver.CONTEXT_KEY;
        b0("GPSAltitude", new f(Math.abs(d2)).toString());
        b0("GPSAltitudeRef", str);
    }

    public final String b(double d2) {
        long j2 = (long) d2;
        double d3 = d2 - j2;
        long j3 = (long) (d3 * 60.0d);
        long round = Math.round((d3 - (j3 / 60.0d)) * 3600.0d * 1.0E7d);
        return j2 + "/1," + j3 + "/1," + round + "/10000000";
    }

    public void b0(String str, String str2) {
        e eVar;
        int i2;
        Matcher matcher;
        String str3 = str;
        String str4 = str2;
        Objects.requireNonNull(str3, "tag shouldn't be null");
        if (("DateTime".equals(str3) || "DateTimeOriginal".equals(str3) || "DateTimeDigitized".equals(str3)) && str4 != null) {
            boolean find = Z.matcher(str4).find();
            boolean find2 = a0.matcher(str4).find();
            if (str2.length() != 19 || (!find && !find2)) {
                Log.w("ExifInterface", "Invalid value for " + str3 + " : " + str4);
                return;
            } else if (find2) {
                str4 = str4.replaceAll("-", ":");
            }
        }
        if ("ISOSpeedRatings".equals(str3)) {
            if (a) {
                Log.d("ExifInterface", "setAttribute: Replacing TAG_ISO_SPEED_RATINGS with TAG_PHOTOGRAPHIC_SENSITIVITY.");
            }
            str3 = "PhotographicSensitivity";
        }
        int i3 = 2;
        int i4 = 1;
        if (str4 != null && S.contains(str3)) {
            if (str3.equals("GPSTimeStamp")) {
                if (!Y.matcher(str4).find()) {
                    Log.w("ExifInterface", "Invalid value for " + str3 + " : " + str4);
                    return;
                }
                str4 = Integer.parseInt(matcher.group(1)) + "/1," + Integer.parseInt(matcher.group(2)) + "/1," + Integer.parseInt(matcher.group(3)) + "/1";
            } else {
                try {
                    str4 = new f(Double.parseDouble(str4)).toString();
                } catch (NumberFormatException unused) {
                    Log.w("ExifInterface", "Invalid value for " + str3 + " : " + str4);
                    return;
                }
            }
        }
        char c2 = 0;
        int i5 = 0;
        while (i5 < O.length) {
            if ((i5 != 4 || this.j0) && (eVar = R[i5].get(str3)) != null) {
                if (str4 == null) {
                    this.g0[i5].remove(str3);
                } else {
                    Pair<Integer, Integer> x2 = x(str4);
                    int i6 = -1;
                    if (eVar.f3200c != ((Integer) x2.first).intValue() && eVar.f3200c != ((Integer) x2.second).intValue()) {
                        int i7 = eVar.f3201d;
                        if (i7 != -1 && (i7 == ((Integer) x2.first).intValue() || eVar.f3201d == ((Integer) x2.second).intValue())) {
                            i2 = eVar.f3201d;
                        } else {
                            int i8 = eVar.f3200c;
                            if (i8 == i4 || i8 == 7 || i8 == i3) {
                                i2 = i8;
                            } else if (a) {
                                StringBuilder sb = new StringBuilder();
                                sb.append("Given tag (");
                                sb.append(str3);
                                sb.append(") value didn't match with one of expected formats: ");
                                String[] strArr = B;
                                sb.append(strArr[eVar.f3200c]);
                                sb.append(eVar.f3201d == -1 ? "" : ", " + strArr[eVar.f3201d]);
                                sb.append(" (guess: ");
                                sb.append(strArr[((Integer) x2.first).intValue()]);
                                sb.append(((Integer) x2.second).intValue() != -1 ? ", " + strArr[((Integer) x2.second).intValue()] : "");
                                sb.append(")");
                                Log.d("ExifInterface", sb.toString());
                            }
                        }
                    } else {
                        i2 = eVar.f3200c;
                    }
                    switch (i2) {
                        case 1:
                            this.g0[i5].put(str3, d.a(str4));
                            continue;
                            i5++;
                            i3 = 2;
                            c2 = 0;
                            i4 = 1;
                        case 2:
                        case 7:
                            this.g0[i5].put(str3, d.e(str4));
                            continue;
                            i5++;
                            i3 = 2;
                            c2 = 0;
                            i4 = 1;
                        case 3:
                            String[] split = str4.split(",", -1);
                            int[] iArr = new int[split.length];
                            for (int i9 = 0; i9 < split.length; i9++) {
                                iArr[i9] = Integer.parseInt(split[i9]);
                            }
                            this.g0[i5].put(str3, d.k(iArr, this.i0));
                            continue;
                            i5++;
                            i3 = 2;
                            c2 = 0;
                            i4 = 1;
                        case 4:
                            String[] split2 = str4.split(",", -1);
                            long[] jArr = new long[split2.length];
                            for (int i10 = 0; i10 < split2.length; i10++) {
                                jArr[i10] = Long.parseLong(split2[i10]);
                            }
                            this.g0[i5].put(str3, d.g(jArr, this.i0));
                            continue;
                            i5++;
                            i3 = 2;
                            c2 = 0;
                            i4 = 1;
                        case 5:
                            String[] split3 = str4.split(",", -1);
                            f[] fVarArr = new f[split3.length];
                            int i11 = 0;
                            while (i11 < split3.length) {
                                String[] split4 = split3[i11].split("/", i6);
                                fVarArr[i11] = new f((long) Double.parseDouble(split4[0]), (long) Double.parseDouble(split4[1]));
                                i11++;
                                i6 = -1;
                            }
                            this.g0[i5].put(str3, d.i(fVarArr, this.i0));
                            continue;
                            i5++;
                            i3 = 2;
                            c2 = 0;
                            i4 = 1;
                        case 6:
                        case 8:
                        case 11:
                        default:
                            if (a) {
                                Log.d("ExifInterface", "Data format isn't one of expected formats: " + i2);
                            } else {
                                continue;
                            }
                            i5++;
                            i3 = 2;
                            c2 = 0;
                            i4 = 1;
                        case 9:
                            String[] split5 = str4.split(",", -1);
                            int[] iArr2 = new int[split5.length];
                            for (int i12 = 0; i12 < split5.length; i12++) {
                                iArr2[i12] = Integer.parseInt(split5[i12]);
                            }
                            this.g0[i5].put(str3, d.c(iArr2, this.i0));
                            break;
                        case 10:
                            String[] split6 = str4.split(",", -1);
                            f[] fVarArr2 = new f[split6.length];
                            int i13 = 0;
                            while (i13 < split6.length) {
                                String[] split7 = split6[i13].split("/", -1);
                                fVarArr2[i13] = new f((long) Double.parseDouble(split7[c2]), (long) Double.parseDouble(split7[i4]));
                                i13++;
                                split6 = split6;
                                c2 = 0;
                                i4 = 1;
                            }
                            this.g0[i5].put(str3, d.d(fVarArr2, this.i0));
                            break;
                        case 12:
                            String[] split8 = str4.split(",", -1);
                            double[] dArr = new double[split8.length];
                            for (int i14 = 0; i14 < split8.length; i14++) {
                                dArr[i14] = Double.parseDouble(split8[i14]);
                            }
                            this.g0[i5].put(str3, d.b(dArr, this.i0));
                            break;
                    }
                }
            }
            i5++;
            i3 = 2;
            c2 = 0;
            i4 = 1;
        }
    }

    public void c0(Location location) {
        if (location == null) {
            return;
        }
        b0("GPSProcessingMethod", location.getProvider());
        d0(location.getLatitude(), location.getLongitude());
        a0(location.getAltitude());
        b0("GPSSpeedRef", "K");
        b0("GPSSpeed", new f((location.getSpeed() * ((float) TimeUnit.HOURS.toSeconds(1L))) / 1000.0f).toString());
        String[] split = z.format(new Date(location.getTime())).split("\\s+", -1);
        b0("GPSDateStamp", split[0]);
        b0("GPSTimeStamp", split[1]);
    }

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

    public void d0(double d2, double d3) {
        if (d2 >= -90.0d && d2 <= 90.0d && !Double.isNaN(d2)) {
            if (d3 >= -180.0d && d3 <= 180.0d && !Double.isNaN(d3)) {
                b0("GPSLatitudeRef", d2 >= 0.0d ? "N" : "S");
                b0("GPSLatitude", b(Math.abs(d2)));
                b0("GPSLongitudeRef", d3 >= 0.0d ? "E" : "W");
                b0("GPSLongitude", b(Math.abs(d3)));
                return;
            }
            throw new IllegalArgumentException("Longitude value " + d3 + " is not valid.");
        }
        throw new IllegalArgumentException("Latitude value " + d2 + " is not valid.");
    }

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

    public final void e0(b bVar) {
        HashMap<String, d> hashMap = this.g0[4];
        d dVar = hashMap.get("Compression");
        if (dVar != null) {
            int m2 = dVar.m(this.i0);
            this.p0 = m2;
            if (m2 != 1) {
                if (m2 == 6) {
                    y(bVar, hashMap);
                    return;
                } else if (m2 != 7) {
                    return;
                }
            }
            if (J(hashMap)) {
                z(bVar, hashMap);
                return;
            }
            return;
        }
        this.p0 = 6;
        y(bVar, hashMap);
    }

    public double f(double d2) {
        double h2 = h("GPSAltitude", -1.0d);
        int i2 = i("GPSAltitudeRef", -1);
        if (h2 < 0.0d || i2 < 0) {
            return d2;
        }
        return h2 * (i2 != 1 ? 1 : -1);
    }

    public String g(String str) {
        Objects.requireNonNull(str, "tag shouldn't be null");
        d j2 = j(str);
        if (j2 != null) {
            if (!S.contains(str)) {
                return j2.n(this.i0);
            }
            if (str.equals("GPSTimeStamp")) {
                int i2 = j2.a;
                if (i2 != 5 && i2 != 10) {
                    Log.w("ExifInterface", "GPS Timestamp format is not rational. format=" + j2.a);
                    return null;
                }
                f[] fVarArr = (f[]) j2.o(this.i0);
                if (fVarArr != null && fVarArr.length == 3) {
                    return String.format("%02d:%02d:%02d", Integer.valueOf((int) (((float) fVarArr[0].a) / ((float) fVarArr[0].f3202b))), Integer.valueOf((int) (((float) fVarArr[1].a) / ((float) fVarArr[1].f3202b))), Integer.valueOf((int) (((float) fVarArr[2].a) / ((float) fVarArr[2].f3202b))));
                }
                Log.w("ExifInterface", "Invalid GPS Timestamp array. array=" + Arrays.toString(fVarArr));
                return null;
            }
            try {
                return Double.toString(j2.l(this.i0));
            } catch (NumberFormatException unused) {
            }
        }
        return null;
    }

    public final void g0(int i2, int i3) {
        if (!this.g0[i2].isEmpty() && !this.g0[i3].isEmpty()) {
            d dVar = this.g0[i2].get("ImageLength");
            d dVar2 = this.g0[i2].get("ImageWidth");
            d dVar3 = this.g0[i3].get("ImageLength");
            d dVar4 = this.g0[i3].get("ImageWidth");
            if (dVar == null || dVar2 == null) {
                if (a) {
                    Log.d("ExifInterface", "First image does not contain valid size information");
                }
            } else if (dVar3 != null && dVar4 != null) {
                int m2 = dVar.m(this.i0);
                int m3 = dVar2.m(this.i0);
                int m4 = dVar3.m(this.i0);
                int m5 = dVar4.m(this.i0);
                if (m2 >= m4 || m3 >= m5) {
                    return;
                }
                HashMap<String, d>[] hashMapArr = this.g0;
                HashMap<String, d> hashMap = hashMapArr[i2];
                hashMapArr[i2] = hashMapArr[i3];
                hashMapArr[i3] = hashMap;
            } else if (a) {
                Log.d("ExifInterface", "Second image does not contain valid size information");
            }
        } else if (a) {
            Log.d("ExifInterface", "Cannot perform swap since only one image data exists");
        }
    }

    public double h(String str, double d2) {
        Objects.requireNonNull(str, "tag shouldn't be null");
        d j2 = j(str);
        if (j2 == null) {
            return d2;
        }
        try {
            return j2.l(this.i0);
        } catch (NumberFormatException unused) {
            return d2;
        }
    }

    public final void h0(g gVar, int i2) {
        d j2;
        d j3;
        d dVar = this.g0[i2].get("DefaultCropSize");
        d dVar2 = this.g0[i2].get("SensorTopBorder");
        d dVar3 = this.g0[i2].get("SensorLeftBorder");
        d dVar4 = this.g0[i2].get("SensorBottomBorder");
        d dVar5 = this.g0[i2].get("SensorRightBorder");
        if (dVar == null) {
            if (dVar2 != null && dVar3 != null && dVar4 != null && dVar5 != null) {
                int m2 = dVar2.m(this.i0);
                int m3 = dVar4.m(this.i0);
                int m4 = dVar5.m(this.i0);
                int m5 = dVar3.m(this.i0);
                if (m3 <= m2 || m4 <= m5) {
                    return;
                }
                d j4 = d.j(m3 - m2, this.i0);
                d j5 = d.j(m4 - m5, this.i0);
                this.g0[i2].put("ImageLength", j4);
                this.g0[i2].put("ImageWidth", j5);
                return;
            }
            V(gVar, i2);
            return;
        }
        if (dVar.a == 5) {
            f[] fVarArr = (f[]) dVar.o(this.i0);
            if (fVarArr != null && fVarArr.length == 2) {
                j2 = d.h(fVarArr[0], this.i0);
                j3 = d.h(fVarArr[1], this.i0);
            } else {
                Log.w("ExifInterface", "Invalid crop size values. cropSize=" + Arrays.toString(fVarArr));
                return;
            }
        } else {
            int[] iArr = (int[]) dVar.o(this.i0);
            if (iArr != null && iArr.length == 2) {
                j2 = d.j(iArr[0], this.i0);
                j3 = d.j(iArr[1], this.i0);
            } else {
                Log.w("ExifInterface", "Invalid crop size values. cropSize=" + Arrays.toString(iArr));
                return;
            }
        }
        this.g0[i2].put("ImageWidth", j2);
        this.g0[i2].put("ImageLength", j3);
    }

    public int i(String str, int i2) {
        Objects.requireNonNull(str, "tag shouldn't be null");
        d j2 = j(str);
        if (j2 == null) {
            return i2;
        }
        try {
            return j2.m(this.i0);
        } catch (NumberFormatException unused) {
            return i2;
        }
    }

    public final void i0() {
        g0(0, 5);
        g0(0, 4);
        g0(5, 4);
        d dVar = this.g0[1].get("PixelXDimension");
        d dVar2 = this.g0[1].get("PixelYDimension");
        if (dVar != null && dVar2 != null) {
            this.g0[0].put("ImageWidth", dVar);
            this.g0[0].put("ImageLength", dVar2);
        }
        if (this.g0[4].isEmpty() && L(this.g0[5])) {
            HashMap<String, d>[] hashMapArr = this.g0;
            hashMapArr[4] = hashMapArr[5];
            hashMapArr[5] = new HashMap<>();
        }
        if (!L(this.g0[4])) {
            Log.d("ExifInterface", "No image meets the size requirements of a thumbnail image.");
        }
        U(0, "ThumbnailOrientation", "Orientation");
        U(0, "ThumbnailImageLength", "ImageLength");
        U(0, "ThumbnailImageWidth", "ImageWidth");
        U(5, "ThumbnailOrientation", "Orientation");
        U(5, "ThumbnailImageLength", "ImageLength");
        U(5, "ThumbnailImageWidth", "ImageWidth");
        U(4, "Orientation", "ThumbnailOrientation");
        U(4, "ImageLength", "ThumbnailImageLength");
        U(4, "ImageWidth", "ThumbnailImageWidth");
    }

    public final d j(String str) {
        Objects.requireNonNull(str, "tag shouldn't be null");
        if ("ISOSpeedRatings".equals(str)) {
            if (a) {
                Log.d("ExifInterface", "getExifAttribute: Replacing TAG_ISO_SPEED_RATINGS with TAG_PHOTOGRAPHIC_SENSITIVITY.");
            }
            str = "PhotographicSensitivity";
        }
        for (int i2 = 0; i2 < O.length; i2++) {
            d dVar = this.g0[i2].get(str);
            if (dVar != null) {
                return dVar;
            }
        }
        return null;
    }

    public final int j0(c cVar) {
        e[][] eVarArr = O;
        int[] iArr = new int[eVarArr.length];
        int[] iArr2 = new int[eVarArr.length];
        for (e eVar : P) {
            T(eVar.f3199b);
        }
        if (this.j0) {
            if (this.k0) {
                T("StripOffsets");
                T("StripByteCounts");
            } else {
                T("JPEGInterchangeFormat");
                T("JPEGInterchangeFormatLength");
            }
        }
        for (int i2 = 0; i2 < O.length; i2++) {
            for (Object obj : this.g0[i2].entrySet().toArray()) {
                Map.Entry entry = (Map.Entry) obj;
                if (entry.getValue() == null) {
                    this.g0[i2].remove(entry.getKey());
                }
            }
        }
        if (!this.g0[1].isEmpty()) {
            this.g0[0].put(P[1].f3199b, d.f(0L, this.i0));
        }
        if (!this.g0[2].isEmpty()) {
            this.g0[0].put(P[2].f3199b, d.f(0L, this.i0));
        }
        if (!this.g0[3].isEmpty()) {
            this.g0[1].put(P[3].f3199b, d.f(0L, this.i0));
        }
        if (this.j0) {
            if (this.k0) {
                this.g0[4].put("StripOffsets", d.j(0, this.i0));
                this.g0[4].put("StripByteCounts", d.j(this.n0, this.i0));
            } else {
                this.g0[4].put("JPEGInterchangeFormat", d.f(0L, this.i0));
                this.g0[4].put("JPEGInterchangeFormatLength", d.f(this.n0, this.i0));
            }
        }
        for (int i3 = 0; i3 < O.length; i3++) {
            int i4 = 0;
            for (Map.Entry<String, d> entry2 : this.g0[i3].entrySet()) {
                int p2 = entry2.getValue().p();
                if (p2 > 4) {
                    i4 += p2;
                }
            }
            iArr2[i3] = iArr2[i3] + i4;
        }
        int i5 = 8;
        for (int i6 = 0; i6 < O.length; i6++) {
            if (!this.g0[i6].isEmpty()) {
                iArr[i6] = i5;
                i5 += (this.g0[i6].size() * 12) + 2 + 4 + iArr2[i6];
            }
        }
        if (this.j0) {
            if (this.k0) {
                this.g0[4].put("StripOffsets", d.j(i5, this.i0));
            } else {
                this.g0[4].put("JPEGInterchangeFormat", d.f(i5, this.i0));
            }
            this.m0 = i5;
            i5 += this.n0;
        }
        if (this.e0 == 4) {
            i5 += 8;
        }
        if (a) {
            for (int i7 = 0; i7 < O.length; i7++) {
                Log.d("ExifInterface", String.format("index: %d, offsets: %d, tag count: %d, data sizes: %d, total size: %d", Integer.valueOf(i7), Integer.valueOf(iArr[i7]), Integer.valueOf(this.g0[i7].size()), Integer.valueOf(iArr2[i7]), Integer.valueOf(i5)));
            }
        }
        if (!this.g0[1].isEmpty()) {
            this.g0[0].put(P[1].f3199b, d.f(iArr[1], this.i0));
        }
        if (!this.g0[2].isEmpty()) {
            this.g0[0].put(P[2].f3199b, d.f(iArr[2], this.i0));
        }
        if (!this.g0[3].isEmpty()) {
            this.g0[1].put(P[3].f3199b, d.f(iArr[3], this.i0));
        }
        int i8 = this.e0;
        if (i8 == 4) {
            cVar.A(i5);
            cVar.write(V);
        } else if (i8 == 13) {
            cVar.p(i5);
            cVar.write(n);
        } else if (i8 == 14) {
            cVar.write(s);
            cVar.p(i5);
        }
        cVar.v(this.i0 == ByteOrder.BIG_ENDIAN ? (short) 19789 : (short) 18761);
        cVar.b(this.i0);
        cVar.A(42);
        cVar.z(8L);
        for (int i9 = 0; i9 < O.length; i9++) {
            if (!this.g0[i9].isEmpty()) {
                cVar.A(this.g0[i9].size());
                int size = iArr[i9] + 2 + (this.g0[i9].size() * 12) + 4;
                for (Map.Entry<String, d> entry3 : this.g0[i9].entrySet()) {
                    int i10 = R[i9].get(entry3.getKey()).a;
                    d value = entry3.getValue();
                    int p3 = value.p();
                    cVar.A(i10);
                    cVar.A(value.a);
                    cVar.p(value.f3196b);
                    if (p3 > 4) {
                        cVar.z(size);
                        size += p3;
                    } else {
                        cVar.write(value.f3198d);
                        if (p3 < 4) {
                            while (p3 < 4) {
                                cVar.j(0);
                                p3++;
                            }
                        }
                    }
                }
                if (i9 == 0 && !this.g0[4].isEmpty()) {
                    cVar.z(iArr[4]);
                } else {
                    cVar.z(0L);
                }
                for (Map.Entry<String, d> entry4 : this.g0[i9].entrySet()) {
                    byte[] bArr = entry4.getValue().f3198d;
                    if (bArr.length > 4) {
                        cVar.write(bArr, 0, bArr.length);
                    }
                }
            }
        }
        if (this.j0) {
            cVar.write(v());
        }
        if (this.e0 == 14 && i5 % 2 == 1) {
            cVar.j(0);
        }
        cVar.b(ByteOrder.BIG_ENDIAN);
        return i5;
    }

    public final void k(g gVar) {
        String str;
        String str2;
        if (Build.VERSION.SDK_INT >= 28) {
            MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
            try {
                try {
                    b.C0069b.a(mediaMetadataRetriever, new C0068a(gVar));
                    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);
                        str = mediaMetadataRetriever.extractMetadata(30);
                        str2 = mediaMetadataRetriever.extractMetadata(31);
                    } else if ("yes".equals(extractMetadata4)) {
                        str3 = mediaMetadataRetriever.extractMetadata(18);
                        str = mediaMetadataRetriever.extractMetadata(19);
                        str2 = mediaMetadataRetriever.extractMetadata(24);
                    } else {
                        str = null;
                        str2 = null;
                    }
                    if (str3 != null) {
                        this.g0[0].put("ImageWidth", d.j(Integer.parseInt(str3), this.i0));
                    }
                    if (str != null) {
                        this.g0[0].put("ImageLength", d.j(Integer.parseInt(str), this.i0));
                    }
                    if (str2 != null) {
                        int i2 = 1;
                        int parseInt = Integer.parseInt(str2);
                        if (parseInt == 90) {
                            i2 = 6;
                        } else if (parseInt == 180) {
                            i2 = 3;
                        } else if (parseInt == 270) {
                            i2 = 8;
                        }
                        this.g0[0].put("Orientation", d.j(i2, this.i0));
                    }
                    if (extractMetadata != null && extractMetadata2 != null) {
                        int parseInt2 = Integer.parseInt(extractMetadata);
                        int parseInt3 = Integer.parseInt(extractMetadata2);
                        if (parseInt3 > 6) {
                            gVar.z(parseInt2);
                            byte[] bArr = new byte[6];
                            if (gVar.read(bArr) == 6) {
                                int i3 = parseInt2 + 6;
                                int i4 = parseInt3 - 6;
                                if (Arrays.equals(bArr, V)) {
                                    byte[] bArr2 = new byte[i4];
                                    if (gVar.read(bArr2) == i4) {
                                        this.q0 = i3;
                                        R(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");
                        }
                    }
                    if (a) {
                        Log.d("ExifInterface", "Heif meta: " + str3 + "x" + str + ", rotation " + str2);
                    }
                    return;
                } catch (RuntimeException unused) {
                    throw new UnsupportedOperationException("Failed to read EXIF from HEIF file. Given stream is either malformed or unsupported.");
                }
            } finally {
                mediaMetadataRetriever.release();
            }
        }
        throw new UnsupportedOperationException("Reading EXIF from HEIF files is supported from SDK 28 and above");
    }

    public final void l(b bVar, int i2, int i3) {
        byte readByte;
        byte readByte2;
        String str;
        String str2 = "ExifInterface";
        if (a) {
            Log.d("ExifInterface", "getJpegAttributes starting with: " + bVar);
        }
        bVar.p(ByteOrder.BIG_ENDIAN);
        byte b2 = -1;
        if (bVar.readByte() == -1) {
            if (bVar.readByte() != -40) {
                throw new IOException("Invalid marker: " + Integer.toHexString(readByte & 255));
            }
            int i4 = 2;
            int i5 = 2;
            while (true) {
                if (bVar.readByte() == b2) {
                    int i6 = i5 + 1;
                    byte readByte3 = bVar.readByte();
                    boolean z2 = a;
                    if (z2) {
                        Log.d(str2, "Found JPEG segment indicator: " + Integer.toHexString(readByte3 & 255));
                    }
                    int i7 = i6 + 1;
                    if (readByte3 != -39 && readByte3 != -38) {
                        int readUnsignedShort = bVar.readUnsignedShort() - i4;
                        int i8 = i7 + i4;
                        if (z2) {
                            Log.d(str2, "JPEG segment: " + Integer.toHexString(readByte3 & 255) + " (length: " + (readUnsignedShort + 2) + ")");
                        }
                        if (readUnsignedShort < 0) {
                            throw new IOException("Invalid length");
                        }
                        if (readByte3 == -31) {
                            byte[] bArr = new byte[readUnsignedShort];
                            bVar.readFully(bArr);
                            int i9 = i8 + readUnsignedShort;
                            byte[] bArr2 = V;
                            if (b.o.a.b.g(bArr, bArr2)) {
                                byte[] copyOfRange = Arrays.copyOfRange(bArr, bArr2.length, readUnsignedShort);
                                this.q0 = i2 + i8 + bArr2.length;
                                R(copyOfRange, i3);
                                e0(new b(copyOfRange));
                            } else {
                                byte[] bArr3 = W;
                                if (b.o.a.b.g(bArr, bArr3)) {
                                    int length = i8 + bArr3.length;
                                    byte[] copyOfRange2 = Arrays.copyOfRange(bArr, bArr3.length, readUnsignedShort);
                                    if (g("Xmp") == null) {
                                        str = str2;
                                        this.g0[0].put("Xmp", new d(1, copyOfRange2.length, length, copyOfRange2));
                                        this.v0 = true;
                                        i8 = i9;
                                    }
                                }
                            }
                            str = str2;
                            i8 = i9;
                        } else if (readByte3 != -2) {
                            switch (readByte3) {
                                default:
                                    switch (readByte3) {
                                        default:
                                            switch (readByte3) {
                                                default:
                                                    switch (readByte3) {
                                                    }
                                                case -55:
                                                case -54:
                                                case -53:
                                                    bVar.v(1);
                                                    this.g0[i3].put(i3 != 4 ? "ImageLength" : "ThumbnailImageLength", d.f(bVar.readUnsignedShort(), this.i0));
                                                    this.g0[i3].put(i3 != 4 ? "ImageWidth" : "ThumbnailImageWidth", d.f(bVar.readUnsignedShort(), this.i0));
                                                    readUnsignedShort -= 5;
                                                    break;
                                            }
                                        case -59:
                                        case -58:
                                        case -57:
                                            break;
                                    }
                                case -64:
                                case -63:
                                case -62:
                                case -61:
                                    break;
                            }
                            str = str2;
                            if (readUnsignedShort < 0) {
                                bVar.v(readUnsignedShort);
                                i5 = i8 + readUnsignedShort;
                                str2 = str;
                                i4 = 2;
                                b2 = -1;
                            } else {
                                throw new IOException("Invalid length");
                            }
                        } else {
                            byte[] bArr4 = new byte[readUnsignedShort];
                            if (bVar.read(bArr4) == readUnsignedShort) {
                                if (g("UserComment") == null) {
                                    this.g0[1].put("UserComment", d.e(new String(bArr4, U)));
                                }
                                str = str2;
                            } else {
                                throw new IOException("Invalid exif");
                            }
                        }
                        readUnsignedShort = 0;
                        if (readUnsignedShort < 0) {
                        }
                    }
                } else {
                    throw new IOException("Invalid marker:" + Integer.toHexString(readByte2 & 255));
                }
            }
        } else {
            throw new IOException("Invalid marker: " + Integer.toHexString(readByte & 255));
        }
    }

    public double[] m() {
        String g2 = g("GPSLatitude");
        String g3 = g("GPSLatitudeRef");
        String g4 = g("GPSLongitude");
        String g5 = g("GPSLongitudeRef");
        if (g2 == null || g3 == null || g4 == null || g5 == null) {
            return null;
        }
        try {
            return new double[]{c(g2, g3), c(g4, g5)};
        } catch (IllegalArgumentException unused) {
            Log.w("ExifInterface", "Latitude/longitude values are not parsable. " + String.format("latValue=%s, latRef=%s, lngValue=%s, lngRef=%s", g2, g3, g4, g5));
            return null;
        }
    }

    public final int n(BufferedInputStream bufferedInputStream) {
        bufferedInputStream.mark(5000);
        byte[] bArr = new byte[5000];
        bufferedInputStream.read(bArr);
        bufferedInputStream.reset();
        if (D(bArr)) {
            return 4;
        }
        if (G(bArr)) {
            return 9;
        }
        if (C(bArr)) {
            return 12;
        }
        if (E(bArr)) {
            return 7;
        }
        if (H(bArr)) {
            return 10;
        }
        if (F(bArr)) {
            return 13;
        }
        return M(bArr) ? 14 : 0;
    }

    public final void o(g gVar) {
        r(gVar);
        d dVar = this.g0[1].get("MakerNote");
        if (dVar != null) {
            g gVar2 = new g(dVar.f3198d);
            gVar2.p(this.i0);
            byte[] bArr = f3186k;
            byte[] bArr2 = new byte[bArr.length];
            gVar2.readFully(bArr2);
            gVar2.z(0L);
            byte[] bArr3 = f3187l;
            byte[] bArr4 = new byte[bArr3.length];
            gVar2.readFully(bArr4);
            if (Arrays.equals(bArr2, bArr)) {
                gVar2.z(8L);
            } else if (Arrays.equals(bArr4, bArr3)) {
                gVar2.z(12L);
            }
            S(gVar2, 6);
            d dVar2 = this.g0[7].get("PreviewImageStart");
            d dVar3 = this.g0[7].get("PreviewImageLength");
            if (dVar2 != null && dVar3 != null) {
                this.g0[5].put("JPEGInterchangeFormat", dVar2);
                this.g0[5].put("JPEGInterchangeFormatLength", dVar3);
            }
            d dVar4 = this.g0[8].get("AspectFrame");
            if (dVar4 != null) {
                int[] iArr = (int[]) dVar4.o(this.i0);
                if (iArr != null && iArr.length == 4) {
                    if (iArr[2] <= iArr[0] || iArr[3] <= iArr[1]) {
                        return;
                    }
                    int i2 = (iArr[2] - iArr[0]) + 1;
                    int i3 = (iArr[3] - iArr[1]) + 1;
                    if (i2 < i3) {
                        int i4 = i2 + i3;
                        i3 = i4 - i3;
                        i2 = i4 - i3;
                    }
                    d j2 = d.j(i2, this.i0);
                    d j3 = d.j(i3, this.i0);
                    this.g0[0].put("ImageWidth", j2);
                    this.g0[0].put("ImageLength", j3);
                    return;
                }
                Log.w("ExifInterface", "Invalid aspect frame values. frame=" + Arrays.toString(iArr));
            }
        }
    }

    public final void p(b bVar) {
        if (a) {
            Log.d("ExifInterface", "getPngAttributes starting with: " + bVar);
        }
        bVar.p(ByteOrder.BIG_ENDIAN);
        byte[] bArr = m;
        bVar.v(bArr.length);
        int length = bArr.length + 0;
        while (true) {
            try {
                int readInt = bVar.readInt();
                int i2 = length + 4;
                byte[] bArr2 = new byte[4];
                if (bVar.read(bArr2) == 4) {
                    int i3 = i2 + 4;
                    if (i3 == 16 && !Arrays.equals(bArr2, o)) {
                        throw new IOException("Encountered invalid PNG file--IHDR chunk should appearas the first chunk");
                    }
                    if (Arrays.equals(bArr2, p)) {
                        return;
                    }
                    if (Arrays.equals(bArr2, n)) {
                        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.q0 = i3;
                                R(bArr3, 0);
                                i0();
                                e0(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.o.a.b.a(bArr2));
                    }
                    int i4 = readInt + 4;
                    bVar.v(i4);
                    length = i3 + i4;
                } 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) {
        boolean z2 = a;
        if (z2) {
            Log.d("ExifInterface", "getRafAttributes starting with: " + bVar);
        }
        bVar.v(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 i2 = ByteBuffer.wrap(bArr).getInt();
        int i3 = ByteBuffer.wrap(bArr2).getInt();
        int i4 = ByteBuffer.wrap(bArr3).getInt();
        byte[] bArr4 = new byte[i3];
        bVar.v(i2 - bVar.b());
        bVar.read(bArr4);
        l(new b(bArr4), i2, 5);
        bVar.v(i4 - bVar.b());
        bVar.p(ByteOrder.BIG_ENDIAN);
        int readInt = bVar.readInt();
        if (z2) {
            Log.d("ExifInterface", "numberOfDirectoryEntry: " + readInt);
        }
        for (int i5 = 0; i5 < readInt; i5++) {
            int readUnsignedShort = bVar.readUnsignedShort();
            int readUnsignedShort2 = bVar.readUnsignedShort();
            if (readUnsignedShort == J.a) {
                short readShort = bVar.readShort();
                short readShort2 = bVar.readShort();
                d j2 = d.j(readShort, this.i0);
                d j3 = d.j(readShort2, this.i0);
                this.g0[0].put("ImageLength", j2);
                this.g0[0].put("ImageWidth", j3);
                if (a) {
                    Log.d("ExifInterface", "Updated to length: " + ((int) readShort) + ", width: " + ((int) readShort2));
                    return;
                }
                return;
            }
            bVar.v(readUnsignedShort2);
        }
    }

    public final void r(g gVar) {
        d dVar;
        O(gVar);
        S(gVar, 0);
        h0(gVar, 0);
        h0(gVar, 5);
        h0(gVar, 4);
        i0();
        if (this.e0 != 8 || (dVar = this.g0[1].get("MakerNote")) == null) {
            return;
        }
        g gVar2 = new g(dVar.f3198d);
        gVar2.p(this.i0);
        gVar2.v(6);
        S(gVar2, 9);
        d dVar2 = this.g0[9].get("ColorSpace");
        if (dVar2 != null) {
            this.g0[1].put("ColorSpace", dVar2);
        }
    }

    public final void s(g gVar) {
        if (a) {
            Log.d("ExifInterface", "getRw2Attributes starting with: " + gVar);
        }
        r(gVar);
        d dVar = this.g0[0].get("JpgFromRaw");
        if (dVar != null) {
            l(new b(dVar.f3198d), (int) dVar.f3197c, 5);
        }
        d dVar2 = this.g0[0].get("ISO");
        d dVar3 = this.g0[1].get("PhotographicSensitivity");
        if (dVar2 == null || dVar3 != null) {
            return;
        }
        this.g0[1].put("PhotographicSensitivity", dVar2);
    }

    public final void t(g gVar) {
        byte[] bArr = V;
        gVar.v(bArr.length);
        byte[] bArr2 = new byte[gVar.available()];
        gVar.readFully(bArr2);
        this.q0 = bArr.length;
        R(bArr2, 0);
    }

    public byte[] u() {
        int i2 = this.p0;
        if (i2 == 6 || i2 == 7) {
            return v();
        }
        return null;
    }

    public byte[] v() {
        FileDescriptor fileDescriptor;
        FileInputStream fileInputStream;
        Exception e2;
        FileDescriptor fileDescriptor2;
        FileInputStream fileInputStream2;
        FileInputStream fileInputStream3;
        Closeable closeable = null;
        if (!this.j0) {
            return null;
        }
        ?? r1 = this.o0;
        try {
            if (r1 != 0) {
                return r1;
            }
            try {
                r1 = this.d0;
                try {
                    if (r1 != 0) {
                        try {
                            if (r1.markSupported()) {
                                r1.reset();
                                fileInputStream3 = r1;
                            } else {
                                Log.d("ExifInterface", "Cannot read thumbnail from inputstream without mark/reset support");
                                b.o.a.b.c(r1);
                                return null;
                            }
                        } catch (Exception e3) {
                            e2 = e3;
                            fileDescriptor2 = null;
                            fileInputStream = r1;
                            Log.d("ExifInterface", "Encountered exception while getting thumbnail", e2);
                            b.o.a.b.c(fileInputStream);
                            if (fileDescriptor2 != null) {
                            }
                            return null;
                        } catch (Throwable th) {
                            th = th;
                            fileDescriptor = null;
                            closeable = r1;
                            b.o.a.b.c(closeable);
                            if (fileDescriptor != null) {
                                b.o.a.b.b(fileDescriptor);
                            }
                            throw th;
                        }
                    } else if (this.b0 != null) {
                        fileInputStream3 = new FileInputStream(this.b0);
                    } else {
                        if (Build.VERSION.SDK_INT >= 21) {
                            FileDescriptor b2 = b.a.b(this.c0);
                            try {
                                b.a.c(b2, 0L, OsConstants.SEEK_SET);
                                fileDescriptor2 = b2;
                                fileInputStream2 = new FileInputStream(b2);
                            } catch (Exception e4) {
                                e2 = e4;
                                fileDescriptor2 = b2;
                                fileInputStream = null;
                                Log.d("ExifInterface", "Encountered exception while getting thumbnail", e2);
                                b.o.a.b.c(fileInputStream);
                                if (fileDescriptor2 != null) {
                                }
                                return null;
                            } catch (Throwable th2) {
                                th = th2;
                                fileDescriptor = b2;
                                b.o.a.b.c(closeable);
                                if (fileDescriptor != null) {
                                }
                                throw th;
                            }
                        } else {
                            fileInputStream2 = null;
                            fileDescriptor2 = null;
                        }
                        if (fileInputStream2 == null) {
                            if (fileInputStream2.skip(this.m0 + this.q0) == this.m0 + this.q0) {
                                byte[] bArr = new byte[this.n0];
                                if (fileInputStream2.read(bArr) == this.n0) {
                                    this.o0 = bArr;
                                    b.o.a.b.c(fileInputStream2);
                                    if (fileDescriptor2 != null) {
                                        b.o.a.b.b(fileDescriptor2);
                                    }
                                    return bArr;
                                }
                                throw new IOException("Corrupted image");
                            }
                            throw new IOException("Corrupted image");
                        }
                        throw new FileNotFoundException();
                    }
                    if (fileInputStream2 == null) {
                    }
                } catch (Exception e5) {
                    e2 = e5;
                    fileInputStream = fileInputStream2;
                    Log.d("ExifInterface", "Encountered exception while getting thumbnail", e2);
                    b.o.a.b.c(fileInputStream);
                    if (fileDescriptor2 != null) {
                        b.o.a.b.b(fileDescriptor2);
                    }
                    return null;
                }
                fileDescriptor2 = null;
                fileInputStream2 = fileInputStream3;
            } catch (Exception e6) {
                fileInputStream = null;
                e2 = e6;
                fileDescriptor2 = null;
            } catch (Throwable th3) {
                th = th3;
                fileDescriptor = null;
            }
        } catch (Throwable th4) {
            th = th4;
        }
    }

    public final void w(b bVar) {
        if (a) {
            Log.d("ExifInterface", "getWebpAttributes starting with: " + bVar);
        }
        bVar.p(ByteOrder.LITTLE_ENDIAN);
        bVar.v(q.length);
        int readInt = bVar.readInt() + 8;
        byte[] bArr = r;
        bVar.v(bArr.length);
        int length = bArr.length + 8;
        while (true) {
            try {
                byte[] bArr2 = new byte[4];
                if (bVar.read(bArr2) == 4) {
                    int readInt2 = bVar.readInt();
                    int i2 = length + 4 + 4;
                    if (Arrays.equals(s, bArr2)) {
                        byte[] bArr3 = new byte[readInt2];
                        if (bVar.read(bArr3) == readInt2) {
                            this.q0 = i2;
                            R(bArr3, 0);
                            e0(new b(bArr3));
                            return;
                        }
                        throw new IOException("Failed to read given length for given PNG chunk type: " + b.o.a.b.a(bArr2));
                    }
                    if (readInt2 % 2 == 1) {
                        readInt2++;
                    }
                    length = i2 + readInt2;
                    if (length == readInt) {
                        return;
                    }
                    if (length <= readInt) {
                        bVar.v(readInt2);
                    } else {
                        throw new IOException("Encountered WebP file with invalid chunk size");
                    }
                } 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) {
        d dVar = (d) hashMap.get("JPEGInterchangeFormat");
        d dVar2 = (d) hashMap.get("JPEGInterchangeFormatLength");
        if (dVar == null || dVar2 == null) {
            return;
        }
        int m2 = dVar.m(this.i0);
        int m3 = dVar2.m(this.i0);
        if (this.e0 == 7) {
            m2 += this.r0;
        }
        if (m2 > 0 && m3 > 0) {
            this.j0 = true;
            if (this.b0 == null && this.d0 == null && this.c0 == null) {
                byte[] bArr = new byte[m3];
                bVar.skip(m2);
                bVar.read(bArr);
                this.o0 = bArr;
            }
            this.m0 = m2;
            this.n0 = m3;
        }
        if (a) {
            Log.d("ExifInterface", "Setting thumbnail attributes with offset: " + m2 + ", length: " + m3);
        }
    }

    public final void z(b bVar, HashMap hashMap) {
        d dVar = (d) hashMap.get("StripOffsets");
        d dVar2 = (d) hashMap.get("StripByteCounts");
        if (dVar == null || dVar2 == null) {
            return;
        }
        long[] d2 = b.o.a.b.d(dVar.o(this.i0));
        long[] d3 = b.o.a.b.d(dVar2.o(this.i0));
        if (d2 != null && d2.length != 0) {
            if (d3 != null && d3.length != 0) {
                if (d2.length != d3.length) {
                    Log.w("ExifInterface", "stripOffsets and stripByteCounts should have same length.");
                    return;
                }
                long j2 = 0;
                for (long j3 : d3) {
                    j2 += j3;
                }
                int i2 = (int) j2;
                byte[] bArr = new byte[i2];
                int i3 = 1;
                this.l0 = true;
                this.k0 = true;
                this.j0 = true;
                int i4 = 0;
                int i5 = 0;
                int i6 = 0;
                while (i4 < d2.length) {
                    int i7 = (int) d2[i4];
                    int i8 = (int) d3[i4];
                    if (i4 < d2.length - i3 && i7 + i8 != d2[i4 + 1]) {
                        this.l0 = false;
                    }
                    int i9 = i7 - i5;
                    if (i9 < 0) {
                        Log.d("ExifInterface", "Invalid strip offset value");
                        return;
                    }
                    long j4 = i9;
                    if (bVar.skip(j4) != j4) {
                        Log.d("ExifInterface", "Failed to skip " + i9 + " bytes.");
                        return;
                    }
                    int i10 = i5 + i9;
                    byte[] bArr2 = new byte[i8];
                    if (bVar.read(bArr2) != i8) {
                        Log.d("ExifInterface", "Failed to read " + i8 + " bytes.");
                        return;
                    }
                    i5 = i10 + i8;
                    System.arraycopy(bArr2, 0, bArr, i6, i8);
                    i6 += i8;
                    i4++;
                    i3 = 1;
                }
                this.o0 = bArr;
                if (this.l0) {
                    this.m0 = (int) d2[0];
                    this.n0 = i2;
                    return;
                }
                return;
            }
            Log.w("ExifInterface", "stripByteCounts should not be null or have zero length.");
            return;
        }
        Log.w("ExifInterface", "stripOffsets should not be null or have zero length.");
    }

    public static class g extends b {
        public g(byte[] bArr) {
            super(bArr);
            this.f3191c.mark(SubsamplingScaleImageView.TILE_SIZE_AUTO);
        }

        public void z(long j2) {
            int i2 = this.f3193i;
            if (i2 > j2) {
                this.f3193i = 0;
                this.f3191c.reset();
            } else {
                j2 -= i2;
            }
            v((int) j2);
        }

        public g(InputStream inputStream) {
            super(inputStream);
            if (inputStream.markSupported()) {
                this.f3191c.mark(SubsamplingScaleImageView.TILE_SIZE_AUTO);
                return;
            }
            throw new IllegalArgumentException("Cannot create SeekableByteOrderedDataInputStream with stream that does not support mark/reset");
        }
    }

    public static class e {
        public final int a;
        public final String f3199b;
        public final int f3200c;
        public final int f3201d;

        public e(String str, int i2, int i3) {
            this.f3199b = str;
            this.a = i2;
            this.f3200c = i3;
            this.f3201d = -1;
        }

        public boolean a(int i2) {
            int i3;
            int i4 = this.f3200c;
            if (i4 == 7 || i2 == 7 || i4 == i2 || (i3 = this.f3201d) == i2) {
                return true;
            }
            if ((i4 == 4 || i3 == 4) && i2 == 3) {
                return true;
            }
            if ((i4 == 9 || i3 == 9) && i2 == 8) {
                return true;
            }
            return (i4 == 12 || i3 == 12) && i2 == 11;
        }

        public e(String str, int i2, int i3, int i4) {
            this.f3199b = str;
            this.a = i2;
            this.f3200c = i3;
            this.f3201d = i4;
        }
    }

    public a(InputStream inputStream) {
        this(inputStream, 0);
    }

    public a(InputStream inputStream, int i2) {
        e[][] eVarArr = O;
        this.g0 = new HashMap[eVarArr.length];
        this.h0 = new HashSet(eVarArr.length);
        this.i0 = ByteOrder.BIG_ENDIAN;
        Objects.requireNonNull(inputStream, "inputStream cannot be null");
        this.b0 = null;
        if (i2 == 1) {
            BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream, V.length);
            if (!B(bufferedInputStream)) {
                Log.w("ExifInterface", "Given data does not follow the structure of an Exif-only data.");
                return;
            }
            this.f0 = true;
            this.d0 = null;
            this.c0 = null;
            inputStream = bufferedInputStream;
        } else if (inputStream instanceof AssetManager.AssetInputStream) {
            this.d0 = (AssetManager.AssetInputStream) inputStream;
            this.c0 = null;
        } else {
            if (inputStream instanceof FileInputStream) {
                FileInputStream fileInputStream = (FileInputStream) inputStream;
                if (I(fileInputStream.getFD())) {
                    this.d0 = null;
                    this.c0 = fileInputStream.getFD();
                }
            }
            this.d0 = null;
            this.c0 = null;
        }
        N(inputStream);
    }
}