package com.pingan.ai; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileFilter; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; /* loaded from: classes3.dex */ public final class y { /* loaded from: classes3.dex */ public static final class a implements FileFilter { @Override // java.io.FileFilter public final boolean accept(File file) { return true; } } /* loaded from: classes3.dex */ public interface b { boolean a(File file, File file2); } static { System.getProperty("line.separator"); } public static File a(String str) { if (b(str)) { return null; } return new File(str); } public static boolean b(File file, File file2, b bVar) { return a(file, file2, bVar, false); } public static boolean c(File file, File file2, b bVar) { return b(file, file2, bVar, false); } public static boolean d(File file) { return file != null && (!file.exists() || (file.isFile() && file.delete())); } public static boolean a(File file) { return file != null && (!file.exists() ? !file.mkdirs() : !file.isDirectory()); } public static boolean b(File file, File file2, b bVar, boolean z) { if (file == null || file2 == null || file.equals(file2) || !file.exists() || !file.isFile()) { return false; } if (file2.exists()) { if (bVar != null && !bVar.a(file, file2)) { return true; } if (!file2.delete()) { return false; } } if (!a(file2.getParentFile())) { return false; } try { if (!a(file2, new FileInputStream(file))) { return false; } if (z) { if (!d(file)) { return false; } } return true; } catch (FileNotFoundException unused) { return false; } } public static boolean c(File file) { if (file == null) { return false; } if (!file.exists()) { return true; } if (!file.isDirectory()) { return false; } File[] listFiles = file.listFiles(); if (listFiles != null && listFiles.length != 0) { for (File file2 : listFiles) { if (file2.isFile()) { if (!file2.delete()) { return false; } } else if (file2.isDirectory() && !c(file2)) { return false; } } } return file.delete(); } public static boolean a(String str, String str2) { return a(a(str), a(str2), null); } public static boolean a(File file, File file2, b bVar) { if (file == null) { return false; } if (file.isDirectory()) { return b(file, file2, bVar); } return c(file, file2, bVar); } public static boolean a(File file, File file2, b bVar, boolean z) { if (file == null || file2 == null) { return false; } StringBuilder sb = new StringBuilder(); sb.append(file.getPath()); sb.append(File.separator); String obj = sb.toString(); StringBuilder sb2 = new StringBuilder(); sb2.append(file2.getPath()); sb2.append(File.separator); String obj2 = sb2.toString(); if (obj2.contains(obj) || !file.exists() || !file.isDirectory() || !a(file2)) { return false; } for (File file3 : file.listFiles()) { StringBuilder sb3 = new StringBuilder(); sb3.append(obj2); sb3.append(file3.getName()); File file4 = new File(sb3.toString()); if (file3.isFile()) { if (!b(file3, file4, bVar, z)) { return false; } } else if (file3.isDirectory() && !a(file3, file4, bVar, z)) { return false; } } return !z || c(file); } public static boolean b(File file) { return a(file, new a()); } public static boolean b(String str) { if (str == null) { return true; } int length = str.length(); for (int i = 0; i < length; i++) { if (!Character.isWhitespace(str.charAt(i))) { return false; } } return true; } public static boolean a(File file, FileFilter fileFilter) { if (file == null || fileFilter == null) { return false; } if (!file.exists()) { return true; } if (!file.isDirectory()) { return false; } File[] listFiles = file.listFiles(); if (listFiles != null && listFiles.length != 0) { for (File file2 : listFiles) { if (fileFilter.accept(file2)) { if (file2.isFile()) { if (!file2.delete()) { return false; } } else if (file2.isDirectory() && !c(file2)) { return false; } } } } return true; } public static boolean a(File file, InputStream inputStream) { BufferedOutputStream bufferedOutputStream = null; try { BufferedOutputStream bufferedOutputStream2 = new BufferedOutputStream(new FileOutputStream(file)); try { byte[] bArr = new byte[8192]; while (true) { int read = inputStream.read(bArr, 0, 8192); if (read != -1) { bufferedOutputStream2.write(bArr, 0, read); } else { try { break; } catch (IOException unused) { } } } inputStream.close(); try { bufferedOutputStream2.close(); return true; } catch (IOException unused2) { return true; } } catch (IOException unused3) { bufferedOutputStream = bufferedOutputStream2; try { inputStream.close(); } catch (IOException unused4) { } if (bufferedOutputStream != null) { try { bufferedOutputStream.close(); } catch (IOException unused5) { } } return false; } catch (Throwable th) { th = th; bufferedOutputStream = bufferedOutputStream2; try { inputStream.close(); } catch (IOException unused6) { } if (bufferedOutputStream != null) { try { bufferedOutputStream.close(); throw th; } catch (IOException unused7) { throw th; } } throw th; } } catch (IOException unused8) { } catch (Throwable th2) { th = th2; } } }