package io.flutter.plugins.imagepicker; import android.content.Context; import android.database.Cursor; import android.net.Uri; import android.webkit.MimeTypeMap; import io.flutter.Log; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.UUID; /* loaded from: classes6.dex */ class FileUtils { /* JADX INFO: Access modifiers changed from: package-private */ public String getPathFromUri(Context context, Uri uri) { try { InputStream openInputStream = context.getContentResolver().openInputStream(uri); try { File file = new File(context.getCacheDir(), UUID.randomUUID().toString()); file.mkdir(); file.deleteOnExit(); String imageName = getImageName(context, uri); if (imageName == null) { StringBuilder sb = new StringBuilder("Cannot get file name for "); sb.append(uri); Log.w("FileUtils", sb.toString()); StringBuilder sb2 = new StringBuilder("image_picker"); sb2.append(getImageExtension(context, uri)); imageName = sb2.toString(); } File file2 = new File(file, imageName); FileOutputStream fileOutputStream = new FileOutputStream(file2); try { copy(openInputStream, fileOutputStream); String path = file2.getPath(); fileOutputStream.close(); if (openInputStream != null) { openInputStream.close(); } return path; } finally { } } finally { } } catch (IOException unused) { return null; } } private static String getImageExtension(Context context, Uri uri) { String str; try { if (uri.getScheme().equals("content")) { str = MimeTypeMap.getSingleton().getExtensionFromMimeType(context.getContentResolver().getType(uri)); } else { str = MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(new File(uri.getPath())).toString()); } } catch (Exception unused) { str = null; } if (str == null || str.isEmpty()) { str = "jpg"; } return ".".concat(String.valueOf(str)); } /* JADX WARN: Code restructure failed: missing block: B:4:0x002c, code lost: r0.close(); */ /* JADX WARN: Code restructure failed: missing block: B:5:0x002f, code lost: return null; */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ private static java.lang.String getImageName(android.content.Context r0, android.net.Uri r1) { /* android.database.Cursor r0 = queryImageName(r0, r1) if (r0 == 0) goto L2a boolean r1 = r0.moveToFirst() // Catch: java.lang.Throwable -> L1e if (r1 == 0) goto L2a int r1 = r0.getColumnCount() // Catch: java.lang.Throwable -> L1e if (r1 > 0) goto L13 goto L2a L13: r1 = 0 java.lang.String r1 = r0.getString(r1) // Catch: java.lang.Throwable -> L1e if (r0 == 0) goto L1d r0.close() L1d: return r1 L1e: r1 = move-exception if (r0 == 0) goto L29 r0.close() // Catch: java.lang.Throwable -> L25 goto L29 L25: r0 = move-exception r1.addSuppressed(r0) L29: throw r1 L2a: if (r0 == 0) goto L2f r0.close() L2f: r0 = 0 return r0 */ throw new UnsupportedOperationException("Method not decompiled: io.flutter.plugins.imagepicker.FileUtils.getImageName(android.content.Context, android.net.Uri):java.lang.String"); } private static Cursor queryImageName(Context context, Uri uri) { return context.getContentResolver().query(uri, new String[]{"_display_name"}, null, null, null); } private static void copy(InputStream inputStream, OutputStream outputStream) throws IOException { byte[] bArr = new byte[4096]; while (true) { int read = inputStream.read(bArr); if (read != -1) { outputStream.write(bArr, 0, read); } else { outputStream.flush(); return; } } } }