340 lines
12 KiB
Java
340 lines
12 KiB
Java
package com.baidu.uaq.agent.android.util;
|
|
|
|
import android.content.Context;
|
|
import com.baidu.uaq.agent.android.customtransmission.APMUploadConfigure;
|
|
import com.baidu.uaq.agent.android.logging.a;
|
|
import java.io.DataInputStream;
|
|
import java.io.DataOutputStream;
|
|
import java.io.EOFException;
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
|
|
/* compiled from: MultiLogPersistentUtil.java */
|
|
/* loaded from: classes.dex */
|
|
public class f {
|
|
private static final a d = com.baidu.uaq.agent.android.logging.b.a();
|
|
private static String e = null;
|
|
private final String a;
|
|
private final ArrayList<String> b = new ArrayList<>();
|
|
private Context c;
|
|
|
|
public f(Context context, String str) {
|
|
this.c = context;
|
|
this.a = str;
|
|
c();
|
|
}
|
|
|
|
private void a(String str, String str2, File file) {
|
|
if (str.equals(APMUploadConfigure.APMUPLOADNAME)) {
|
|
b(str2, file);
|
|
} else {
|
|
a(str2, file);
|
|
}
|
|
}
|
|
|
|
private void b(String str, File file) {
|
|
try {
|
|
FileOutputStream fileOutputStream = new FileOutputStream(file, true);
|
|
fileOutputStream.write(str.getBytes());
|
|
fileOutputStream.write(",".getBytes());
|
|
fileOutputStream.flush();
|
|
fileOutputStream.close();
|
|
} catch (IOException e2) {
|
|
e2.printStackTrace();
|
|
com.baidu.uaq.agent.android.harvest.health.a.a(e2);
|
|
}
|
|
}
|
|
|
|
private boolean e(String str) {
|
|
String b = b();
|
|
try {
|
|
File file = new File(b);
|
|
if (!file.exists()) {
|
|
file.mkdirs();
|
|
}
|
|
File file2 = new File(b + str + "_ini");
|
|
if (file2.exists()) {
|
|
return true;
|
|
}
|
|
file2.createNewFile();
|
|
if (this.b.contains(file2.getAbsolutePath())) {
|
|
return true;
|
|
}
|
|
this.b.add(file2.getAbsolutePath());
|
|
return true;
|
|
} catch (IOException e2) {
|
|
e2.printStackTrace();
|
|
com.baidu.uaq.agent.android.harvest.health.a.a(e2);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public ArrayList<String> c(String str) {
|
|
FileInputStream fileInputStream;
|
|
ArrayList<String> arrayList = new ArrayList<>();
|
|
FileInputStream fileInputStream2 = null;
|
|
try {
|
|
try {
|
|
fileInputStream = new FileInputStream(str);
|
|
try {
|
|
int available = fileInputStream.available();
|
|
if (available > 0) {
|
|
int i = 0;
|
|
while (i < available) {
|
|
DataInputStream dataInputStream = new DataInputStream(fileInputStream);
|
|
long readLong = dataInputStream.readLong();
|
|
int i2 = (int) readLong;
|
|
char[] cArr = new char[i2];
|
|
for (int i3 = 0; i3 < readLong; i3++) {
|
|
cArr[i3] = dataInputStream.readChar();
|
|
}
|
|
arrayList.add(new String(cArr, 0, i2));
|
|
i = (int) (i + 8 + readLong);
|
|
}
|
|
}
|
|
try {
|
|
fileInputStream.close();
|
|
} catch (IOException e2) {
|
|
e2.printStackTrace();
|
|
}
|
|
return arrayList;
|
|
} catch (EOFException unused) {
|
|
fileInputStream2 = fileInputStream;
|
|
d.d("read end");
|
|
if (fileInputStream2 != null) {
|
|
try {
|
|
fileInputStream2.close();
|
|
} catch (IOException e3) {
|
|
e3.printStackTrace();
|
|
}
|
|
}
|
|
return arrayList;
|
|
} catch (IOException unused2) {
|
|
fileInputStream2 = fileInputStream;
|
|
d.d("read end");
|
|
if (fileInputStream2 != null) {
|
|
try {
|
|
fileInputStream2.close();
|
|
} catch (IOException e4) {
|
|
e4.printStackTrace();
|
|
}
|
|
}
|
|
return arrayList;
|
|
} catch (Throwable th) {
|
|
th = th;
|
|
if (fileInputStream != null) {
|
|
try {
|
|
fileInputStream.close();
|
|
} catch (IOException e5) {
|
|
e5.printStackTrace();
|
|
}
|
|
}
|
|
throw th;
|
|
}
|
|
} catch (EOFException unused3) {
|
|
} catch (IOException unused4) {
|
|
}
|
|
} catch (Throwable th2) {
|
|
th = th2;
|
|
fileInputStream = null;
|
|
}
|
|
}
|
|
|
|
public File d(String str) {
|
|
File file = new File(b() + str + "_ini");
|
|
if (file.exists() || e(str)) {
|
|
return file;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public void a(String str, String str2) {
|
|
File d2 = d(str);
|
|
if (d2 == null) {
|
|
return;
|
|
}
|
|
if (d2.length() + str2.length() <= 10240) {
|
|
a(str, str2, d2);
|
|
return;
|
|
}
|
|
if (this.b.size() < 10) {
|
|
a(d2, str2);
|
|
return;
|
|
}
|
|
Collections.sort(this.b);
|
|
String remove = this.b.remove(0);
|
|
d.d("expire with file: " + remove);
|
|
File file = new File(remove);
|
|
if (file.exists()) {
|
|
file.delete();
|
|
}
|
|
a(d2, str2);
|
|
}
|
|
|
|
/* JADX WARN: Removed duplicated region for block: B:41:0x0072 A[EXC_TOP_SPLITTER, SYNTHETIC] */
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct code enable 'Show inconsistent code' option in preferences
|
|
*/
|
|
public java.lang.String b(java.lang.String r7) {
|
|
/*
|
|
r6 = this;
|
|
r0 = 0
|
|
java.io.File r1 = new java.io.File // Catch: java.lang.Throwable -> L5c java.io.IOException -> L5e
|
|
r1.<init>(r7) // Catch: java.lang.Throwable -> L5c java.io.IOException -> L5e
|
|
boolean r2 = r1.exists() // Catch: java.lang.Throwable -> L5c java.io.IOException -> L5e
|
|
if (r2 != 0) goto L2b
|
|
java.lang.String r1 = r6.a // Catch: java.lang.Throwable -> L5c java.io.IOException -> L5e
|
|
boolean r1 = r7.contains(r1) // Catch: java.lang.Throwable -> L5c java.io.IOException -> L5e
|
|
if (r1 != 0) goto L2a
|
|
com.baidu.uaq.agent.android.logging.a r1 = com.baidu.uaq.agent.android.util.f.d // Catch: java.lang.Throwable -> L5c java.io.IOException -> L5e
|
|
java.lang.StringBuilder r2 = new java.lang.StringBuilder // Catch: java.lang.Throwable -> L5c java.io.IOException -> L5e
|
|
r2.<init>() // Catch: java.lang.Throwable -> L5c java.io.IOException -> L5e
|
|
java.lang.String r3 = "log file not exists: "
|
|
r2.append(r3) // Catch: java.lang.Throwable -> L5c java.io.IOException -> L5e
|
|
r2.append(r7) // Catch: java.lang.Throwable -> L5c java.io.IOException -> L5e
|
|
java.lang.String r7 = r2.toString() // Catch: java.lang.Throwable -> L5c java.io.IOException -> L5e
|
|
r1.a(r7) // Catch: java.lang.Throwable -> L5c java.io.IOException -> L5e
|
|
L2a:
|
|
return r0
|
|
L2b:
|
|
java.io.FileReader r7 = new java.io.FileReader // Catch: java.lang.Throwable -> L5c java.io.IOException -> L5e
|
|
r7.<init>(r1) // Catch: java.lang.Throwable -> L5c java.io.IOException -> L5e
|
|
java.lang.StringBuilder r1 = new java.lang.StringBuilder // Catch: java.lang.Throwable -> L52 java.io.IOException -> L57
|
|
r1.<init>() // Catch: java.lang.Throwable -> L52 java.io.IOException -> L57
|
|
r2 = 1024(0x400, float:1.435E-42)
|
|
char[] r2 = new char[r2] // Catch: java.lang.Throwable -> L52 java.io.IOException -> L57
|
|
L39:
|
|
int r3 = r7.read(r2) // Catch: java.lang.Throwable -> L52 java.io.IOException -> L57
|
|
r4 = -1
|
|
if (r3 == r4) goto L45
|
|
r4 = 0
|
|
r1.append(r2, r4, r3) // Catch: java.lang.Throwable -> L52 java.io.IOException -> L57
|
|
goto L39
|
|
L45:
|
|
java.lang.String r0 = r1.toString() // Catch: java.lang.Throwable -> L52 java.io.IOException -> L57
|
|
r7.close() // Catch: java.io.IOException -> L4d
|
|
goto L51
|
|
L4d:
|
|
r7 = move-exception
|
|
r7.printStackTrace()
|
|
L51:
|
|
return r0
|
|
L52:
|
|
r0 = move-exception
|
|
r5 = r0
|
|
r0 = r7
|
|
r7 = r5
|
|
goto L70
|
|
L57:
|
|
r1 = move-exception
|
|
r5 = r1
|
|
r1 = r7
|
|
r7 = r5
|
|
goto L60
|
|
L5c:
|
|
r7 = move-exception
|
|
goto L70
|
|
L5e:
|
|
r7 = move-exception
|
|
r1 = r0
|
|
L60:
|
|
r7.printStackTrace() // Catch: java.lang.Throwable -> L6e
|
|
if (r1 == 0) goto L6d
|
|
r1.close() // Catch: java.io.IOException -> L69
|
|
goto L6d
|
|
L69:
|
|
r7 = move-exception
|
|
r7.printStackTrace()
|
|
L6d:
|
|
return r0
|
|
L6e:
|
|
r7 = move-exception
|
|
r0 = r1
|
|
L70:
|
|
if (r0 == 0) goto L7a
|
|
r0.close() // Catch: java.io.IOException -> L76
|
|
goto L7a
|
|
L76:
|
|
r0 = move-exception
|
|
r0.printStackTrace()
|
|
L7a:
|
|
throw r7
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: com.baidu.uaq.agent.android.util.f.b(java.lang.String):java.lang.String");
|
|
}
|
|
|
|
private void a(File file, String str) {
|
|
String absolutePath = file.getAbsolutePath();
|
|
int lastIndexOf = absolutePath.lastIndexOf(File.separator) + 1;
|
|
if (lastIndexOf >= 0 && lastIndexOf <= absolutePath.length()) {
|
|
String str2 = absolutePath.substring(0, lastIndexOf) + this.a + "_" + System.currentTimeMillis();
|
|
file.renameTo(new File(str2));
|
|
this.b.add(str2);
|
|
a(this.a, str, file);
|
|
return;
|
|
}
|
|
d.b("in toPersistentFile, StringIndexOutOfBoundsException happened!");
|
|
}
|
|
|
|
private void c() {
|
|
if (!this.b.isEmpty()) {
|
|
this.b.clear();
|
|
}
|
|
File file = new File(b());
|
|
e(this.a);
|
|
String[] list = file.list();
|
|
if (list == null || list.length == 0) {
|
|
return;
|
|
}
|
|
for (String str : list) {
|
|
if (!this.b.contains(b() + str) && str.contains(this.a)) {
|
|
this.b.add(b() + str);
|
|
}
|
|
}
|
|
Collections.reverse(this.b);
|
|
}
|
|
|
|
private void a(String str, File file) {
|
|
try {
|
|
FileOutputStream fileOutputStream = new FileOutputStream(file, true);
|
|
DataOutputStream dataOutputStream = new DataOutputStream(fileOutputStream);
|
|
d.d("writeToDefaultCustomFile log size:" + str.length());
|
|
dataOutputStream.writeLong((long) str.length());
|
|
dataOutputStream.writeChars(str);
|
|
dataOutputStream.flush();
|
|
dataOutputStream.close();
|
|
fileOutputStream.flush();
|
|
fileOutputStream.close();
|
|
} catch (IOException e2) {
|
|
e2.printStackTrace();
|
|
com.baidu.uaq.agent.android.harvest.health.a.a(e2);
|
|
}
|
|
}
|
|
|
|
private String b() {
|
|
if (e == null) {
|
|
e = this.c.getFilesDir().getAbsolutePath() + "/apm/";
|
|
}
|
|
return e;
|
|
}
|
|
|
|
public boolean a(String str) {
|
|
File file = new File(str);
|
|
this.b.remove(str);
|
|
if (file.exists()) {
|
|
return file.delete();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public ArrayList<String> a() {
|
|
Collections.sort(this.b);
|
|
return this.b;
|
|
}
|
|
}
|