- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
138 lines
4.0 KiB
Java
138 lines
4.0 KiB
Java
package com.mbridge.msdk.foundation.tools;
|
|
|
|
import com.applovin.exoplayer2.common.base.Ascii;
|
|
import java.io.Closeable;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.RandomAccessFile;
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.Method;
|
|
import java.security.SecureRandom;
|
|
|
|
/* loaded from: classes4.dex */
|
|
final class ar {
|
|
|
|
public static class a {
|
|
static final char[] a = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
|
static final SecureRandom b = new SecureRandom();
|
|
}
|
|
|
|
public static void a(File file) {
|
|
try {
|
|
if (file.exists()) {
|
|
d(file);
|
|
}
|
|
} catch (Exception unused) {
|
|
}
|
|
}
|
|
|
|
private static void d(File file) {
|
|
File[] listFiles;
|
|
if (file.isDirectory() && (listFiles = file.listFiles()) != null) {
|
|
for (File file2 : listFiles) {
|
|
d(file2);
|
|
}
|
|
}
|
|
file.delete();
|
|
}
|
|
|
|
public static byte[] b(File file) throws IOException {
|
|
if (!file.isFile()) {
|
|
return null;
|
|
}
|
|
long length = file.length();
|
|
if ((length >> 32) != 0) {
|
|
throw new IllegalArgumentException("file too large, path:" + file.getPath());
|
|
}
|
|
int i = (int) length;
|
|
byte[] bArr = new byte[i];
|
|
a(file, bArr, i);
|
|
return bArr;
|
|
}
|
|
|
|
public static void a(File file, byte[] bArr, int i) throws IOException {
|
|
RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
|
|
int i2 = 0;
|
|
while (i2 < i) {
|
|
try {
|
|
int read = randomAccessFile.read(bArr, i2, i - i2);
|
|
if (read < 0) {
|
|
break;
|
|
} else {
|
|
i2 += read;
|
|
}
|
|
} finally {
|
|
a(randomAccessFile);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void a(Closeable closeable) {
|
|
if (closeable != null) {
|
|
try {
|
|
closeable.close();
|
|
} catch (Exception unused) {
|
|
}
|
|
}
|
|
}
|
|
|
|
public static int a() {
|
|
try {
|
|
Class<?> cls = Class.forName("sun.misc.Unsafe");
|
|
Field declaredField = cls.getDeclaredField("theUnsafe");
|
|
declaredField.setAccessible(true);
|
|
Method declaredMethod = cls.getDeclaredMethod("pageSize", new Class[0]);
|
|
declaredMethod.setAccessible(true);
|
|
return ((Integer) declaredMethod.invoke(declaredField.get(null), new Object[0])).intValue();
|
|
} catch (Throwable unused) {
|
|
return 4096;
|
|
}
|
|
}
|
|
|
|
public static String b() {
|
|
byte[] bArr = new byte[16];
|
|
a.b.nextBytes(bArr);
|
|
char[] cArr = new char[32];
|
|
for (int i = 0; i < 16; i++) {
|
|
byte b = bArr[i];
|
|
int i2 = i << 1;
|
|
char[] cArr2 = a.a;
|
|
cArr[i2] = cArr2[(b >> 4) & 15];
|
|
cArr[i2 + 1] = cArr2[b & Ascii.SI];
|
|
}
|
|
return new String(cArr);
|
|
}
|
|
|
|
public static boolean a(File file, byte[] bArr) {
|
|
File file2;
|
|
try {
|
|
file2 = new File(file.getParent(), file.getName() + ".tmp");
|
|
} catch (Exception unused) {
|
|
}
|
|
if (!c(file2)) {
|
|
return false;
|
|
}
|
|
RandomAccessFile randomAccessFile = new RandomAccessFile(file2, "rw");
|
|
try {
|
|
randomAccessFile.setLength(bArr.length);
|
|
randomAccessFile.write(bArr);
|
|
a(randomAccessFile);
|
|
if (!file.exists() || file.delete()) {
|
|
return file2.renameTo(file);
|
|
}
|
|
return false;
|
|
} catch (Throwable th) {
|
|
a(randomAccessFile);
|
|
throw th;
|
|
}
|
|
}
|
|
|
|
public static boolean c(File file) throws IOException {
|
|
if (file.isFile()) {
|
|
return true;
|
|
}
|
|
File parentFile = file.getParentFile();
|
|
return parentFile != null && (parentFile.isDirectory() || parentFile.mkdirs()) && file.createNewFile();
|
|
}
|
|
}
|