package B0;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import okhttp3.HttpUrl;

/* JADX INFO: loaded from: classes.dex */
public abstract class a {
    private static void a(File file, ZipOutputStream zipOutputStream, String str, String str2) throws Throwable {
        b(file, zipOutputStream, str, str2, false);
    }

    private static void b(File file, ZipOutputStream zipOutputStream, String str, String str2, boolean z2) throws Throwable {
        StringBuilder sb = new StringBuilder();
        sb.append(str);
        sb.append(str.trim().length() == 0 ? HttpUrl.FRAGMENT_ENCODE_SET : File.separator);
        String string = sb.toString();
        if (!z2) {
            string = string + file.getName();
        }
        if (file.isDirectory()) {
            for (File file2 : file.listFiles()) {
                a(file2, zipOutputStream, string, HttpUrl.FRAGMENT_ENCODE_SET);
            }
            return;
        }
        FileInputStream fileInputStream = null;
        try {
            byte[] bArr = new byte[10240];
            FileInputStream fileInputStream2 = new FileInputStream(file);
            try {
                BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream2, 10240);
                zipOutputStream.putNextEntry(new ZipEntry(string));
                zipOutputStream.setComment(str2);
                while (true) {
                    int i2 = bufferedInputStream.read(bArr);
                    if (i2 == -1) {
                        bufferedInputStream.close();
                        zipOutputStream.flush();
                        zipOutputStream.closeEntry();
                        fileInputStream2.close();
                        return;
                    }
                    zipOutputStream.write(bArr, 0, i2);
                }
            } catch (Throwable th) {
                th = th;
                fileInputStream = fileInputStream2;
                if (fileInputStream != null) {
                    fileInputStream.close();
                }
                throw th;
            }
        } catch (Throwable th2) {
            th = th2;
        }
    }

    public static void c(String str, String str2) throws Throwable {
        e(str, str2, false);
    }

    public static void d(String str, String str2, String str3, boolean z2) throws Throwable {
        FileOutputStream fileOutputStream;
        ZipOutputStream zipOutputStream = null;
        try {
            fileOutputStream = new FileOutputStream(str2);
            try {
                ZipOutputStream zipOutputStream2 = new ZipOutputStream(new BufferedOutputStream(fileOutputStream, 10240));
                try {
                    b(new File(str), zipOutputStream2, HttpUrl.FRAGMENT_ENCODE_SET, str3, z2);
                    zipOutputStream2.close();
                    fileOutputStream.close();
                } catch (Throwable th) {
                    th = th;
                    zipOutputStream = zipOutputStream2;
                    if (zipOutputStream != null) {
                        zipOutputStream.close();
                    }
                    if (fileOutputStream != null) {
                        fileOutputStream.close();
                    }
                    throw th;
                }
            } catch (Throwable th2) {
                th = th2;
            }
        } catch (Throwable th3) {
            th = th3;
            fileOutputStream = null;
        }
    }

    public static void e(String str, String str2, boolean z2) throws Throwable {
        d(str, str2, HttpUrl.FRAGMENT_ENCODE_SET, z2);
    }
}
