package com.vungle.warren.utility; import android.os.Build; import android.util.Log; import java.io.Closeable; 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.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; /* loaded from: classes2.dex */ public abstract class j { /* renamed from: a, reason: collision with root package name */ private static b f8598a = new a(); /* renamed from: b, reason: collision with root package name */ private static final String f8599b = j.class.getSimpleName(); /* renamed from: c, reason: collision with root package name */ protected static final List f8600c = Arrays.asList(LinkedHashSet.class, HashSet.class, HashMap.class, ArrayList.class, File.class); class a implements b { a() { } @Override // com.vungle.warren.utility.j.b /* renamed from: b, reason: merged with bridge method [inline-methods] */ public s a(InputStream inputStream) { return new s(inputStream, j.f8600c); } } interface b { ObjectInputStream a(InputStream inputStream); } public static void a(Closeable closeable) { if (closeable != null) { try { closeable.close(); } catch (IOException unused) { } } } public static void b(File file) { if (file == null || !file.exists()) { return; } if (file.isDirectory()) { File[] listFiles = file.listFiles(); if (listFiles == null) { return; } for (File file2 : listFiles) { b(file2); } } if (file.delete()) { return; } throw new FileNotFoundException("Failed to delete file: " + file); } public static void c(File file) { Path path; try { if (Build.VERSION.SDK_INT >= 26) { path = file.toPath(); Files.delete(path); } else if (!file.delete()) { Log.e(f8599b, "Cannot delete " + file.getName()); } } catch (IOException e10) { Log.e(f8599b, "Cannot delete " + file.getName(), e10); } } public static boolean d(String str) { if (str != null) { return str.endsWith(".mp4"); } return false; } public static void e(File file) { } public static HashMap f(String str) { Object g10 = g(new File(str)); return g10 instanceof HashMap ? (HashMap) g10 : new HashMap(); } /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Not initialized variable reg: 2, insn: 0x005d: MOVE (r1 I:??[OBJECT, ARRAY]) = (r2 I:??[OBJECT, ARRAY]) (LINE:94), block:B:47:0x005d */ /* JADX WARN: Type inference failed for: r0v0, types: [boolean] */ /* JADX WARN: Type inference failed for: r0v1, types: [java.io.Closeable] */ /* JADX WARN: Type inference failed for: r0v10, types: [java.io.Closeable, java.io.FileInputStream, java.io.InputStream] */ /* JADX WARN: Type inference failed for: r0v2 */ /* JADX WARN: Type inference failed for: r0v3 */ /* JADX WARN: Type inference failed for: r0v4 */ /* JADX WARN: Type inference failed for: r0v5 */ /* JADX WARN: Type inference failed for: r0v6 */ /* JADX WARN: Type inference failed for: r0v7 */ /* JADX WARN: Type inference failed for: r0v9 */ /* JADX WARN: Type inference failed for: r2v11, types: [com.vungle.warren.utility.j$b] */ public static Object g(File file) { Closeable closeable; ObjectInputStream objectInputStream; Closeable closeable2; ?? exists = file.exists(); Closeable closeable3 = null; try { if (exists == 0) { return null; } try { exists = new FileInputStream(file); } catch (IOException e10) { e = e10; exists = 0; objectInputStream = null; } catch (ClassNotFoundException e11) { e = e11; exists = 0; objectInputStream = null; } catch (Exception e12) { e = e12; exists = 0; objectInputStream = null; } catch (Throwable th) { th = th; exists = 0; } try { objectInputStream = f8598a.a(exists); } catch (IOException e13) { e = e13; objectInputStream = null; } catch (ClassNotFoundException e14) { e = e14; objectInputStream = null; } catch (Exception e15) { e = e15; objectInputStream = null; } catch (Throwable th2) { th = th2; a(closeable3); a(exists); throw th; } try { Object readObject = objectInputStream.readObject(); a(objectInputStream); a(exists); return readObject; } catch (IOException e16) { e = e16; Log.e(f8599b, "IOIOException", e); closeable2 = exists; a(objectInputStream); a(closeable2); try { b(file); } catch (IOException unused) { } return null; } catch (ClassNotFoundException e17) { e = e17; Log.e(f8599b, "ClassNotFoundException", e); closeable2 = exists; a(objectInputStream); a(closeable2); b(file); return null; } catch (Exception e18) { e = e18; Log.e(f8599b, "cannot read serializable", e); closeable2 = exists; a(objectInputStream); a(closeable2); b(file); return null; } } catch (Throwable th3) { th = th3; closeable3 = closeable; } } public static long h(File file) { long j10 = 0; if (file == null || !file.exists()) { return 0L; } if (!file.isDirectory()) { return file.length(); } File[] listFiles = file.listFiles(); if (listFiles != null && listFiles.length > 0) { for (File file2 : listFiles) { j10 += h(file2); } } return j10; } public static void i(String str, HashMap hashMap) { File file = new File(str); if (hashMap.isEmpty()) { return; } j(file, hashMap); } public static void j(File file, Serializable serializable) { FileOutputStream fileOutputStream; if (file.exists()) { c(file); } if (serializable == null) { return; } ObjectOutputStream objectOutputStream = null; try { fileOutputStream = new FileOutputStream(file); try { try { ObjectOutputStream objectOutputStream2 = new ObjectOutputStream(fileOutputStream); try { objectOutputStream2.writeObject(serializable); objectOutputStream2.reset(); a(objectOutputStream2); } catch (IOException e10) { e = e10; objectOutputStream = objectOutputStream2; Log.e(f8599b, "IOIOException", e); a(objectOutputStream); a(fileOutputStream); } catch (Throwable th) { th = th; objectOutputStream = objectOutputStream2; a(objectOutputStream); a(fileOutputStream); throw th; } } catch (Throwable th2) { th = th2; } } catch (IOException e11) { e = e11; } } catch (IOException e12) { e = e12; fileOutputStream = null; } catch (Throwable th3) { th = th3; fileOutputStream = null; } a(fileOutputStream); } }