package com.vungle.warren.utility; import android.text.TextUtils; import android.util.Log; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; /* loaded from: classes2.dex */ public abstract class x { /* renamed from: a, reason: collision with root package name */ private static final String f8638a = "com.vungle.warren.utility.x"; public interface a { boolean a(String str); } static class b extends IOException { b(String str) { super(str); } } static void a(InputStream inputStream, String str) { FileOutputStream fileOutputStream; BufferedOutputStream bufferedOutputStream; File file = new File(str); j.b(file); File parentFile = file.getParentFile(); if (parentFile != null && !parentFile.exists()) { parentFile.mkdirs(); } BufferedOutputStream bufferedOutputStream2 = null; try { fileOutputStream = new FileOutputStream(str); try { bufferedOutputStream = new BufferedOutputStream(fileOutputStream); } catch (Throwable th) { th = th; } try { byte[] bArr = new byte[4096]; while (true) { int read = inputStream.read(bArr); if (read == -1) { j.a(inputStream); j.a(bufferedOutputStream); j.a(fileOutputStream); return; } bufferedOutputStream.write(bArr, 0, read); } } catch (Throwable th2) { th = th2; bufferedOutputStream2 = bufferedOutputStream; j.a(inputStream); j.a(bufferedOutputStream2); j.a(fileOutputStream); throw th; } } catch (Throwable th3) { th = th3; fileOutputStream = null; } } public static List b(String str, String str2, a aVar) { ZipFile zipFile; if (TextUtils.isEmpty(str)) { throw new IOException("Path is empty"); } File file = new File(str); if (!file.exists()) { throw new IOException("File does not exist"); } File file2 = new File(str2); if (!file2.exists()) { file2.mkdir(); } ArrayList arrayList = new ArrayList(); ZipFile zipFile2 = null; try { zipFile = new ZipFile(file); } catch (Throwable th) { th = th; } try { Enumeration entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry nextElement = entries.nextElement(); String str3 = str2 + File.separator + nextElement.getName(); if (aVar == null || aVar.a(str3)) { c(str3, str2); if (nextElement.isDirectory()) { File file3 = new File(str3); if (!file3.exists()) { file3.mkdir(); } } else { a(zipFile.getInputStream(nextElement), str3); arrayList.add(new File(str3)); } } } try { zipFile.close(); } catch (IOException unused) { } return arrayList; } catch (Throwable th2) { th = th2; zipFile2 = zipFile; if (zipFile2 != null) { try { zipFile2.close(); } catch (IOException unused2) { } } throw th; } } private static String c(String str, String str2) { String canonicalPath = new File(str).getCanonicalPath(); if (canonicalPath.startsWith(new File(str2).getCanonicalPath())) { return canonicalPath; } Log.e(f8638a, "File is outside extraction target directory."); throw new b("File is outside extraction target directory."); } }