package com.baidu.idl.main.facesdk.utils; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Environment; import android.text.TextUtils; import android.util.Log; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; public class FileUitls { public static boolean assetOpen(Context context, String str) { if (context == null || TextUtils.isEmpty(str)) { return false; } try { context.getAssets().open(str); return true; } catch (Exception unused) { return false; } } public static void deleteLicense(Context context, String str) { File file = new File(context.getFilesDir().getParent() + "/" + str); if (file.exists()) { file.delete(); } File dir = context.getDir(str, 0); if (dir != null && dir.exists()) { dir.delete(); } } public static boolean fileIsExists(String str) { try { if (new File(str).exists()) { return true; } Log.i("wtf", "file_state->file not exits"); return false; } catch (Exception e) { Log.i("wtf", "file_state->" + e.getMessage()); return false; } } public static File getBatchFaceDirectory(String str) { File sDRootFile = getSDRootFile(); if (sDRootFile == null || !sDRootFile.exists()) { return null; } File file = new File(sDRootFile, str); if (file.exists()) { return file; } file.mkdirs(); return file; } /* JADX WARNING: Removed duplicated region for block: B:18:0x0028 A[SYNTHETIC, Splitter:B:18:0x0028] */ /* JADX WARNING: Removed duplicated region for block: B:26:0x0036 A[SYNTHETIC, Splitter:B:26:0x0036] */ public static Bitmap getBitmap(Context context, String str) { Throwable th; Exception e; InputStream inputStream; InputStream inputStream2 = null; try { inputStream = context.getResources().getAssets().open(str); try { Bitmap decodeStream = BitmapFactory.decodeStream(inputStream); if (inputStream != null) { try { inputStream.close(); } catch (IOException e2) { e2.printStackTrace(); } } return decodeStream; } catch (Exception e3) { e = e3; try { e.printStackTrace(); if (inputStream != null) { try { inputStream.close(); } catch (IOException e4) { e4.printStackTrace(); } } return null; } catch (Throwable th2) { inputStream2 = inputStream; th = th2; if (inputStream2 != null) { try { inputStream2.close(); } catch (IOException e5) { e5.printStackTrace(); } } throw th; } } } catch (Exception e6) { e = e6; inputStream = null; e.printStackTrace(); if (inputStream != null) { } return null; } catch (Throwable th3) { th = th3; if (inputStream2 != null) { } throw th; } } public static byte[] getByteArrayFromAssets(Context context, String str) { byte[] bArr; IOException e; try { InputStream open = context.getAssets().open(str); bArr = new byte[open.available()]; try { open.read(bArr); open.close(); } catch (IOException e2) { e = e2; } } catch (IOException e3) { e = e3; bArr = null; Log.e("zq", "e-->" + e.getMessage()); e.printStackTrace(); return bArr; } return bArr; } public static File getFaceDirectory() { File sDRootFile = getSDRootFile(); if (sDRootFile == null || !sDRootFile.exists()) { return null; } File file = new File(sDRootFile, "faces"); if (file.exists()) { return file; } file.mkdirs(); return file; } /* JADX DEBUG: Failed to insert an additional move for type inference into block B:22:? */ /* JADX DEBUG: Failed to insert an additional move for type inference into block B:24:? */ /* JADX DEBUG: Failed to insert an additional move for type inference into block B:25:0x0035 */ /* JADX DEBUG: Failed to insert an additional move for type inference into block B:28:? */ /* JADX DEBUG: Failed to insert an additional move for type inference into block B:32:0x0040 */ /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Type inference failed for: r3v0 */ /* JADX WARN: Type inference failed for: r3v1 */ /* JADX WARN: Type inference failed for: r3v3, types: [java.io.InputStream] */ /* JADX WARN: Type inference failed for: r3v5, types: [java.io.FileInputStream] */ /* JADX WARN: Type inference failed for: r3v6 */ /* JADX WARN: Type inference failed for: r3v7 */ /* JADX WARN: Type inference failed for: r3v9 */ /* JADX WARN: Type inference failed for: r3v10 */ /* JADX WARN: Type inference failed for: r3v12 */ /* JADX WARN: Type inference failed for: r3v13 */ /* JADX WARN: Type inference failed for: r3v14 */ /* JADX WARNING: Code restructure failed: missing block: B:23:0x0031, code lost: if (r3 != 0) goto L_0x0037; */ /* JADX WARNING: Code restructure failed: missing block: B:25:0x0035, code lost: if (r3 != 0) goto L_0x0037; */ /* JADX WARNING: Code restructure failed: missing block: B:27:?, code lost: r3.close(); */ /* JADX WARNING: Code restructure failed: missing block: B:34:0x0055, code lost: if (r3 != 0) goto L_0x0062; */ /* JADX WARNING: Code restructure failed: missing block: B:39:0x005f, code lost: if (r3 != 0) goto L_0x0062; */ /* JADX WARNING: Code restructure failed: missing block: B:41:?, code lost: r3.close(); */ /* JADX WARNING: Removed duplicated region for block: B:18:0x002c A[SYNTHETIC, Splitter:B:18:0x002c] */ public static byte[] getModelContent(Context context, String str) { InputStream inputStream; Throwable th; byte[] bArr = new byte[0]; File file = new File(str); InputStream inputStream2 = 0; FileInputStream fileInputStream = null; inputStream2 = 0; inputStream2 = 0; if (file.exists()) { try { FileInputStream fileInputStream2 = new FileInputStream(file); try { bArr = new byte[fileInputStream2.available()]; fileInputStream2.read(bArr); try { fileInputStream2.close(); } catch (IOException unused) { } inputStream2 = fileInputStream2; } catch (FileNotFoundException unused2) { inputStream2 = fileInputStream2; } catch (IOException unused3) { inputStream2 = fileInputStream2; } catch (Throwable th2) { th = th2; fileInputStream = fileInputStream2; if (fileInputStream != null) { try { fileInputStream.close(); } catch (IOException unused4) { } } throw th; } } catch (FileNotFoundException unused5) { } catch (IOException unused6) { } catch (Throwable th3) { th = th3; if (fileInputStream != null) { } throw th; } } if (bArr.length > 0) { return bArr; } try { inputStream2 = context.getResources().getAssets().open(str); bArr = new byte[inputStream2.available()]; inputStream2.read(bArr); inputStream = inputStream2; } catch (IOException e) { e.printStackTrace(); inputStream = inputStream2; } catch (Throwable th4) { if (inputStream2 != 0) { try { inputStream2.close(); } catch (IOException unused7) { } } throw th4; } return bArr; } public static String getSDPath() { File externalStorageDirectory = Environment.getExternalStorageState().equals("mounted") ? Environment.getExternalStorageDirectory() : null; if (externalStorageDirectory != null) { return externalStorageDirectory.toString(); } return null; } public static File getSDRootFile() { if (isSdCardAvailable()) { return Environment.getExternalStorageDirectory(); } return null; } public static boolean isSdCardAvailable() { return Environment.getExternalStorageState().equals("mounted"); } public static String readFile(String str) { String str2; File file = new File(str); String str3 = ""; if (!file.isDirectory()) { try { FileInputStream fileInputStream = new FileInputStream(file); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream)); while (true) { String readLine = bufferedReader.readLine(); if (readLine == null) { break; } str3 = readLine; } fileInputStream.close(); } catch (FileNotFoundException unused) { } catch (IOException e) { str2 = e.getMessage(); } return str3; } str2 = "The File doesn't not exist."; Log.d("TestFile", str2); return str3; } public static ArrayList<String> readLicense(String str) { String str2; ArrayList<String> arrayList = new ArrayList<>(); File file = new File(str); if (!file.isDirectory()) { try { FileInputStream fileInputStream = new FileInputStream(file); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream)); while (true) { String readLine = bufferedReader.readLine(); if (readLine == null) { break; } arrayList.add(readLine); } fileInputStream.close(); } catch (FileNotFoundException unused) { } catch (IOException e) { str2 = e.getMessage(); } return arrayList; } str2 = "The File doesn't not exist."; Log.d("TestFile", str2); return arrayList; } public static Bitmap returnBitMap(String str) { URL url; Bitmap bitmap = null; try { url = new URL(str); } catch (MalformedURLException e) { e.printStackTrace(); url = null; } try { HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); httpURLConnection.setDoInput(true); httpURLConnection.connect(); InputStream inputStream = httpURLConnection.getInputStream(); bitmap = BitmapFactory.decodeStream(inputStream); inputStream.close(); return bitmap; } catch (IOException e2) { e2.printStackTrace(); return bitmap; } } /* JADX WARNING: Removed duplicated region for block: B:18:0x0025 A[SYNTHETIC, Splitter:B:18:0x0025] */ /* JADX WARNING: Removed duplicated region for block: B:23:0x0031 A[SYNTHETIC, Splitter:B:23:0x0031] */ /* JADX WARNING: Removed duplicated region for block: B:31:? A[RETURN, SYNTHETIC] */ public static boolean saveFile(File file, Bitmap bitmap) { Throwable th; Exception e; FileOutputStream fileOutputStream = null; try { FileOutputStream fileOutputStream2 = new FileOutputStream(file); try { bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream2); try { fileOutputStream2.close(); return true; } catch (Exception e2) { e2.printStackTrace(); return true; } } catch (Exception e3) { e = e3; fileOutputStream = fileOutputStream2; try { e.printStackTrace(); if (fileOutputStream != null) { } } catch (Throwable th2) { th = th2; if (fileOutputStream != null) { } throw th; } } catch (Throwable th3) { th = th3; fileOutputStream = fileOutputStream2; if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (Exception e4) { e4.printStackTrace(); } } throw th; } } catch (Exception e5) { e = e5; e.printStackTrace(); if (fileOutputStream != null) { return false; } try { fileOutputStream.close(); return false; } catch (Exception e6) { e6.printStackTrace(); return false; } } } public static boolean writeTxtFile(String str, String str2) { File file = new File(str2); if (!file.exists()) { return false; } try { FileOutputStream fileOutputStream = new FileOutputStream(file); fileOutputStream.write(str.getBytes("utf-8")); fileOutputStream.close(); return true; } catch (Exception e) { e.printStackTrace(); return false; } } }