package com.ubt.jimu.base.util; import android.text.TextUtils; import com.ubtrobot.log.ALog; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.nio.channels.FileChannel; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; /* loaded from: classes.dex */ public class FileUtil { public static final int ZIP_BUFFER_SIZE = 4096; public static void copy(File file, File file2) { try { FileInputStream fileInputStream = new FileInputStream(file); try { FileChannel channel = fileInputStream.getChannel(); try { FileOutputStream fileOutputStream = new FileOutputStream(file2); try { FileChannel channel2 = fileOutputStream.getChannel(); try { channel2.transferFrom(channel, 0L, channel.size()); if (channel2 != null) { channel2.close(); } fileOutputStream.close(); if (channel != null) { channel.close(); } fileInputStream.close(); } finally { } } finally { } } finally { } } finally { } } catch (IOException e) { e.printStackTrace(); } } public static boolean deleteFile(File file) { if (file != null) { if (file.isFile()) { if (file.delete()) { return true; } file.deleteOnExit(); return false; } if (file.isDirectory()) { File[] listFiles = file.listFiles(); if (listFiles != null) { for (File file2 : listFiles) { deleteFile(file2); } } return file.delete(); } } return false; } public static void doZip(ZipOutputStream zipOutputStream, File file, String str, byte[] bArr) throws IOException { BufferedInputStream bufferedInputStream; if (zipOutputStream == null || file == null) { throw new IOException("I/O Object got NullPointerException"); } if (!file.exists()) { return; } String name = TextUtils.isEmpty(str) ? file.getName() : str + File.separator + file.getName(); if (!file.isFile()) { if (file.isDirectory()) { for (File file2 : file.listFiles()) { doZip(zipOutputStream, file2, name, bArr); } return; } return; } try { bufferedInputStream = new BufferedInputStream(new FileInputStream(file)); try { zipOutputStream.putNextEntry(new ZipEntry(name)); while (true) { int read = bufferedInputStream.read(bArr, 0, bArr.length); if (-1 == read) { Closer.close(bufferedInputStream); return; } zipOutputStream.write(bArr, 0, read); } } catch (IOException e) { e = e; Closer.close(bufferedInputStream); throw e; } } catch (IOException e2) { e = e2; bufferedInputStream = null; } } public static boolean zip(File[] fileArr, File file) { boolean z = false; if (fileArr == null || fileArr.length < 1 || file == null) { return false; } ZipOutputStream zipOutputStream = null; try { try { byte[] bArr = new byte[ZIP_BUFFER_SIZE]; ZipOutputStream zipOutputStream2 = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(file, false))); try { for (File file2 : fileArr) { doZip(zipOutputStream2, file2, null, bArr); } zipOutputStream2.flush(); zipOutputStream2.closeEntry(); Closer.close(zipOutputStream2); z = true; } catch (IOException e) { e = e; zipOutputStream = zipOutputStream2; ALog.a("Exception").d("printStackTrace()--->", e); Closer.close(zipOutputStream); return z; } catch (Throwable th) { th = th; zipOutputStream = zipOutputStream2; Closer.close(zipOutputStream); throw th; } } catch (IOException e2) { e = e2; } return z; } catch (Throwable th2) { th = th2; } } }