501 lines
20 KiB
Java
501 lines
20 KiB
Java
package com.ubtech.utils;
|
|
|
|
import android.content.Context;
|
|
import android.text.TextUtils;
|
|
import android.util.Log;
|
|
import com.ijm.dataencryption.de.DataDecryptTool;
|
|
import java.io.BufferedReader;
|
|
import java.io.BufferedWriter;
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.Closeable;
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStreamReader;
|
|
import java.io.OutputStreamWriter;
|
|
import java.util.zip.ZipEntry;
|
|
import java.util.zip.ZipInputStream;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class FileHelper {
|
|
public static final String a = "FileHelper";
|
|
|
|
public static void a(Context context, String str, String str2, boolean z) throws IOException {
|
|
a(context.getAssets().open(str), str2, z);
|
|
}
|
|
|
|
public static boolean b(File file, File file2) {
|
|
boolean z = false;
|
|
if (file != null && file.exists() && file.isFile() && file2 != null) {
|
|
try {
|
|
FileInputStream fileInputStream = new FileInputStream(file);
|
|
try {
|
|
FileOutputStream fileOutputStream = new FileOutputStream(file2);
|
|
try {
|
|
byte[] bArr = new byte[DataDecryptTool.DECRYPT_SP_FILE];
|
|
while (true) {
|
|
int read = fileInputStream.read(bArr);
|
|
if (read == -1) {
|
|
break;
|
|
}
|
|
fileOutputStream.write(bArr, 0, read);
|
|
}
|
|
fileOutputStream.flush();
|
|
z = true;
|
|
fileOutputStream.close();
|
|
fileInputStream.close();
|
|
} finally {
|
|
}
|
|
} finally {
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
return z;
|
|
}
|
|
|
|
public static boolean c(String str, String str2) {
|
|
File file = new File(str);
|
|
if (!file.exists() || TextUtils.isEmpty(str2)) {
|
|
return false;
|
|
}
|
|
return file.renameTo(new File(str2));
|
|
}
|
|
|
|
public static void a(String str, String str2, boolean z) throws IOException {
|
|
File file = new File(str);
|
|
if (file.exists()) {
|
|
a(new FileInputStream(file), str2, z);
|
|
}
|
|
}
|
|
|
|
public static void a(InputStream inputStream, String str, boolean z) throws IOException {
|
|
File file = new File(str);
|
|
if (!file.exists()) {
|
|
file.mkdirs();
|
|
}
|
|
ZipInputStream zipInputStream = new ZipInputStream(inputStream);
|
|
try {
|
|
try {
|
|
byte[] bArr = new byte[1048576];
|
|
for (ZipEntry nextEntry = zipInputStream.getNextEntry(); nextEntry != null; nextEntry = zipInputStream.getNextEntry()) {
|
|
String replace = nextEntry.getName().replace("\\", File.separator);
|
|
if (nextEntry.isDirectory()) {
|
|
File file2 = new File(str + File.separator + replace);
|
|
if (z || !file2.exists()) {
|
|
file2.mkdirs();
|
|
}
|
|
} else {
|
|
File file3 = new File(str + File.separator + replace);
|
|
if (!file3.getParentFile().exists()) {
|
|
file3.getParentFile().mkdirs();
|
|
}
|
|
if (z || !file3.exists()) {
|
|
if (file3.getParentFile().exists() && !file3.getParentFile().isDirectory()) {
|
|
file3.getParentFile().mkdirs();
|
|
}
|
|
if (replace.endsWith(File.separator)) {
|
|
file3.mkdirs();
|
|
} else {
|
|
file3.createNewFile();
|
|
FileOutputStream fileOutputStream = new FileOutputStream(file3);
|
|
while (true) {
|
|
try {
|
|
int read = zipInputStream.read(bArr);
|
|
if (read <= 0) {
|
|
break;
|
|
} else {
|
|
fileOutputStream.write(bArr, 0, read);
|
|
}
|
|
} catch (Throwable th) {
|
|
try {
|
|
throw th;
|
|
} catch (Throwable th2) {
|
|
try {
|
|
fileOutputStream.close();
|
|
} catch (Throwable th3) {
|
|
th.addSuppressed(th3);
|
|
}
|
|
throw th2;
|
|
}
|
|
}
|
|
}
|
|
fileOutputStream.close();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
try {
|
|
zipInputStream.close();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
} catch (IOException e2) {
|
|
e2.printStackTrace();
|
|
throw e2;
|
|
}
|
|
} catch (Throwable th4) {
|
|
try {
|
|
zipInputStream.close();
|
|
} catch (IOException e3) {
|
|
e3.printStackTrace();
|
|
}
|
|
throw th4;
|
|
}
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
/* JADX WARN: Type inference failed for: r1v0, types: [java.io.File] */
|
|
/* JADX WARN: Type inference failed for: r1v1 */
|
|
/* JADX WARN: Type inference failed for: r1v10 */
|
|
/* JADX WARN: Type inference failed for: r1v11 */
|
|
/* JADX WARN: Type inference failed for: r1v12, types: [java.io.InputStreamReader, java.io.Reader] */
|
|
/* JADX WARN: Type inference failed for: r1v2 */
|
|
/* JADX WARN: Type inference failed for: r1v3 */
|
|
/* JADX WARN: Type inference failed for: r1v4, types: [java.io.Closeable] */
|
|
/* JADX WARN: Type inference failed for: r1v5 */
|
|
/* JADX WARN: Type inference failed for: r1v7 */
|
|
/* JADX WARN: Type inference failed for: r1v9 */
|
|
public static String b(String str, String str2) {
|
|
FileInputStream fileInputStream;
|
|
Closeable closeable;
|
|
Closeable closeable2;
|
|
?? file = new File(str);
|
|
String str3 = "";
|
|
if (file.exists() && !file.isDirectory()) {
|
|
if (str2 == null || "".equals(str2)) {
|
|
str2 = "UTF-8";
|
|
}
|
|
BufferedReader bufferedReader = null;
|
|
try {
|
|
try {
|
|
fileInputStream = new FileInputStream((File) file);
|
|
try {
|
|
file = new InputStreamReader(fileInputStream, str2);
|
|
try {
|
|
BufferedReader bufferedReader2 = new BufferedReader(file);
|
|
try {
|
|
StringBuilder sb = new StringBuilder();
|
|
while (true) {
|
|
String readLine = bufferedReader2.readLine();
|
|
if (readLine == null) {
|
|
break;
|
|
}
|
|
sb.append(readLine);
|
|
}
|
|
str3 = sb.toString();
|
|
a(bufferedReader2);
|
|
closeable2 = file;
|
|
} catch (FileNotFoundException e) {
|
|
e = e;
|
|
bufferedReader = bufferedReader2;
|
|
e.printStackTrace();
|
|
Log.i(a, e.getMessage());
|
|
closeable = file;
|
|
a(bufferedReader);
|
|
closeable2 = closeable;
|
|
a(closeable2);
|
|
a(fileInputStream);
|
|
return str3;
|
|
} catch (IOException e2) {
|
|
e = e2;
|
|
bufferedReader = bufferedReader2;
|
|
e.printStackTrace();
|
|
Log.i(a, e.getMessage());
|
|
closeable = file;
|
|
a(bufferedReader);
|
|
closeable2 = closeable;
|
|
a(closeable2);
|
|
a(fileInputStream);
|
|
return str3;
|
|
} catch (Throwable th) {
|
|
th = th;
|
|
bufferedReader = bufferedReader2;
|
|
a(bufferedReader);
|
|
a((Closeable) file);
|
|
a(fileInputStream);
|
|
throw th;
|
|
}
|
|
} catch (FileNotFoundException e3) {
|
|
e = e3;
|
|
} catch (IOException e4) {
|
|
e = e4;
|
|
}
|
|
} catch (FileNotFoundException e5) {
|
|
e = e5;
|
|
file = 0;
|
|
} catch (IOException e6) {
|
|
e = e6;
|
|
file = 0;
|
|
} catch (Throwable th2) {
|
|
th = th2;
|
|
file = 0;
|
|
}
|
|
} catch (FileNotFoundException e7) {
|
|
e = e7;
|
|
file = 0;
|
|
fileInputStream = null;
|
|
} catch (IOException e8) {
|
|
e = e8;
|
|
file = 0;
|
|
fileInputStream = null;
|
|
} catch (Throwable th3) {
|
|
th = th3;
|
|
file = 0;
|
|
fileInputStream = null;
|
|
}
|
|
a(closeable2);
|
|
a(fileInputStream);
|
|
} catch (Throwable th4) {
|
|
th = th4;
|
|
}
|
|
}
|
|
return str3;
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
/* JADX WARN: Not initialized variable reg: 2, insn: 0x004e: MOVE (r0 I:??[OBJECT, ARRAY]) = (r2 I:??[OBJECT, ARRAY]), block:B:41:0x004e */
|
|
/* JADX WARN: Type inference failed for: r1v1, types: [boolean] */
|
|
/* JADX WARN: Type inference failed for: r1v2, types: [java.io.Closeable] */
|
|
/* JADX WARN: Type inference failed for: r1v3 */
|
|
/* JADX WARN: Type inference failed for: r1v4 */
|
|
/* JADX WARN: Type inference failed for: r1v5 */
|
|
/* JADX WARN: Type inference failed for: r1v6 */
|
|
/* JADX WARN: Type inference failed for: r1v7 */
|
|
/* JADX WARN: Type inference failed for: r1v9, types: [java.io.FileInputStream] */
|
|
public static byte[] b(File file) {
|
|
Closeable closeable;
|
|
ByteArrayOutputStream byteArrayOutputStream;
|
|
Closeable closeable2;
|
|
Closeable closeable3 = null;
|
|
r0 = null;
|
|
byte[] bArr = null;
|
|
closeable3 = null;
|
|
if (file != null) {
|
|
?? isFile = file.isFile();
|
|
try {
|
|
if (isFile != 0) {
|
|
try {
|
|
isFile = new FileInputStream(file);
|
|
} catch (IOException e) {
|
|
e = e;
|
|
isFile = 0;
|
|
byteArrayOutputStream = null;
|
|
} catch (Exception e2) {
|
|
e = e2;
|
|
isFile = 0;
|
|
byteArrayOutputStream = null;
|
|
} catch (Throwable th) {
|
|
th = th;
|
|
isFile = 0;
|
|
}
|
|
try {
|
|
byte[] bArr2 = new byte[DataDecryptTool.DECRYPT_SP_FILE];
|
|
byteArrayOutputStream = new ByteArrayOutputStream();
|
|
while (true) {
|
|
try {
|
|
int read = isFile.read(bArr2);
|
|
if (read == -1) {
|
|
break;
|
|
}
|
|
byteArrayOutputStream.write(bArr2, 0, read);
|
|
} catch (IOException e3) {
|
|
e = e3;
|
|
e.printStackTrace();
|
|
closeable2 = isFile;
|
|
a(closeable2);
|
|
a(byteArrayOutputStream);
|
|
return bArr;
|
|
} catch (Exception e4) {
|
|
e = e4;
|
|
e.printStackTrace();
|
|
closeable2 = isFile;
|
|
a(closeable2);
|
|
a(byteArrayOutputStream);
|
|
return bArr;
|
|
}
|
|
}
|
|
bArr = byteArrayOutputStream.toByteArray();
|
|
closeable2 = isFile;
|
|
} catch (IOException e5) {
|
|
e = e5;
|
|
byteArrayOutputStream = null;
|
|
} catch (Exception e6) {
|
|
e = e6;
|
|
byteArrayOutputStream = null;
|
|
} catch (Throwable th2) {
|
|
th = th2;
|
|
a((Closeable) isFile);
|
|
a(closeable3);
|
|
throw th;
|
|
}
|
|
a(closeable2);
|
|
a(byteArrayOutputStream);
|
|
return bArr;
|
|
}
|
|
} catch (Throwable th3) {
|
|
th = th3;
|
|
closeable3 = closeable;
|
|
}
|
|
}
|
|
Log.e(a, "FileHelper#readFileToByteArray: file not exist");
|
|
return null;
|
|
}
|
|
|
|
public static void a(Closeable closeable) {
|
|
if (closeable != null) {
|
|
try {
|
|
closeable.close();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void a(File file) {
|
|
if (file == null) {
|
|
return;
|
|
}
|
|
if (file.isFile()) {
|
|
file.delete();
|
|
return;
|
|
}
|
|
if (file.isDirectory()) {
|
|
File[] listFiles = file.listFiles();
|
|
if (listFiles != null && listFiles.length != 0) {
|
|
for (File file2 : listFiles) {
|
|
a(file2);
|
|
}
|
|
file.delete();
|
|
return;
|
|
}
|
|
file.delete();
|
|
}
|
|
}
|
|
|
|
public static boolean a(String str, String str2, String str3) {
|
|
FileOutputStream fileOutputStream;
|
|
OutputStreamWriter outputStreamWriter;
|
|
BufferedWriter bufferedWriter = null;
|
|
try {
|
|
if (TextUtils.isEmpty(str3)) {
|
|
str3 = "UTF-8";
|
|
}
|
|
File file = new File(str);
|
|
if (!file.getParentFile().exists()) {
|
|
file.getParentFile().mkdirs();
|
|
}
|
|
if (!file.exists()) {
|
|
file.createNewFile();
|
|
}
|
|
FileOutputStream fileOutputStream2 = new FileOutputStream(file);
|
|
try {
|
|
outputStreamWriter = new OutputStreamWriter(fileOutputStream2, str3);
|
|
try {
|
|
BufferedWriter bufferedWriter2 = new BufferedWriter(outputStreamWriter);
|
|
try {
|
|
bufferedWriter2.write(str2);
|
|
bufferedWriter2.flush();
|
|
a(bufferedWriter2);
|
|
a(outputStreamWriter);
|
|
a(fileOutputStream2);
|
|
return true;
|
|
} catch (Exception e) {
|
|
e = e;
|
|
bufferedWriter = bufferedWriter2;
|
|
Exception exc = e;
|
|
fileOutputStream = fileOutputStream2;
|
|
e = exc;
|
|
try {
|
|
e.printStackTrace();
|
|
Log.i(a, e.getMessage());
|
|
a(bufferedWriter);
|
|
a(outputStreamWriter);
|
|
a(fileOutputStream);
|
|
return false;
|
|
} catch (Throwable th) {
|
|
th = th;
|
|
a(bufferedWriter);
|
|
a(outputStreamWriter);
|
|
a(fileOutputStream);
|
|
throw th;
|
|
}
|
|
} catch (Throwable th2) {
|
|
th = th2;
|
|
bufferedWriter = bufferedWriter2;
|
|
Throwable th3 = th;
|
|
fileOutputStream = fileOutputStream2;
|
|
th = th3;
|
|
a(bufferedWriter);
|
|
a(outputStreamWriter);
|
|
a(fileOutputStream);
|
|
throw th;
|
|
}
|
|
} catch (Exception e2) {
|
|
e = e2;
|
|
} catch (Throwable th4) {
|
|
th = th4;
|
|
}
|
|
} catch (Exception e3) {
|
|
e = e3;
|
|
outputStreamWriter = null;
|
|
} catch (Throwable th5) {
|
|
th = th5;
|
|
outputStreamWriter = null;
|
|
}
|
|
} catch (Exception e4) {
|
|
e = e4;
|
|
fileOutputStream = null;
|
|
outputStreamWriter = null;
|
|
} catch (Throwable th6) {
|
|
th = th6;
|
|
fileOutputStream = null;
|
|
outputStreamWriter = null;
|
|
}
|
|
}
|
|
|
|
public static void a(File file, File file2) throws Exception {
|
|
if (file == null || !file.exists()) {
|
|
return;
|
|
}
|
|
if (file.isFile()) {
|
|
b(file, file2);
|
|
return;
|
|
}
|
|
if (!file2.exists()) {
|
|
file2.mkdirs();
|
|
}
|
|
File[] listFiles = file.listFiles();
|
|
if (listFiles == null || listFiles.length == 0) {
|
|
return;
|
|
}
|
|
for (int i = 0; i < listFiles.length; i++) {
|
|
if (listFiles[i].isFile()) {
|
|
b(listFiles[i], new File(file2.getAbsolutePath() + File.separator + listFiles[i].getName()));
|
|
}
|
|
if (listFiles[i].isDirectory()) {
|
|
a(new File(file.getAbsolutePath() + File.separator + listFiles[i].getName()), new File(file2.getAbsolutePath() + File.separator + listFiles[i].getName()));
|
|
}
|
|
}
|
|
}
|
|
|
|
public static String a(String str) {
|
|
if (TextUtils.isEmpty(str)) {
|
|
return "";
|
|
}
|
|
int lastIndexOf = str.lastIndexOf(File.separator);
|
|
return lastIndexOf == -1 ? str : str.substring(lastIndexOf + 1);
|
|
}
|
|
|
|
public static boolean a(String str, String str2) {
|
|
if (TextUtils.isEmpty(str2) || TextUtils.isEmpty(str) || !new File(str2).exists()) {
|
|
return false;
|
|
}
|
|
return EncryptUtils.a(new File(str2)).toLowerCase().equals(str.toLowerCase());
|
|
}
|
|
}
|