package o;

import android.content.Context;
import android.net.Uri;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.Ru, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C0461Ru extends Sb0 implements SC {
    public final /* synthetic */ int p;
    public final /* synthetic */ Context q;
    public final /* synthetic */ Uri r;
    public final /* synthetic */ String s;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public /* synthetic */ C0461Ru(Context context, Uri uri, String str, InterfaceC0220Im interfaceC0220Im, int i) {
        super(2, interfaceC0220Im);
        this.p = i;
        this.q = context;
        this.r = uri;
        this.s = str;
    }

    @Override // o.SC
    public final Object f(Object obj, Object obj2) {
        InterfaceC0065Cn interfaceC0065Cn = (InterfaceC0065Cn) obj;
        InterfaceC0220Im interfaceC0220Im = (InterfaceC0220Im) obj2;
        switch (this.p) {
        }
        return ((C0461Ru) l(interfaceC0065Cn, interfaceC0220Im)).n(Oh0.a);
    }

    @Override // o.AbstractC0728ad
    public final InterfaceC0220Im l(Object obj, InterfaceC0220Im interfaceC0220Im) {
        switch (this.p) {
            case 0:
                return new C0461Ru(this.q, this.r, this.s, interfaceC0220Im, 0);
            default:
                return new C0461Ru(this.q, this.r, this.s, interfaceC0220Im, 1);
        }
    }

    @Override // o.AbstractC0728ad
    public final Object n(Object obj) throws IOException {
        InputStream inputStreamOpenInputStream;
        FileOutputStream fileOutputStream;
        switch (this.p) {
            case 0:
                Context context = this.q;
                IJ.H(obj);
                try {
                    inputStreamOpenInputStream = context.getContentResolver().openInputStream(this.r);
                    if (inputStreamOpenInputStream == null) {
                        return null;
                    }
                    File fileCreateTempFile = File.createTempFile(this.s, ".tmp", context.getCacheDir());
                    try {
                        fileOutputStream = new FileOutputStream(fileCreateTempFile);
                        try {
                            byte[] bArr = new byte[8192];
                            for (int i = inputStreamOpenInputStream.read(bArr); i >= 0; i = inputStreamOpenInputStream.read(bArr)) {
                                fileOutputStream.write(bArr, 0, i);
                            }
                            fileOutputStream.close();
                            inputStreamOpenInputStream.close();
                            return fileCreateTempFile;
                        } finally {
                            try {
                                throw th;
                            } finally {
                            }
                        }
                    } finally {
                        try {
                            throw th;
                        } finally {
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    return null;
                }
            default:
                Context context2 = this.q;
                IJ.H(obj);
                try {
                    inputStreamOpenInputStream = context2.getContentResolver().openInputStream(this.r);
                    if (inputStreamOpenInputStream == null) {
                        return null;
                    }
                    File fileCreateTempFile2 = File.createTempFile(this.s, ".tmp", context2.getCacheDir());
                    try {
                        fileOutputStream = new FileOutputStream(fileCreateTempFile2);
                        try {
                            byte[] bArr2 = new byte[8192];
                            for (int i2 = inputStreamOpenInputStream.read(bArr2); i2 >= 0; i2 = inputStreamOpenInputStream.read(bArr2)) {
                                fileOutputStream.write(bArr2, 0, i2);
                            }
                            fileOutputStream.close();
                            inputStreamOpenInputStream.close();
                            return fileCreateTempFile2;
                        } finally {
                        }
                    } finally {
                    }
                } catch (Exception e2) {
                    e2.printStackTrace();
                    return null;
                }
        }
    }
}
