package w1;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import kotlin.jvm.internal.l;

/* JADX INFO: Access modifiers changed from: package-private */
/* JADX INFO: loaded from: classes.dex */
public abstract class j extends i {
    public static final File a(File file, File target, boolean z2, int i2) throws IOException {
        l.e(file, "<this>");
        l.e(target, "target");
        if (!file.exists()) {
            throw new k(file, null, "The source file doesn't exist.", 2, null);
        }
        if (target.exists()) {
            if (!z2) {
                throw new d(file, target, "The destination file already exists.");
            }
            if (!target.delete()) {
                throw new d(file, target, "Tried to overwrite the destination, but failed to delete it.");
            }
        }
        if (!file.isDirectory()) {
            File parentFile = target.getParentFile();
            if (parentFile != null) {
                parentFile.mkdirs();
            }
            FileInputStream fileInputStream = new FileInputStream(file);
            try {
                FileOutputStream fileOutputStream = new FileOutputStream(target);
                try {
                    a.a(fileInputStream, fileOutputStream, i2);
                    b.a(fileOutputStream, null);
                    b.a(fileInputStream, null);
                } finally {
                }
            } finally {
            }
        } else if (!target.mkdirs()) {
            throw new e(file, target, "Failed to create target directory.");
        }
        return target;
    }

    public static /* synthetic */ File b(File file, File file2, boolean z2, int i2, int i3, Object obj) {
        if ((i3 & 2) != 0) {
            z2 = false;
        }
        if ((i3 & 4) != 0) {
            i2 = 8192;
        }
        return a(file, file2, z2, i2);
    }
}
