package b5;

import a5.g;
import android.net.Uri;
import android.util.Log;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.data.j;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Objects;

/* JADX INFO: loaded from: classes.dex */
public final class c implements com.bumptech.glide.load.data.e {

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public InputStream f4727c;

    public c(Uri uri, e eVar) {
        this.f4725a = uri;
        this.f4726b = eVar;
    }

    @Override // com.bumptech.glide.load.data.e
    public final Class a() {
        return InputStream.class;
    }

    @Override // com.bumptech.glide.load.data.e
    public final void b() {
        InputStream inputStream = this.f4727c;
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException unused) {
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:22:0x0040  */
    /* JADX WARN: Removed duplicated region for block: B:36:? A[RETURN, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final InputStream c() throws Throwable {
        int orientation;
        e eVar = this.f4726b;
        Uri uri = this.f4725a;
        InputStream inputStreamA = eVar.a(uri);
        if (inputStreamA != null) {
            eVar.getClass();
            InputStream inputStreamOpenInputStream = null;
            try {
                try {
                    inputStreamOpenInputStream = eVar.f4730c.openInputStream(uri);
                    orientation = g.getOrientation((List<a5.c>) eVar.f4731d, inputStreamOpenInputStream, eVar.f4729b);
                    if (inputStreamOpenInputStream != null) {
                        try {
                            inputStreamOpenInputStream.close();
                        } catch (IOException unused) {
                        }
                    }
                } catch (IOException | NullPointerException unused2) {
                    if (Log.isLoggable("ThumbStreamOpener", 3)) {
                        Objects.toString(uri);
                    }
                    if (inputStreamOpenInputStream != null) {
                        try {
                            inputStreamOpenInputStream.close();
                        } catch (IOException unused3) {
                        }
                    }
                    orientation = -1;
                    if (orientation == -1) {
                    }
                }
            } catch (Throwable th) {
                if (inputStreamOpenInputStream != null) {
                    try {
                        inputStreamOpenInputStream.close();
                    } catch (IOException unused4) {
                    }
                }
                throw th;
            }
        } else {
            orientation = -1;
        }
        return orientation == -1 ? new j(inputStreamA, orientation) : inputStreamA;
    }

    @Override // com.bumptech.glide.load.data.e
    public final void cancel() {
    }

    @Override // com.bumptech.glide.load.data.e
    public final DataSource d() {
        return DataSource.f5589a;
    }

    @Override // com.bumptech.glide.load.data.e
    public final void e(Priority priority, com.bumptech.glide.load.data.d dVar) throws Throwable {
        try {
            InputStream inputStreamC = c();
            this.f4727c = inputStreamC;
            dVar.onDataReady(inputStreamC);
        } catch (FileNotFoundException e10) {
            dVar.c(e10);
        }
    }
}
