package o; import java.io.File; import java.io.FileFilter; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.math.BigInteger; import java.nio.channels.FileChannel; import java.nio.charset.Charset; import java.nio.file.Files; import java.util.Collection; import java.util.LinkedList; import okhttp3.internal.ws.RealWebSocket; /* renamed from: o.gjl, reason: case insensitive filesystem */ /* loaded from: classes6.dex */ public final class C15191gjl { static { BigInteger valueOf = BigInteger.valueOf(RealWebSocket.DEFAULT_MINIMUM_DEFLATE_SIZE); valueOf.multiply(valueOf.multiply(valueOf.multiply(valueOf.multiply(valueOf.multiply(valueOf))))); valueOf.multiply(BigInteger.valueOf(RealWebSocket.DEFAULT_MINIMUM_DEFLATE_SIZE).multiply(BigInteger.valueOf(1152921504606846976L))); } private static void b(Collection collection, File file, InterfaceC15199gjt interfaceC15199gjt, boolean z) { File[] listFiles = file.listFiles((FileFilter) interfaceC15199gjt); if (listFiles != null) { for (File file2 : listFiles) { if (file2.isDirectory()) { if (z) { collection.add(file2); } b(collection, file2, interfaceC15199gjt, z); } else { collection.add(file2); } } } } private static long b(File file) { long length; File[] listFiles = file.listFiles(); if (listFiles == null) { return 0L; } long j = 0; for (File file2 : listFiles) { if (file2 == null) { throw new NullPointerException("File must not be null"); break; } try { if (!Files.isSymbolicLink(file2.toPath())) { if (file2.isDirectory()) { length = b(file2); } else { length = file2.length(); } j += length; if (j < 0) { break; } } else { continue; } } catch (IOException unused) { continue; } continue; } return j; } public static void a(File file) throws IOException { if (!file.exists()) { StringBuilder sb = new StringBuilder(); sb.append(file); sb.append(" does not exist"); throw new IllegalArgumentException(sb.toString()); } if (!file.isDirectory()) { StringBuilder sb2 = new StringBuilder(); sb2.append(file); sb2.append(" is not a directory"); throw new IllegalArgumentException(sb2.toString()); } File[] listFiles = file.listFiles(); if (listFiles != null) { IOException e = null; for (File file2 : listFiles) { try { if (!file2.isDirectory()) { boolean exists = file2.exists(); if (!file2.delete()) { if (!exists) { throw new FileNotFoundException("File does not exist: ".concat(String.valueOf(file2))); } throw new IOException("Unable to delete file: ".concat(String.valueOf(file2))); } } else if (!file2.exists()) { continue; } else { if (file2 == null) { throw new NullPointerException("File must not be null"); } if (!Files.isSymbolicLink(file2.toPath())) { a(file2); } if (!file2.delete()) { StringBuilder sb3 = new StringBuilder("Unable to delete directory "); sb3.append(file2); sb3.append("."); throw new IOException(sb3.toString()); } } } catch (IOException e2) { e = e2; } } if (e != null) { throw e; } return; } throw new IOException("Failed to list contents of ".concat(String.valueOf(file))); } public static void b(File file, File file2) throws IOException { if (file == null) { throw new NullPointerException("Source must not be null"); } if (file2 == null) { throw new NullPointerException("Destination must not be null"); } if (!file.exists()) { StringBuilder sb = new StringBuilder("Source '"); sb.append(file); sb.append("' does not exist"); throw new FileNotFoundException(sb.toString()); } if (file.isDirectory()) { StringBuilder sb2 = new StringBuilder("Source '"); sb2.append(file); sb2.append("' exists but is a directory"); throw new IOException(sb2.toString()); } if (file.getCanonicalPath().equals(file2.getCanonicalPath())) { StringBuilder sb3 = new StringBuilder("Source '"); sb3.append(file); sb3.append("' and destination '"); sb3.append(file2); sb3.append("' are the same"); throw new IOException(sb3.toString()); } File parentFile = file2.getParentFile(); if (parentFile != null && !parentFile.mkdirs() && !parentFile.isDirectory()) { StringBuilder sb4 = new StringBuilder("Destination '"); sb4.append(parentFile); sb4.append("' directory cannot be created"); throw new IOException(sb4.toString()); } if (file2.exists() && !file2.canWrite()) { StringBuilder sb5 = new StringBuilder("Destination '"); sb5.append(file2); sb5.append("' exists but is read-only"); throw new IOException(sb5.toString()); } if (file2.exists() && file2.isDirectory()) { StringBuilder sb6 = new StringBuilder("Destination '"); sb6.append(file2); sb6.append("' exists but is a directory"); throw new IOException(sb6.toString()); } FileInputStream fileInputStream = new FileInputStream(file); try { FileChannel channel = fileInputStream.getChannel(); try { FileOutputStream fileOutputStream = new FileOutputStream(file2); try { FileChannel channel2 = fileOutputStream.getChannel(); try { long size = channel.size(); long j = 0; while (j < size) { long j2 = size - j; long transferFrom = channel2.transferFrom(channel, j, j2 > 31457280 ? 31457280L : j2); if (transferFrom == 0) { break; } else { j += transferFrom; } } if (channel2 != null) { channel2.close(); } fileOutputStream.close(); if (channel != null) { channel.close(); } fileInputStream.close(); long length = file.length(); long length2 = file2.length(); if (length == length2) { file2.setLastModified(file.lastModified()); return; } StringBuilder sb7 = new StringBuilder("Failed to copy full contents from '"); sb7.append(file); sb7.append("' to '"); sb7.append(file2); sb7.append("' Expected length: "); sb7.append(length); sb7.append(" Actual: "); sb7.append(length2); throw new IOException(sb7.toString()); } finally { } } finally { } } finally { } } finally { } } public static Collection d(File file, InterfaceC15199gjt interfaceC15199gjt, InterfaceC15199gjt interfaceC15199gjt2) { if (!file.isDirectory()) { throw new IllegalArgumentException("Parameter 'directory' is not a directory: ".concat(String.valueOf(file))); } if (interfaceC15199gjt == null) { throw new NullPointerException("Parameter 'fileFilter' is null"); } InterfaceC15199gjt e = C15204gjy.e(interfaceC15199gjt, C15204gjy.e(C15193gjn.a)); InterfaceC15199gjt e2 = interfaceC15199gjt2 == null ? C15201gjv.d : C15204gjy.e(interfaceC15199gjt2, C15193gjn.a); LinkedList linkedList = new LinkedList(); if (file.isDirectory()) { linkedList.add(file); } b(linkedList, file, C15204gjy.a(e, e2), true); return linkedList; } public static String b(File file, String str) throws IOException { return b(file, Charset.forName(str)); } private static String b(File file, Charset charset) throws IOException { if (file.exists()) { if (file.isDirectory()) { StringBuilder sb = new StringBuilder("File '"); sb.append(file); sb.append("' exists but is a directory"); throw new IOException(sb.toString()); } if (!file.canRead()) { StringBuilder sb2 = new StringBuilder("File '"); sb2.append(file); sb2.append("' cannot be read"); throw new IOException(sb2.toString()); } FileInputStream fileInputStream = new FileInputStream(file); if (charset == null) { try { charset = Charset.defaultCharset(); } finally { } } String d = C15195gjp.d(fileInputStream, charset); fileInputStream.close(); return d; } StringBuilder sb3 = new StringBuilder("File '"); sb3.append(file); sb3.append("' does not exist"); throw new FileNotFoundException(sb3.toString()); } public static long c(File file) { if (!file.exists()) { StringBuilder sb = new StringBuilder(); sb.append(file); sb.append(" does not exist"); throw new IllegalArgumentException(sb.toString()); } if (file.isDirectory()) { return b(file); } StringBuilder sb2 = new StringBuilder(); sb2.append(file); sb2.append(" is not a directory"); throw new IllegalArgumentException(sb2.toString()); } public static void d(File file, byte[] bArr) throws IOException { int length = bArr.length; if (file.exists()) { if (file.isDirectory()) { StringBuilder sb = new StringBuilder("File '"); sb.append(file); sb.append("' exists but is a directory"); throw new IOException(sb.toString()); } if (!file.canWrite()) { StringBuilder sb2 = new StringBuilder("File '"); sb2.append(file); sb2.append("' cannot be written to"); throw new IOException(sb2.toString()); } } else { File parentFile = file.getParentFile(); if (parentFile != null && !parentFile.mkdirs() && !parentFile.isDirectory()) { StringBuilder sb3 = new StringBuilder("Directory '"); sb3.append(parentFile); sb3.append("' could not be created"); throw new IOException(sb3.toString()); } } FileOutputStream fileOutputStream = new FileOutputStream(file, false); try { fileOutputStream.write(bArr, 0, length); fileOutputStream.close(); } finally { } } }