QQ浏览器 v12.2.3.7053版本的 MD5 值为:8285ab3059e5c8b521a264dfbc5c3685
以下内容为反编译后的 NovelCacheBase.java 源代码,内容仅作参考
package com.tencent.mtt.external.novel.base.engine;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import com.tencent.common.http.MttRequestBase;
import com.tencent.common.threadpool.BrowserExecutorSupplier;
import com.tencent.common.utils.DesUtils;
import com.tencent.common.utils.FileUtils;
import com.tencent.common.utils.TEACoding;
import com.tencent.common.utils.gzip.GzipUtils;
import com.tencent.mtt.account.base.IAccount;
import com.tencent.mtt.apkplugin.impl.IAPInjectService;
import com.tencent.mtt.base.task.Task;
import com.tencent.mtt.browser.WebEngine;
import com.tencent.mtt.external.novel.base.engine.offline.IChapterSaveInteface;
import com.tencent.mtt.external.novel.base.model.NovelChapterInfo;
import com.tencent.mtt.external.novel.base.model.NovelContentInfo;
import com.tencent.mtt.external.novel.base.model.NovelInfo;
import com.tencent.mtt.external.novel.base.stat.NovelBehaviourRecorder;
import com.tencent.mtt.external.novel.base.stat.NovelStatUtils;
import com.tencent.mtt.external.novel.base.stat.NvQltRptBase;
import com.tencent.mtt.external.novel.base.tools.NovelContext;
import com.tencent.mtt.external.novel.base.tools.NovelUtils;
import com.tencent.mtt.external.novel.inhost.base.NovelConstant;
import com.tencent.mtt.log.access.Logs;
import com.tencent.mtt.miniprogram.util.WeChatMiniProgramConstant;
import com.tencent.mtt.sdkcontext.SDKContext;
import com.xiaomi.mipush.sdk.Constants;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import java.util.concurrent.ConcurrentHashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public abstract class NovelCacheBase {
private static final byte[] n = {80, MttRequestBase.REQUEST_FILE_DOWNLOAD, 97, MttRequestBase.REQUEST_SEARCH, MttRequestBase.REQUEST_VIDEO_DOWNLOAD, MttRequestBase.REQUEST_NOVEL, MttRequestBase.REQUEST_VIDEO_REPORT, 81, MttRequestBase.REQUEST_WUP, 64, 49, 52, 48, 57, 50, 56};
NovelContext m;
ConcurrentHashMap<String, JSONObject> f54236d = new ConcurrentHashMap<>();
ConcurrentHashMap<String, ConcurrentHashMap<Integer, Index>> e = new ConcurrentHashMap<>();
ConcurrentHashMap<String, Boolean> f = new ConcurrentHashMap<>();
Hashtable<String, NovelContentInfo> g = new Hashtable<>();
HashMap<String, Header> h = new HashMap<>();
ConcurrentHashMap<String, ConcurrentHashMap<Integer, Integer[]>> i = new ConcurrentHashMap<>();
HashMap<String, ConcurrentHashMap<Integer, Integer>> j = new HashMap<>();
HashMap<String, ConcurrentHashMap<Integer, Integer>> k = new HashMap<>();
ConcurrentHashMap<String, byte[]> l = new ConcurrentHashMap<>();
public Handler f54233a = new Handler(BrowserExecutorSupplier.getLooperForRunLongTime());
public Handler f54234b = new Handler(BrowserExecutorSupplier.getBusinessLooper("novel_core_thread"));
public Handler f54235c = new Handler(Looper.getMainLooper());
public static class DataIntParams {
public int f54269a;
public Integer f54270b = null;
public Integer f54271c = null;
public Integer f54272d = null;
public DataIntParams(int i) {
this.f54269a = i;
}
public String toString() {
return "[f:0x" + Integer.toHexString(this.f54269a) + ",sid:[" + this.f54270b + Constants.ACCEPT_TIME_SEPARATOR_SERVER + this.f54271c + "]s:" + this.f54272d + "]";
}
}
public static abstract class DataIntTask extends Task {
public float k = 0.0f;
public NovelChapterInfo l = null;
public ArrayList<NovelChapterInfo> m = null;
}
public static class Header {
public String f54273a;
public String f54274b;
public int f54275c;
public int f54276d;
public int e;
public Header() {
this.f54273a = "";
this.f54274b = "";
this.f54275c = 2;
this.e = 0;
}
public Header(String str, String str2, int i, int i2, int i3) {
this.f54273a = "";
this.f54274b = "";
this.f54275c = 2;
this.e = 0;
this.f54273a = str;
this.f54274b = str2;
this.f54275c = i;
this.f54276d = i2;
this.e = i3;
}
public void a(Header header) {
this.f54273a = header.f54273a;
this.f54274b = header.f54274b;
this.f54275c = header.f54275c;
this.f54276d = header.f54276d;
this.e = header.e;
}
public String toString() {
return "[bid_" + this.f54273a + ",v_" + this.f54275c + ",sz_" + this.f54276d + ",c_" + this.e + "]";
}
}
public static class Index {
public int f54277a;
public long f54278b;
public Index(int i, long j) {
this.f54277a = 0;
this.f54278b = 0L;
this.f54277a = i;
this.f54278b = j;
}
public boolean equals(Object obj) {
int i;
if (!(obj instanceof Index)) {
return false;
}
Index index = (Index) obj;
int i2 = this.f54277a;
return (i2 == 0 || (i = index.f54277a) == 0 || i2 != i) ? false : true;
}
public int hashCode() {
int i = this.f54277a;
return (i * 10) + i;
}
}
public NovelCacheBase(NovelContext novelContext) {
this.m = novelContext;
}
public static long a(int i) {
return i * 5120;
}
private NovelChapterInfo a(RandomAccessFile randomAccessFile, String str, int i) {
NovelChapterInfo novelChapterInfo = new NovelChapterInfo();
if (a(randomAccessFile, str, i, novelChapterInfo)) {
return novelChapterInfo;
}
return null;
}
private NovelContentInfo a(int i, NovelContentInfo novelContentInfo, JSONArray jSONArray, int i2) {
try {
NovelContentInfo a2 = a(jSONArray.getJSONObject(i2));
if (a2.f54472a != null) {
a2.f54472a = a2.f54472a.replace("<br>", "\r\n");
a2.f54472a = a2.f54472a.replace("<br/>", "\r\n");
}
a(a2.f, a2, false, (IContentSaveInteface) null);
return a2.f54473b == i ? a2 : novelContentInfo;
} catch (JSONException unused) {
return novelContentInfo;
}
}
public static NovelContentInfo a(JSONObject jSONObject) throws JSONException {
NovelContentInfo novelContentInfo = new NovelContentInfo();
novelContentInfo.f54472a = jSONObject.getString("serialcontent");
novelContentInfo.f = jSONObject.getString("resourceid");
novelContentInfo.g = jSONObject.getString("booktitle");
novelContentInfo.f54473b = jSONObject.getInt("serialid");
novelContentInfo.f54475d = jSONObject.getString("serialurl");
novelContentInfo.h = jSONObject.getString("serialname");
novelContentInfo.e = jSONObject.getString("serialmd5");
if (jSONObject.has("serialsitename")) {
novelContentInfo.i = jSONObject.getString("serialsitename");
}
if (jSONObject.has("contentOnline")) {
novelContentInfo.k = jSONObject.getInt("contentOnline");
}
if (jSONObject.has("contentUuid")) {
novelContentInfo.l = jSONObject.getString("contentUuid");
}
if (jSONObject.has("seriallastmodifytime")) {
novelContentInfo.j = jSONObject.getLong("seriallastmodifytime");
}
if (jSONObject.has("chapterid")) {
novelContentInfo.f54474c = jSONObject.getInt("chapterid");
}
if (jSONObject.has("conpayret")) {
novelContentInfo.m = jSONObject.getInt("conpayret");
}
if (jSONObject.has("conpaymsg")) {
novelContentInfo.n = jSONObject.getString("conpaymsg");
}
if (jSONObject.has("conpayprice")) {
novelContentInfo.o = jSONObject.getInt("conpayprice");
}
if (jSONObject.has("conchpprice")) {
novelContentInfo.r = jSONObject.getInt("conchpprice");
}
if (jSONObject.has("conpbookrice")) {
novelContentInfo.s = jSONObject.getInt("conpbookrice");
}
if (jSONObject.has("conpaybanlance")) {
novelContentInfo.p = jSONObject.getInt("conpaybanlance");
}
if (jSONObject.has("conpaybanlancefree")) {
novelContentInfo.q = jSONObject.getInt("conpaybanlancefree");
}
if (jSONObject.has("conpayintegrity")) {
novelContentInfo.t = jSONObject.getBoolean("conpayintegrity");
}
jSONObject.has("concuruser");
if (!TextUtils.isEmpty(novelContentInfo.f54472a) && jSONObject.has("pack")) {
System.currentTimeMillis();
if (jSONObject.getInt("pack") == 19831025) {
String str = novelContentInfo.f54472a;
try {
byte[] b2 = new TEACoding(n).b(novelContentInfo.f54472a);
if (b2 != null) {
novelContentInfo.f54472a = new String(b2, "UTF-16BE");
}
} catch (Throwable unused) {
}
}
}
return novelContentInfo;
}
private String a(NovelContentInfo novelContentInfo, JSONObject jSONObject, Integer num) {
String str = novelContentInfo.f54472a;
if (TextUtils.isEmpty(str)) {
return str;
}
System.currentTimeMillis();
if (num == null || num.equals(0)) {
return str;
}
try {
TEACoding tEACoding = new TEACoding(n);
byte[] bytes = str.getBytes("UTF-16BE");
if (bytes == null) {
return str;
}
String b2 = tEACoding.b(bytes);
if (TextUtils.isEmpty(b2)) {
return str;
}
try {
jSONObject.put("pack", 19831025);
return b2;
} catch (Throwable th) {
th = th;
str = b2;
Logs.a("NovelCacheBase", th);
return str;
}
} catch (Throwable th2) {
th = th2;
}
}
private String a(Throwable th) {
String th2 = th.toString();
if ((th instanceof JSONException) || (th instanceof FileNotFoundException)) {
return th2;
}
return th2 + "@" + NovelStatUtils.a(NovelStatUtils.a(th.getStackTrace(), 0, 3));
}
private JSONObject a(File file, Object[] objArr) {
BufferedReader bufferedReader;
boolean z;
boolean z2 = true;
if (file == null || !file.exists()) {
NvQltRptBase nvQltRptBase = new NvQltRptBase(this.m.g, 3, "" + objArr[0] + Constants.ACCEPT_TIME_SEPARATOR_SERVER + objArr[1]);
boolean z3 = objArr[2] instanceof Integer;
String str = IAPInjectService.EP_NULL;
if (z3 && ((Integer) objArr[2]).equals(4)) {
NvQltRptBase c2 = nvQltRptBase.c(com.tencent.connect.common.Constants.VIA_REPORT_TYPE_SHARE_TO_TROOPBAR);
if (file != null) {
str = file.getAbsolutePath();
}
c2.e(str);
} else {
NvQltRptBase d2 = nvQltRptBase.d(com.tencent.connect.common.Constants.VIA_REPORT_TYPE_SHARE_TO_TROOPBAR);
if (file != null) {
str = file.getAbsolutePath();
}
d2.f(str);
}
} else {
try {
StringBuilder sb = new StringBuilder();
try {
bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file.getAbsolutePath()), "UTF-8"));
} catch (Throwable th) {
th = th;
bufferedReader = null;
}
while (true) {
try {
try {
String readLine = bufferedReader.readLine();
if (readLine != null) {
sb.append(readLine);
}
} catch (Throwable th2) {
th = th2;
try {
new NvQltRptBase(this.m.g, 3, "" + objArr[0] + Constants.ACCEPT_TIME_SEPARATOR_SERVER + objArr[1]).c(WeChatMiniProgramConstant.LOG_TYPE_FLOW_VIDEO).e(th.toString());
break;
JSONObject jSONObject = new JSONObject(sb.toString());
if (bufferedReader != null) {
}
return jSONObject;
} catch (Throwable th3) {
th = th3;
z = false;
try {
new NvQltRptBase(this.m.g, 3, "" + objArr[0] + Constants.ACCEPT_TIME_SEPARATOR_SERVER + objArr[1]).c(WeChatMiniProgramConstant.LOG_TYPE_FLOW_VIDEO).e(th.toString());
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException unused) {
}
}
z2 = z;
if (z2) {
FileUtils.d(file);
}
return null;
} catch (Throwable th4) {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException unused2) {
}
}
throw th4;
}
}
}
break;
} catch (Throwable th5) {
try {
new NvQltRptBase(this.m.g, 3, "" + objArr[0] + Constants.ACCEPT_TIME_SEPARATOR_SERVER + objArr[1]).c("21").e(th5.toString());
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException unused3) {
}
}
} catch (Throwable th6) {
th = th6;
z = true;
new NvQltRptBase(this.m.g, 3, "" + objArr[0] + Constants.ACCEPT_TIME_SEPARATOR_SERVER + objArr[1]).c(WeChatMiniProgramConstant.LOG_TYPE_FLOW_VIDEO).e(th.toString());
if (bufferedReader != null) {
}
z2 = z;
if (z2) {
}
return null;
}
if (z2) {
}
return null;
}
}
JSONObject jSONObject2 = new JSONObject(sb.toString());
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException unused4) {
}
}
return jSONObject2;
} catch (Throwable th7) {
th = th7;
bufferedReader = null;
}
}
return null;
}
private void a(NovelContentInfo novelContentInfo, boolean z, int i, int i2, int i3, boolean z2, boolean z3) {
}
public void a(RandomAccessFile randomAccessFile, String str) {
if (randomAccessFile != null) {
try {
randomAccessFile.close();
} catch (Exception unused) {
}
}
}
private void a(Object obj, RandomAccessFile randomAccessFile) {
if (randomAccessFile != null) {
try {
randomAccessFile.close();
} catch (Exception unused) {
}
}
}
private void a(String str, NovelContentInfo novelContentInfo) {
Integer num;
Integer num2;
if (novelContentInfo.f54474c > 0) {
ConcurrentHashMap<Integer, Integer> a2 = a(this.j, str);
if (!a2.containsKey(Integer.valueOf(novelContentInfo.f54474c)) || (num2 = a2.get(Integer.valueOf(novelContentInfo.f54474c))) == null || num2.intValue() <= 0) {
return;
}
novelContentInfo.f54473b = num2.intValue();
return;
}
if (novelContentInfo.f54473b > 0) {
ConcurrentHashMap<Integer, Integer> a3 = a(this.k, str);
if (!a3.containsKey(Integer.valueOf(novelContentInfo.f54473b)) || (num = a3.get(Integer.valueOf(novelContentInfo.f54473b))) == null || num.intValue() <= 0) {
return;
}
novelContentInfo.f54474c = num.intValue();
}
}
private void a(final String str, final NovelContentInfo novelContentInfo, final boolean z, final IContentSaveInteface iContentSaveInteface, final int i, final int i2, final boolean z2, final boolean z3, final boolean z4, final Integer num) {
this.f54233a.post(new Runnable() {
@Override
public void run() {
int i3 = novelContentInfo.f54473b;
int a2 = NovelCacheBase.this.a(novelContentInfo, num);
boolean z5 = a2 == 0;
if (iContentSaveInteface != null && NovelEngine.a(Integer.valueOf(i), 3)) {
ContentSaveCallBack contentSaveCallBack = new ContentSaveCallBack();
contentSaveCallBack.f = 1;
contentSaveCallBack.f54195a = str;
contentSaveCallBack.f54196b = i3;
contentSaveCallBack.g = z5;
contentSaveCallBack.h = i;
contentSaveCallBack.i = i2;
contentSaveCallBack.j = z2;
contentSaveCallBack.k = z3;
contentSaveCallBack.l = z4;
contentSaveCallBack.m = a2;
contentSaveCallBack.e = z ? 1 : 0;
iContentSaveInteface.a(contentSaveCallBack);
}
NovelCacheBase.this.g.remove(str + i3);
}
});
}
private void a(String str, ArrayList<NovelChapterInfo> arrayList) {
if (arrayList.size() <= 0 || NovelConstant.f55230b) {
return;
}
int size = arrayList.size();
int min = Math.min(size, 3);
for (int i = 1; i <= min; i++) {
arrayList.get(size - i);
}
}
private boolean a(IContentSaveInteface iContentSaveInteface, int i) {
return iContentSaveInteface != null && NovelEngine.a(Integer.valueOf(i), 3);
}
private boolean a(RandomAccessFile randomAccessFile, String str, int i, NovelChapterInfo novelChapterInfo) {
novelChapterInfo.f54468a = str;
novelChapterInfo.f54469b = i;
try {
byte[] bArr = new byte[randomAccessFile.readInt()];
randomAccessFile.read(bArr);
novelChapterInfo.j = new String(bArr, "UTF-8");
novelChapterInfo.k = randomAccessFile.readInt();
novelChapterInfo.i = randomAccessFile.readInt();
byte[] bArr2 = new byte[randomAccessFile.readInt()];
randomAccessFile.read(bArr2);
novelChapterInfo.f54470c = new String(bArr2, "UTF-8");
byte[] bArr3 = new byte[randomAccessFile.readInt()];
randomAccessFile.read(bArr3);
novelChapterInfo.f54471d = new String(bArr3, "UTF-8");
byte[] bArr4 = new byte[randomAccessFile.readInt()];
randomAccessFile.read(bArr4);
novelChapterInfo.e = new String(bArr4, "UTF-8");
novelChapterInfo.f = randomAccessFile.readFloat();
novelChapterInfo.g = randomAccessFile.readInt();
novelChapterInfo.h = randomAccessFile.readLong();
novelChapterInfo.l = randomAccessFile.readLong();
novelChapterInfo.m = randomAccessFile.readInt();
boolean z = NovelConstant.f55230b;
return true;
} catch (Throwable th) {
new NvQltRptBase(this.m.g, 3, str + Constants.ACCEPT_TIME_SEPARATOR_SERVER + i).e(th.toString() + "@" + NovelStatUtils.a(th.getStackTrace())).c(com.tencent.connect.common.Constants.VIA_REPORT_TYPE_START_WAP);
return false;
}
}
private boolean a(String str, int i, boolean z, boolean z2, ArrayList<NovelChapterInfo> arrayList) {
File file;
int i2;
boolean z3 = false;
RandomAccessFile randomAccessFile = null;
try {
file = new File(this.m.f54693b.a(str), str + Constants.ACCEPT_TIME_SEPARATOR_SERVER + ".newContent");
} catch (Throwable unused) {
}
if (file.exists()) {
long j = 0;
if (this.f54236d.containsKey(str + i)) {
JSONObject jSONObject = this.f54236d.get(str + i);
if (!z || (z && jSONObject.has("contentoffline") && jSONObject.getBoolean("contentoffline"))) {
long j2 = jSONObject.getLong("start");
i2 = jSONObject.getInt("length");
j = j2;
if (!z2) {
if (i2 != 0) {
byte[] bArr = new byte[i2];
RandomAccessFile randomAccessFile2 = new RandomAccessFile(file, "r");
try {
randomAccessFile2.seek(j);
randomAccessFile2.read(bArr, 0, i2);
randomAccessFile2.close();
new JSONObject(new String(bArr, "UTF-8"));
randomAccessFile = randomAccessFile2;
z3 = true;
} catch (Throwable unused2) {
randomAccessFile = randomAccessFile2;
}
}
}
}
i2 = 0;
if (!z2) {
}
} else {
NovelChapterInfo a2 = NovelChapterInfo.a(i, arrayList);
if (a2 != null && (!z || (z && a2.i == 1))) {
j = a2.l;
i2 = a2.m;
if (!z2) {
}
}
i2 = 0;
if (!z2) {
}
}
try {
randomAccessFile.close();
} catch (Exception unused3) {
return z3;
}
}
}
@Deprecated
private NovelChapterInfo b(RandomAccessFile randomAccessFile, String str, int i) {
NovelChapterInfo novelChapterInfo = new NovelChapterInfo();
a(randomAccessFile, str, i, novelChapterInfo);
return novelChapterInfo;
}
public static NovelContentInfo b(JSONObject jSONObject) throws JSONException {
NovelContentInfo novelContentInfo = new NovelContentInfo();
novelContentInfo.f54473b = jSONObject.getInt("iSerialID");
novelContentInfo.f54475d = jSONObject.getString("sSerialUrl");
novelContentInfo.h = jSONObject.getString("sSerialName");
novelContentInfo.e = jSONObject.getString("sContentMD5");
novelContentInfo.f54474c = jSONObject.getInt("sSerialUniqID");
novelContentInfo.i = jSONObject.getString("sSiteName");
novelContentInfo.l = jSONObject.getString("sContentUniqID");
if (jSONObject.has("eStrategy")) {
novelContentInfo.w = jSONObject.getInt("eStrategy");
}
return novelContentInfo;
}
private NovelContentInfo d(String str, int i, int i2) {
NvQltRptBase nvQltRptBase;
File a2 = this.m.f54693b.a(str);
StringBuilder sb = new StringBuilder();
sb.append(i);
sb.append(i2 >= 4 ? ".novel" : ".json");
File file = new File(a2, sb.toString());
Integer valueOf = i2 > 2 ? a(this.j, str).get(Integer.valueOf(i)) : Integer.valueOf(i);
JSONObject a3 = a(file, new Object[]{str, valueOf, Integer.valueOf(i2)});
if (valueOf != null) {
nvQltRptBase = new NvQltRptBase(this.m.g, 3, str + Constants.ACCEPT_TIME_SEPARATOR_SERVER + valueOf);
NovelBehaviourRecorder.Recorder c2 = nvQltRptBase.c();
Object[] objArr = new Object[7];
objArr[0] = 10;
objArr[1] = str;
objArr[2] = Integer.valueOf(i);
objArr[3] = Integer.valueOf(i2);
objArr[4] = file.getName();
objArr[5] = Boolean.valueOf(file.exists());
objArr[6] = Boolean.valueOf(a3 != null);
c2.a(8, objArr);
} else {
nvQltRptBase = null;
}
if (a3 == null) {
return null;
}
try {
return a(a3);
} catch (JSONException e) {
if (nvQltRptBase != null) {
nvQltRptBase.c().a(8, "excp", e.toString());
nvQltRptBase.c("18").e(e.toString());
}
if (!file.isFile()) {
return null;
}
FileUtils.d(file);
return null;
}
}
private void e(String str) {
try {
FileUtils.a(new File(this.m.f54693b.a(str), str + "file_header.header"));
} catch (Exception unused) {
}
}
private NovelContentInfo f(String str, int i) {
String str2;
JSONArray jSONArray;
NovelContentInfo novelContentInfo = null;
try {
str2 = WebEngine.e().a("http://book.soso.com", WebEngine.H5ApplicationCacheType.Persistent);
} catch (Exception unused) {
str2 = null;
}
if (TextUtils.isEmpty(str2)) {
return null;
}
try {
File file = new File(new File(new File(str2), str), "data_" + (((i / 10) * 10) + 1));
if (file.exists()) {
JSONObject a2 = a(file, new Object[]{str, Integer.valueOf(i), true});
if (a2 == null) {
return null;
}
try {
jSONArray = a2.getJSONArray("details");
} catch (JSONException unused2) {
jSONArray = null;
}
if (jSONArray != null && jSONArray.length() > 0) {
int length = jSONArray.length();
for (int i2 = 0; i2 < length; i2++) {
novelContentInfo = a(i, novelContentInfo, jSONArray, i2);
}
}
}
} catch (Exception unused3) {
}
return novelContentInfo;
}
private NovelContentInfo g(String str, int i) {
String str2;
String str3;
char c2;
NovelContentInfo novelContentInfo;
RandomAccessFile randomAccessFile;
byte[] d2;
RandomAccessFile randomAccessFile2;
NovelContentInfo novelContentInfo2;
String str4;
NvQltRptBase nvQltRptBase = new NvQltRptBase(this.m.g, 3, str + Constants.ACCEPT_TIME_SEPARATOR_SERVER + i);
File a2 = this.m.f54693b.a(str);
File file = new File(a2, str + "_index.dat");
File file2 = new File(a2, str + "_content.dat");
File file3 = new File(a2, str + "_info.dat");
boolean exists = file.exists();
boolean exists2 = file2.exists();
boolean exists3 = file3.exists();
nvQltRptBase.c().a(4, 10, Boolean.valueOf(exists), Boolean.valueOf(exists2), Boolean.valueOf(exists3));
if (!exists || !exists2 || !exists3) {
if (!exists) {
str2 = com.tencent.connect.common.Constants.VIA_REPORT_TYPE_CHAT_AIO;
} else if (!exists2) {
str2 = com.tencent.connect.common.Constants.VIA_REPORT_TYPE_CHAT_AUDIO;
} else {
if (exists3) {
return null;
}
str2 = com.tencent.connect.common.Constants.VIA_REPORT_TYPE_CHAT_VIDEO;
}
nvQltRptBase.d(str2);
return null;
}
Integer b2 = b(str, i);
nvQltRptBase.c().a(4, 20, str, Integer.valueOf(i), b2);
if (b2 == null) {
str4 = "27";
} else {
if (!this.i.containsKey(str)) {
ConcurrentHashMap<Integer, Integer[]> concurrentHashMap = new ConcurrentHashMap<>();
a(file, concurrentHashMap);
this.i.put(str, concurrentHashMap);
}
ConcurrentHashMap<Integer, Integer[]> concurrentHashMap2 = this.i.get(str);
if (concurrentHashMap2.containsKey(b2)) {
Integer[] numArr = concurrentHashMap2.get(b2);
nvQltRptBase.c().a(4, 30, numArr);
int intValue = numArr[2].intValue();
int intValue2 = numArr[3].intValue();
if (intValue2 != 0) {
byte[] bArr = new byte[intValue2];
try {
randomAccessFile2 = new RandomAccessFile(file3, "r");
try {
try {
randomAccessFile2.seek(intValue);
randomAccessFile2.read(bArr, 0, intValue2);
str3 = "UTF-8";
} catch (Exception e) {
e = e;
str3 = "UTF-8";
}
try {
JSONObject jSONObject = new JSONObject(new String(bArr, str3));
if (jSONObject.getInt("iSerialID") != i) {
jSONObject.put("iSerialID", i);
}
novelContentInfo2 = b(jSONObject);
} catch (Exception e2) {
e = e2;
novelContentInfo2 = null;
nvQltRptBase.c("30").e(e.toString());
nvQltRptBase.c().a(4, "excp10", e.toString());
}
try {
novelContentInfo2.f = str;
} catch (Exception e3) {
e = e3;
nvQltRptBase.c("30").e(e.toString());
nvQltRptBase.c().a(4, "excp10", e.toString());
}
} catch (Throwable th) {
th = th;
if (randomAccessFile2 != null) {
try {
randomAccessFile2.close();
} catch (IOException unused) {
}
}
throw th;
}
} catch (Exception e4) {
e = e4;
str3 = "UTF-8";
novelContentInfo2 = null;
randomAccessFile2 = null;
} catch (Throwable th2) {
th = th2;
randomAccessFile2 = null;
if (randomAccessFile2 != null) {
}
throw th;
}
try {
randomAccessFile2.close();
} catch (IOException unused2) {
}
novelContentInfo = novelContentInfo2;
c2 = 0;
} else {
str3 = "UTF-8";
nvQltRptBase.c("29").e("" + intValue2);
c2 = 0;
novelContentInfo = null;
}
int intValue3 = numArr[c2].intValue();
int intValue4 = numArr[1].intValue();
if (intValue4 != 0) {
byte[] bArr2 = new byte[intValue4];
try {
randomAccessFile = new RandomAccessFile(file2, "r");
try {
randomAccessFile.seek(intValue3);
randomAccessFile.read(bArr2, 0, intValue4);
String str5 = "key_novel_privatekey_" + str;
if (novelContentInfo == null || novelContentInfo.w != 1) {
String str6 = new String(bArr2, str3);
if (novelContentInfo != null) {
novelContentInfo.f54472a = str6;
}
} else {
boolean e5 = this.m.f54694c.e(str5);
boolean a3 = this.m.f54694c.a("key_novel_all_cached_" + str, false);
if (e5 && a3) {
if (this.l.containsKey(str)) {
d2 = this.l.get(str);
} else {
d2 = NovelUtils.d(str);
this.l.put(str, d2);
}
String str7 = new String(GzipUtils.c(DesUtils.b(d2, bArr2, 2)), str3);
if (!TextUtils.isEmpty(str7)) {
novelContentInfo.f54472a = str7;
}
novelContentInfo.v = true;
} else {
novelContentInfo = null;
}
}
nvQltRptBase.c().a(4, 50, NovelStatUtils.a(novelContentInfo));
} catch (Throwable th3) {
th = th3;
try {
nvQltRptBase.c("32").e(th.toString());
nvQltRptBase.c().a(4, "excp20", th.toString());
} catch (Throwable th4) {
if (randomAccessFile != null) {
try {
randomAccessFile.close();
} catch (IOException unused3) {
}
}
throw th4;
}
}
} catch (Throwable th5) {
th = th5;
randomAccessFile = null;
}
try {
randomAccessFile.close();
} catch (IOException unused4) {
}
} else {
nvQltRptBase.c("31").e("" + intValue2);
}
return novelContentInfo;
}
str4 = com.tencent.connect.common.Constants.VIA_ACT_TYPE_TWENTY_EIGHT;
}
nvQltRptBase.c(str4);
return null;
}
private NovelContentInfo h(String str, int i) {
RandomAccessFile randomAccessFile;
RandomAccessFile randomAccessFile2;
NovelContentInfo novelContentInfo;
File file;
File file2;
RandomAccessFile randomAccessFile3;
long j;
RandomAccessFile randomAccessFile4;
int i2;
String str2;
RandomAccessFile randomAccessFile5;
NvQltRptBase nvQltRptBase = new NvQltRptBase(this.m.g, 3, str + Constants.ACCEPT_TIME_SEPARATOR_SERVER + i);
try {
File a2 = this.m.f54693b.a(str);
file = new File(a2, str + Constants.ACCEPT_TIME_SEPARATOR_SERVER + ".indx");
file2 = new File(a2, str + Constants.ACCEPT_TIME_SEPARATOR_SERVER + ".newContent");
} catch (Throwable th) {
th = th;
randomAccessFile = null;
}
if (file2.exists()) {
long j2 = 0;
if (this.f54236d.containsKey(str + i)) {
JSONObject jSONObject = this.f54236d.get(str + i);
long j3 = jSONObject.getLong("start");
int i3 = jSONObject.getInt("length");
if (i3 <= 0) {
nvQltRptBase.c("12");
nvQltRptBase.c().a(3, 10, Long.valueOf(j3), Integer.valueOf(i3));
}
i2 = i3;
j = j3;
randomAccessFile4 = null;
} else if (file.exists()) {
randomAccessFile = new RandomAccessFile(file, "r");
try {
StringBuilder sb = new StringBuilder();
sb.append("getContent-");
if (a(str, sb).containsKey(Integer.valueOf(i))) {
StringBuilder sb2 = new StringBuilder();
sb.append("getContent2-");
long j4 = a(str, sb2).get(Integer.valueOf(i)).f54278b;
randomAccessFile.seek(j4);
randomAccessFile.readInt();
int readInt = randomAccessFile.readInt();
int readInt2 = randomAccessFile.readInt();
nvQltRptBase.c().a(3, 20, Long.valueOf(j4), Integer.valueOf(readInt), Integer.valueOf(readInt2), Integer.valueOf(i));
if (readInt == 1) {
NovelChapterInfo b2 = b(randomAccessFile, str, readInt2);
if (b2 != null) {
long j5 = b2.l;
i2 = b2.m;
j2 = j5;
} else {
i2 = 0;
}
if (i2 <= 0) {
nvQltRptBase.c(com.tencent.connect.common.Constants.VIA_REPORT_TYPE_START_GROUP);
}
randomAccessFile4 = randomAccessFile;
j = j2;
} else {
str2 = com.tencent.connect.common.Constants.VIA_REPORT_TYPE_WPA_STATE;
}
} else {
str2 = com.tencent.connect.common.Constants.VIA_REPORT_TYPE_MAKE_FRIEND;
}
nvQltRptBase.c(str2);
i2 = 0;
randomAccessFile4 = randomAccessFile;
j = j2;
} catch (Throwable th2) {
th = th2;
randomAccessFile2 = null;
novelContentInfo = null;
try {
String a3 = a(th);
nvQltRptBase.c().a(3, "excp10", a3);
nvQltRptBase.d(com.tencent.connect.common.Constants.VIA_ACT_TYPE_NINETEEN).f(a3);
a(randomAccessFile, "getContentBySerialId2:");
a(randomAccessFile2, "getContentBySerialId3:");
return novelContentInfo;
} catch (Throwable th3) {
a(randomAccessFile, "getContentBySerialId2:");
a(randomAccessFile2, "getContentBySerialId3:");
throw th3;
}
}
} else {
nvQltRptBase.c(com.tencent.connect.common.Constants.VIA_REPORT_TYPE_JOININ_GROUP).e("1");
j = 0;
randomAccessFile4 = null;
i2 = 0;
}
try {
NovelBehaviourRecorder.Recorder c2 = nvQltRptBase.c();
Object[] objArr = new Object[4];
objArr[0] = 30;
objArr[1] = Integer.valueOf(i);
objArr[2] = Long.valueOf(j);
randomAccessFile5 = randomAccessFile4;
try {
objArr[3] = Integer.valueOf(i2);
c2.a(3, objArr);
} catch (Throwable th4) {
th = th4;
randomAccessFile = randomAccessFile5;
randomAccessFile2 = null;
novelContentInfo = null;
String a32 = a(th);
nvQltRptBase.c().a(3, "excp10", a32);
nvQltRptBase.d(com.tencent.connect.common.Constants.VIA_ACT_TYPE_NINETEEN).f(a32);
a(randomAccessFile, "getContentBySerialId2:");
a(randomAccessFile2, "getContentBySerialId3:");
return novelContentInfo;
}
} catch (Throwable th5) {
th = th5;
randomAccessFile5 = randomAccessFile4;
}
if (i2 != 0) {
byte[] bArr = new byte[i2];
randomAccessFile2 = new RandomAccessFile(file2, "r");
try {
randomAccessFile2.seek(j);
randomAccessFile2.read(bArr, 0, i2);
JSONObject jSONObject2 = new JSONObject(new String(bArr, "UTF-8"));
if (jSONObject2.getInt("serialid") != i) {
jSONObject2.put("serialid", i);
}
NovelContentInfo a4 = a(jSONObject2);
try {
a4.f = str;
novelContentInfo = a4;
randomAccessFile3 = randomAccessFile5;
a(randomAccessFile3, "getContentBySerialId2:");
} catch (Throwable th6) {
th = th6;
novelContentInfo = a4;
randomAccessFile = randomAccessFile5;
String a322 = a(th);
nvQltRptBase.c().a(3, "excp10", a322);
nvQltRptBase.d(com.tencent.connect.common.Constants.VIA_ACT_TYPE_NINETEEN).f(a322);
a(randomAccessFile, "getContentBySerialId2:");
a(randomAccessFile2, "getContentBySerialId3:");
return novelContentInfo;
}
} catch (Throwable th7) {
th = th7;
randomAccessFile = randomAccessFile5;
novelContentInfo = null;
String a3222 = a(th);
nvQltRptBase.c().a(3, "excp10", a3222);
nvQltRptBase.d(com.tencent.connect.common.Constants.VIA_ACT_TYPE_NINETEEN).f(a3222);
a(randomAccessFile, "getContentBySerialId2:");
a(randomAccessFile2, "getContentBySerialId3:");
return novelContentInfo;
}
a(randomAccessFile2, "getContentBySerialId3:");
return novelContentInfo;
}
randomAccessFile3 = randomAccessFile5;
} else {
nvQltRptBase.c().a(3, 50);
randomAccessFile3 = null;
}
randomAccessFile2 = null;
novelContentInfo = null;
a(randomAccessFile3, "getContentBySerialId2:");
a(randomAccessFile2, "getContentBySerialId3:");
return novelContentInfo;
}
private boolean i(String str, int i) {
File file;
File file2;
File file3;
boolean exists;
boolean exists2;
boolean exists3;
Integer b2;
RandomAccessFile randomAccessFile;
try {
File a2 = this.m.f54693b.a(str);
file = new File(a2, str + "_index.dat");
file2 = new File(a2, str + "_content.dat");
file3 = new File(a2, str + "_info.dat");
exists = file.exists();
exists2 = file2.exists();
exists3 = file3.exists();
} catch (Throwable unused) {
}
if (!exists || !exists2 || !exists3 || (b2 = b(str, i)) == null) {
return false;
}
if (!this.i.containsKey(str)) {
ConcurrentHashMap<Integer, Integer[]> concurrentHashMap = new ConcurrentHashMap<>();
a(file, concurrentHashMap);
this.i.put(str, concurrentHashMap);
}
ConcurrentHashMap<Integer, Integer[]> concurrentHashMap2 = this.i.get(str);
if (!concurrentHashMap2.containsKey(b2)) {
return false;
}
Integer[] numArr = concurrentHashMap2.get(b2);
int intValue = numArr[2].intValue();
int intValue2 = numArr[3].intValue();
if (intValue2 != 0) {
byte[] bArr = new byte[intValue2];
try {
randomAccessFile = new RandomAccessFile(file3, "r");
} catch (Exception unused2) {
randomAccessFile = null;
} catch (Throwable th) {
th = th;
randomAccessFile = null;
}
try {
randomAccessFile.seek(intValue);
randomAccessFile.read(bArr, 0, intValue2);
new JSONObject(new String(bArr, "UTF-8"));
randomAccessFile.close();
int intValue3 = numArr[0].intValue();
int intValue4 = numArr[1].intValue();
return intValue4 != 0 && intValue3 >= 0 && ((long) intValue4) <= file2.length();
} catch (Exception unused3) {
if (randomAccessFile != null) {
randomAccessFile.close();
}
return false;
} catch (Throwable th2) {
th = th2;
if (randomAccessFile != null) {
randomAccessFile.close();
}
throw th;
}
}
return false;
}
protected abstract int a();
public int a(NovelContentInfo novelContentInfo, Integer num) {
BufferedOutputStream bufferedOutputStream;
int i = 1;
if (novelContentInfo == null || TextUtils.isEmpty(novelContentInfo.f54472a)) {
return 1;
}
File file = new File(this.m.f54693b.a(novelContentInfo.f), novelContentInfo.f54474c + ".novel");
BufferedOutputStream bufferedOutputStream2 = null;
if (novelContentInfo != null) {
try {
} catch (Throwable th) {
th = th;
}
if (!TextUtils.isEmpty(novelContentInfo.f54472a)) {
if (file.exists()) {
file.delete();
}
file.createNewFile();
byte[] bytes = b(novelContentInfo, num).toString().getBytes("UTF-8");
bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file));
try {
bufferedOutputStream.write(bytes);
bufferedOutputStream.flush();
i = 0;
} catch (Throwable th2) {
th = th2;
bufferedOutputStream2 = bufferedOutputStream;
try {
if (th instanceof IOException) {
if (th.toString().matches(".+\\W((ENOSPC)|([Nn]o\\sspace\\sleft\\son\\sdevice)).*")) {
i = 3;
}
}
if (bufferedOutputStream2 != null) {
bufferedOutputStream2.close();
}
return i;
} catch (Throwable th3) {
if (bufferedOutputStream2 != null) {
try {
bufferedOutputStream2.close();
} catch (Exception unused) {
}
}
throw th3;
}
}
if (bufferedOutputStream != null) {
bufferedOutputStream.close();
}
return i;
}
}
bufferedOutputStream = null;
i = 0;
if (bufferedOutputStream != null) {
}
return i;
}
int a(RandomAccessFile randomAccessFile, NovelChapterInfo novelChapterInfo) {
int i = 8;
try {
byte[] bytes = novelChapterInfo.j.getBytes("UTF-8");
try {
int length = 12 + bytes.length + 4 + 4;
try {
byte[] bytes2 = novelChapterInfo.f54470c.getBytes("UTF-8");
int length2 = length + 4 + bytes2.length;
byte[] bytes3 = novelChapterInfo.f54471d.getBytes("UTF-8");
int length3 = length2 + 4 + bytes3.length;
byte[] bytes4 = novelChapterInfo.e.getBytes("UTF-8");
length = length3 + 4;
i = length + bytes4.length + 4 + 4 + 8 + 8 + 4;
int i2 = i + 4;
randomAccessFile.write(ByteBuffer.allocate(i2).order(ByteOrder.BIG_ENDIAN).putInt(i).putInt(1).putInt(novelChapterInfo.f54469b).putInt(bytes.length).put(bytes).putInt(novelChapterInfo.k).putInt(novelChapterInfo.i).putInt(bytes2.length).put(bytes2).putInt(bytes3.length).put(bytes3).putInt(bytes4.length).put(bytes4).putFloat(novelChapterInfo.f).putInt(novelChapterInfo.g).putLong(novelChapterInfo.h).putLong(novelChapterInfo.l).putInt(novelChapterInfo.m).array());
return i2;
} catch (IOException unused) {
i = length;
return -(i + 4);
}
} catch (IOException unused2) {
i = 12;
}
} catch (IOException unused3) {
}
}
public int a(String str, int i, int i2, int i3, ArrayList<NovelChapterInfo> arrayList) {
int i4 = (i3 + i) - 1;
if (i4 <= i2) {
i2 = i4;
}
while (i <= i2) {
if (!this.g.containsKey(str + i) && !a(false, str, arrayList, i, 0)) {
break;
}
i++;
}
int i5 = i - 1;
if (i5 < 1) {
return 1;
}
return i5;
}
public DataIntTask a(NovelInfo novelInfo, final boolean z, final Map<Integer, Integer> map, final Handler handler, final Message message, final DataIntParams dataIntParams, ArrayList<NovelChapterInfo> arrayList, final Throwable th) {
final Stack stack = new Stack();
Integer.toHexString((short) (Math.random() * 32767.0d));
final Object[] a2 = NovelStatUtils.a(3);
final NovelInfo novelInfo2 = new NovelInfo();
novelInfo2.b(novelInfo);
DataIntTask dataIntTask = new DataIntTask() {
byte a() {
char c2;
String str;
int i;
String str2;
int i2;
if (!this.mCanceled) {
boolean z2 = (dataIntParams.f54269a & 1) != 0;
String str3 = novelInfo2.f36399b;
ArrayList<NovelChapterInfo> arrayList2 = this.m;
if (arrayList2 == null || arrayList2.size() <= 0) {
arrayList2 = NovelCacheBase.this.c(str3);
}
ArrayList<NovelChapterInfo> arrayList3 = arrayList2;
Stack stack2 = new Stack();
if (!this.mCanceled) {
int intValue = (dataIntParams.f54270b == null || dataIntParams.f54270b.intValue() <= 0) ? 1 : dataIntParams.f54270b.intValue();
int i3 = novelInfo2.r;
if (dataIntParams.f54271c != null) {
i3 = Math.min(dataIntParams.f54271c.intValue(), i3);
}
int i4 = i3;
int i5 = intValue;
while (true) {
if (i5 > i4) {
c2 = 2;
break;
}
if (this.mCanceled) {
return (byte) 6;
}
if (novelInfo2.R == null || novelInfo2.R.longValue() <= 0) {
str = str3;
} else {
str = str3;
if (i5 > novelInfo2.W) {
}
}
NovelChapterInfo a3 = NovelChapterInfo.a(i5, arrayList3);
if ((a3.k != 0 || a3.f54469b != 0 || !TextUtils.isEmpty(a3.f54468a)) && (novelInfo2.S == null || novelInfo2.S.longValue() <= 0 || i5 <= novelInfo2.W || a3.f <= 0.0f || map.containsKey(Integer.valueOf(a3.k)))) {
this.l = a3;
this.k = (((i5 - intValue) + 1) * 100.0f) / ((i4 - intValue) + 1);
fireObserverEvent(2);
if (z2) {
c2 = 2;
i = i4;
str2 = str;
i2 = i5;
if (NovelCacheBase.this.a(true, str, arrayList3, i5, dataIntParams.f54269a & 6)) {
continue;
i5 = i2 + 1;
str3 = str2;
i4 = i;
}
stack2.add(Integer.valueOf(i2));
if (dataIntParams.f54272d != null && dataIntParams.f54272d.intValue() > 0 && stack2.size() >= dataIntParams.f54272d.intValue()) {
break;
}
i5 = i2 + 1;
str3 = str2;
i4 = i;
} else {
i = i4;
c2 = 2;
Hashtable<String, NovelContentInfo> hashtable = NovelCacheBase.this.g;
StringBuilder sb = new StringBuilder();
str2 = str;
sb.append(str2);
i2 = i5;
sb.append(i2);
if (hashtable.containsKey(sb.toString())) {
continue;
i5 = i2 + 1;
str3 = str2;
i4 = i;
}
stack2.add(Integer.valueOf(i2));
if (dataIntParams.f54272d != null) {
break;
break;
}
continue;
i5 = i2 + 1;
str3 = str2;
i4 = i;
}
}
i2 = i5;
i = i4;
str2 = str;
i5 = i2 + 1;
str3 = str2;
i4 = i;
}
} else {
return (byte) 6;
}
} else {
return (byte) 6;
}
return (byte) 3;
}
@Override
public void cancel() {
if (this.mStatus < 3) {
this.mCanceled = true;
}
}
@Override
public void doRun() {
this.mNeedNotifyCanceled = true;
this.mStatus = (byte) 1;
fireObserverEvent(this.mStatus);
this.mStatus = a();
fireObserverEvent(this.mStatus);
if (this.mObservers != null) {
this.mObservers.clear();
}
}
};
dataIntTask.m = arrayList;
return dataIntTask;
}
public NovelContentInfo a(final String str, final int i, final INovelAsyncCallBack iNovelAsyncCallBack) {
if (iNovelAsyncCallBack == null) {
return c(str, i);
}
try {
this.f54234b.post(new Runnable() {
@Override
public void run() {
final NovelContentInfo c2 = NovelCacheBase.this.c(str, i);
NovelCacheBase.this.f54235c.post(new Runnable() {
@Override
public void run() {
iNovelAsyncCallBack.a(c2);
}
});
}
});
return null;
} catch (Exception unused) {
return null;
}
}
public String a(String str, int i, long j, int i2) {
if (!this.g.containsKey(str + i)) {
NovelContentInfo c2 = c(str, i);
return c2 != null ? c2.h : "";
}
NovelContentInfo novelContentInfo = this.g.get(str + i);
return novelContentInfo != null ? novelContentInfo.h : "";
}
public Map<Integer, Index> a(String str, StringBuilder sb) {
File file;
Header d2;
RandomAccessFile randomAccessFile;
long j;
int i = 0;
sb.append(0);
sb.append(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
if (!this.f.containsKey(str) || !this.f.get(str).booleanValue()) {
String hexString = Integer.toHexString((int) (Math.random() * 2.147483647E9d));
synchronized (this.e) {
if (!this.f.containsKey(str) || !this.f.get(str).booleanValue()) {
if (!this.e.containsKey(str)) {
sb.append(3);
sb.append(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
ConcurrentHashMap<Integer, Index> concurrentHashMap = new ConcurrentHashMap<>();
sb.append(4);
sb.append(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
this.e.put(str, concurrentHashMap);
sb.append(5);
sb.append(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
}
sb.append(5);
sb.append(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
RandomAccessFile randomAccessFile2 = null;
long j2 = 101;
try {
sb.append(6);
sb.append(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
File a2 = this.m.f54693b.a(str);
sb.append(7);
sb.append(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
file = new File(a2, str + Constants.ACCEPT_TIME_SEPARATOR_SERVER + ".indx");
sb.append(8);
sb.append(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
d2 = d(str);
sb.append(9);
sb.append(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
} catch (Throwable unused) {
}
if (file.exists() && d2 != null) {
sb.append(10);
sb.append(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
int i2 = d2.f54276d;
sb.append(11);
sb.append(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
long length = file.length();
sb.append(12);
sb.append(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
if (length > 0) {
sb.append(13);
sb.append(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
randomAccessFile = new RandomAccessFile(file, "r");
try {
sb.append(14);
sb.append(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
long j3 = 0;
while (i < i2) {
int readInt = randomAccessFile.readInt();
int readInt2 = randomAccessFile.readInt();
int readInt3 = randomAccessFile.readInt();
int i3 = i2;
randomAccessFile.skipBytes((readInt - 4) - 4);
long j4 = j2 + 1 + 1 + 1 + 1;
if (readInt2 == 1) {
j = j4 + 1;
this.e.get(str).put(Integer.valueOf(readInt3), new Index(readInt3, j3));
} else {
j = j4 + 1;
i--;
}
j2 = j + 1;
j3 += readInt + 4;
i++;
i2 = i3;
}
sb.append(j2);
sb.append(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
sb.append(15);
sb.append(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
randomAccessFile.close();
sb.append(16);
sb.append(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
} catch (Throwable unused2) {
randomAccessFile2 = randomAccessFile;
a(hexString, randomAccessFile2);
sb.append(17);
sb.append(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
this.f.put(str, true);
sb.append(18);
sb.append(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
return this.e.get(str);
}
} else {
randomAccessFile = null;
}
a(hexString, randomAccessFile);
sb.append(17);
sb.append(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
this.f.put(str, true);
sb.append(18);
sb.append(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
}
ConcurrentHashMap<Integer, Index> concurrentHashMap2 = this.e.get(str);
a(hexString, (RandomAccessFile) null);
return concurrentHashMap2;
}
}
}
return this.e.get(str);
}
public ConcurrentHashMap<Integer, Integer> a(HashMap<String, ConcurrentHashMap<Integer, Integer>> hashMap, String str) {
ConcurrentHashMap<Integer, Integer> concurrentHashMap;
synchronized (hashMap) {
concurrentHashMap = hashMap.containsKey(str) ? hashMap.get(str) : null;
if (concurrentHashMap == null) {
concurrentHashMap = new ConcurrentHashMap<>();
hashMap.put(str, concurrentHashMap);
}
}
return concurrentHashMap;
}
public void a(DataIntTask dataIntTask) {
this.f54233a.post(dataIntTask);
}
void a(final Header header) {
if (this.h.containsKey(header.f54273a)) {
this.h.get(header.f54273a).a(header);
}
final File file = new File(this.m.f54693b.a(header.f54273a), header.f54273a + "file_header.header");
final NovelBehaviourRecorder.Recorder c2 = new NvQltRptBase(this.m.g, 7, header.f54273a).c();
if (file.exists()) {
this.f54233a.post(new Runnable() {
@Override
public void run() {
RandomAccessFile randomAccessFile;
Exception e;
try {
randomAccessFile = new RandomAccessFile(file, "rw");
try {
try {
randomAccessFile.writeUTF(header.f54273a);
randomAccessFile.writeUTF(header.f54274b);
randomAccessFile.writeInt(header.f54275c);
randomAccessFile.writeInt(header.f54276d);
randomAccessFile.writeInt(header.e);
randomAccessFile.close();
c2.a(7, header, "fin");
} catch (Exception e2) {
e = e2;
if (!NovelInfo.a(header.f54273a)) {
c2.a(7, header, e);
}
NovelCacheBase.this.a(randomAccessFile, "updataHeaderFile2:");
}
} catch (Throwable th) {
th = th;
NovelCacheBase.this.a(randomAccessFile, "updataHeaderFile2:");
throw th;
}
} catch (Exception e3) {
randomAccessFile = null;
e = e3;
} catch (Throwable th2) {
th = th2;
randomAccessFile = null;
NovelCacheBase.this.a(randomAccessFile, "updataHeaderFile2:");
throw th;
}
NovelCacheBase.this.a(randomAccessFile, "updataHeaderFile2:");
}
});
} else {
if (NovelInfo.a(header.f54273a)) {
return;
}
c2.a(7, header, "!exists");
}
}
public void a(final NovelInfo novelInfo) {
final String str = novelInfo.f36399b;
final File file = new File(this.m.f54693b.a(str), str + "file_header.header");
if (!file.exists() || d(str) == null) {
Header header = new Header();
header.f54273a = str;
header.f54274b = novelInfo.f36400c;
header.f54275c = 2;
header.f54276d = 0;
header.e = 0;
if (!this.h.containsKey(str)) {
this.h.put(str, header);
}
this.f54233a.post(new Runnable() {
@Override
public void run() {
RandomAccessFile randomAccessFile;
Throwable th;
try {
file.createNewFile();
randomAccessFile = new RandomAccessFile(file, "rw");
try {
randomAccessFile.writeUTF(str);
randomAccessFile.writeUTF(novelInfo.f36400c);
randomAccessFile.writeInt(2);
randomAccessFile.writeInt(0);
randomAccessFile.writeInt(0);
randomAccessFile.close();
} catch (Exception unused) {
} catch (Throwable th2) {
th = th2;
NovelCacheBase.this.a(randomAccessFile, "createHeaderFile2:");
throw th;
}
} catch (Exception unused2) {
randomAccessFile = null;
} catch (Throwable th3) {
randomAccessFile = null;
th = th3;
}
NovelCacheBase.this.a(randomAccessFile, "createHeaderFile2:");
}
});
}
}
public void a(File file, ConcurrentHashMap<Integer, Integer[]> concurrentHashMap) {
RandomAccessFile randomAccessFile;
try {
randomAccessFile = new RandomAccessFile(file, "r");
try {
int length = (int) (randomAccessFile.length() / 20);
for (int i = 0; i < length; i++) {
concurrentHashMap.put(Integer.valueOf(randomAccessFile.readInt()), new Integer[]{Integer.valueOf(randomAccessFile.readInt()), Integer.valueOf(randomAccessFile.readInt()), Integer.valueOf(randomAccessFile.readInt()), Integer.valueOf(randomAccessFile.readInt())});
}
} catch (EOFException unused) {
if (randomAccessFile == null) {
return;
}
randomAccessFile.close();
} catch (IOException unused2) {
if (randomAccessFile == null) {
return;
}
randomAccessFile.close();
} catch (Exception unused3) {
if (randomAccessFile == null) {
return;
}
randomAccessFile.close();
} catch (Throwable th) {
th = th;
if (randomAccessFile != null) {
try {
randomAccessFile.close();
} catch (IOException unused4) {
}
}
throw th;
}
} catch (EOFException unused5) {
randomAccessFile = null;
} catch (IOException unused6) {
randomAccessFile = null;
} catch (Exception unused7) {
randomAccessFile = null;
} catch (Throwable th2) {
th = th2;
randomAccessFile = null;
}
try {
randomAccessFile.close();
} catch (IOException unused8) {
}
}
public void a(String str) {
String str2;
File[] listFiles;
try {
str2 = WebEngine.e().a("http://book.soso.com", WebEngine.H5ApplicationCacheType.Persistent);
} catch (Exception unused) {
str2 = null;
}
if (TextUtils.isEmpty(str2) || (listFiles = new File(str2).listFiles()) == null || listFiles.length <= 0) {
return;
}
for (File file : listFiles) {
if (file != null && file.isDirectory()) {
String name = file.getName();
if (!TextUtils.isEmpty(name) && str.equals(name)) {
FileUtils.d(file);
}
}
}
}
public void a(final String str, int i, final String str2, final ArrayList<NovelChapterInfo> arrayList, final boolean z, final int i2, final Stack<Integer> stack, final NovelDataListener novelDataListener, final IChapterSaveInteface iChapterSaveInteface) {
final NovelBehaviourRecorder.Recorder c2 = new NvQltRptBase(this.m.g, 7, str).c();
c2.a(6, "s10", Boolean.valueOf(z), Integer.valueOf(i2), NovelStatUtils.a((List<Integer>) stack, true), NovelStatUtils.a(arrayList));
final long currentTimeMillis = System.currentTimeMillis();
Math.random();
this.f54233a.post(new Runnable() {
@Override
public void run() {
String str3;
RandomAccessFile randomAccessFile;
Header header;
RandomAccessFile randomAccessFile2;
int i3;
int i4;
File a2;
File file;
int i5;
NovelChapterInfo novelChapterInfo;
int i6;
ArrayList arrayList2;
Header header2;
RandomAccessFile randomAccessFile3;
int i7;
int i8;
int i9;
ArrayList arrayList3;
RandomAccessFile randomAccessFile4;
int size = arrayList.size();
c2.a(6, "s20", Integer.valueOf(i2), Long.valueOf(System.currentTimeMillis() - currentTimeMillis));
String str4 = "0";
if (size <= 0) {
if (i2 > 0) {
new NvQltRptBase(NovelCacheBase.this.m.g, 7, str).c("18").e("chpSize=" + size).a("0");
return;
}
return;
}
ArrayList arrayList4 = new ArrayList();
try {
a2 = NovelCacheBase.this.m.f54693b.a(str);
file = new File(a2, str + Constants.ACCEPT_TIME_SEPARATOR_SERVER + ".indx");
header = NovelCacheBase.this.d(str);
try {
} catch (Throwable th) {
th = th;
str3 = "0";
}
} catch (Throwable th2) {
th = th2;
str3 = "0";
randomAccessFile = null;
header = null;
randomAccessFile2 = null;
}
if (header == null) {
if (i2 > 0) {
new NvQltRptBase(NovelCacheBase.this.m.g, 7, str).c("18").e("headerInfo=null").a("0");
return;
}
return;
}
try {
if (!file.exists()) {
file.createNewFile();
}
i5 = header.f54276d;
novelChapterInfo = (NovelChapterInfo) arrayList.get(0);
} catch (Throwable th3) {
th = th3;
str3 = "0";
randomAccessFile = null;
randomAccessFile2 = null;
}
if (novelChapterInfo == null) {
if (i2 > 0) {
new NvQltRptBase(NovelCacheBase.this.m.g, 7, str).c("18").e("get(0)=null").a("0");
return;
}
return;
}
if (z) {
try {
File file2 = new File(a2, str + Constants.ACCEPT_TIME_SEPARATOR_SERVER + ".tempIndx");
if (!file2.exists()) {
file2.createNewFile();
}
randomAccessFile = new RandomAccessFile(file2, "rw");
try {
StringBuilder sb = new StringBuilder();
sb.append("saveChapters-");
NovelCacheBase.this.a(str, sb).clear();
NovelCacheBase.this.a(NovelCacheBase.this.j, str).clear();
ArrayList arrayList5 = new ArrayList();
StringBuilder sb2 = new StringBuilder();
Iterator it = arrayList.iterator();
long j = 0;
i3 = 0;
int i10 = 0;
while (true) {
try {
if (!it.hasNext()) {
str3 = str4;
i6 = i5;
arrayList2 = arrayList4;
header2 = header;
break;
}
Iterator it2 = it;
NovelChapterInfo novelChapterInfo2 = (NovelChapterInfo) it.next();
str3 = str4;
try {
ConcurrentHashMap<String, JSONObject> concurrentHashMap = NovelCacheBase.this.f54236d;
header2 = header;
try {
StringBuilder sb3 = new StringBuilder();
i6 = i5;
sb3.append(novelChapterInfo2.f54468a);
sb3.append(novelChapterInfo2.f54469b);
boolean containsKey = concurrentHashMap.containsKey(sb3.toString());
if (novelChapterInfo2.k <= 0) {
arrayList4.add(Integer.valueOf(novelChapterInfo2.f54469b));
}
if (containsKey) {
JSONObject jSONObject = NovelCacheBase.this.f54236d.get(novelChapterInfo2.f54468a + novelChapterInfo2.f54469b);
arrayList2 = arrayList4;
novelChapterInfo2.l = jSONObject.getLong("start");
novelChapterInfo2.m = jSONObject.getInt("length");
NovelCacheBase.this.f54236d.remove(novelChapterInfo2.f54468a + novelChapterInfo2.f54469b);
} else {
arrayList2 = arrayList4;
}
int a3 = NovelCacheBase.this.a(randomAccessFile, novelChapterInfo2);
int i11 = i10 + 1;
if (i11 >= 300) {
sb2.setLength(0);
arrayList5.clear();
i10 = 0;
} else {
arrayList5.add(Integer.valueOf(novelChapterInfo2.f54469b));
sb2.append(a3);
sb2.append(Constants.ACCEPT_TIME_SEPARATOR_SP);
i10 = i11;
}
if (a3 <= 0) {
break;
}
StringBuilder sb4 = new StringBuilder();
sb4.append("saveChapters-");
NovelCacheBase.this.a(str, sb4).put(Integer.valueOf(novelChapterInfo2.f54469b), new Index(novelChapterInfo2.f54469b, j));
NovelCacheBase.this.a(NovelCacheBase.this.j, str).put(Integer.valueOf(novelChapterInfo2.k), Integer.valueOf(novelChapterInfo2.f54469b));
NovelCacheBase.this.a(NovelCacheBase.this.k, str).put(Integer.valueOf(novelChapterInfo2.f54469b), Integer.valueOf(novelChapterInfo2.k));
j += a3;
i3++;
str4 = str3;
it = it2;
header = header2;
i5 = i6;
arrayList4 = arrayList2;
arrayList5 = arrayList5;
} catch (Throwable th4) {
th = th4;
header = header2;
randomAccessFile2 = null;
try {
if (i2 > 0) {
new NvQltRptBase(NovelCacheBase.this.m.g, 7, str).c(com.tencent.connect.common.Constants.VIA_ACT_TYPE_NINETEEN).e("savChpsFail.excp=" + th.toString()).a(str3);
}
if (randomAccessFile2 != null) {
try {
randomAccessFile2.close();
} catch (Exception unused) {
i4 = i3;
if (i4 <= 0) {
}
}
}
i4 = i3;
if (i4 <= 0) {
}
} finally {
if (randomAccessFile2 != null) {
try {
randomAccessFile2.close();
} catch (Exception unused2) {
}
}
if (randomAccessFile != null) {
randomAccessFile.close();
}
}
}
} catch (Throwable th5) {
th = th5;
randomAccessFile2 = null;
if (i2 > 0) {
}
i4 = i3;
if (i4 <= 0) {
}
}
} catch (Throwable th6) {
th = th6;
str3 = str4;
}
}
randomAccessFile.close();
c2.a(6, "s25", Boolean.valueOf(file.delete()), Boolean.valueOf(file2.renameTo(new File(a2, str + Constants.ACCEPT_TIME_SEPARATOR_SERVER + ".indx"))));
randomAccessFile3 = randomAccessFile;
i7 = i3;
i8 = size;
i9 = i6;
arrayList3 = arrayList2;
} catch (Throwable th7) {
th = th7;
str3 = "0";
randomAccessFile2 = null;
i3 = 0;
if (i2 > 0) {
}
i4 = i3;
if (i4 <= 0) {
}
}
} catch (Throwable th8) {
th = th8;
str3 = "0";
randomAccessFile = null;
randomAccessFile2 = null;
i3 = 0;
if (i2 > 0) {
}
i4 = i3;
if (i4 <= 0) {
}
}
} else {
str3 = "0";
ArrayList arrayList6 = arrayList4;
header2 = header;
try {
} catch (Throwable th9) {
th = th9;
randomAccessFile = null;
randomAccessFile2 = null;
header = header2;
i3 = 0;
if (i2 > 0) {
}
i4 = i3;
if (i4 <= 0) {
}
}
if (novelChapterInfo.f54469b - i5 == 1) {
try {
randomAccessFile4 = new RandomAccessFile(file, "rw");
long j2 = 0;
i9 = i5;
for (int i12 = 0; i12 < i9; i12++) {
try {
randomAccessFile4.seek(j2);
j2 += randomAccessFile4.readInt() + 4;
} catch (Throwable th10) {
th = th10;
i3 = i9;
randomAccessFile2 = randomAccessFile4;
header = header2;
randomAccessFile = null;
if (i2 > 0) {
}
i4 = i3;
if (i4 <= 0) {
}
}
}
randomAccessFile4.seek(j2);
long j3 = j2;
i7 = i9;
i8 = size;
int i13 = 0;
while (true) {
if (i13 >= i8) {
arrayList3 = arrayList6;
break;
}
try {
NovelChapterInfo novelChapterInfo3 = (NovelChapterInfo) arrayList.get(i13);
boolean containsKey2 = NovelCacheBase.this.f54236d.containsKey(novelChapterInfo3.f54468a + novelChapterInfo3.f54469b);
if (novelChapterInfo3.k <= 0) {
arrayList3 = arrayList6;
arrayList3.add(Integer.valueOf(novelChapterInfo3.f54469b));
} else {
arrayList3 = arrayList6;
}
if (containsKey2) {
JSONObject jSONObject2 = NovelCacheBase.this.f54236d.get(novelChapterInfo3.f54468a + novelChapterInfo3.f54469b);
novelChapterInfo3.l = jSONObject2.getLong("start");
novelChapterInfo3.m = jSONObject2.getInt("length");
NovelCacheBase.this.f54236d.remove(novelChapterInfo3.f54468a + novelChapterInfo3.f54469b);
}
int a4 = NovelCacheBase.this.a(randomAccessFile4, novelChapterInfo3);
if (a4 <= 0) {
break;
}
StringBuilder sb5 = new StringBuilder();
sb5.append("saveChapters-");
NovelCacheBase.this.a(str, sb5).put(Integer.valueOf(novelChapterInfo3.f54469b), new Index(novelChapterInfo3.f54469b, j3));
NovelCacheBase.this.a(NovelCacheBase.this.j, str).put(Integer.valueOf(novelChapterInfo3.k), Integer.valueOf(novelChapterInfo3.f54469b));
NovelCacheBase.this.a(NovelCacheBase.this.k, str).put(Integer.valueOf(novelChapterInfo3.f54469b), Integer.valueOf(novelChapterInfo3.k));
j3 += a4;
i7++;
i13++;
arrayList6 = arrayList3;
} catch (Throwable th11) {
th = th11;
i3 = i7;
randomAccessFile2 = randomAccessFile4;
header = header2;
randomAccessFile = null;
if (i2 > 0) {
}
i4 = i3;
if (i4 <= 0) {
}
}
}
randomAccessFile4.close();
randomAccessFile3 = null;
if (i2 > 0) {
c2.a(6, "s30", header2, Integer.valueOf(i7), NovelStatUtils.a((List<Integer>) arrayList3, true), Integer.valueOf(i2), Boolean.valueOf(z), Integer.valueOf(i8), Integer.valueOf(i9));
NovelCallBackData novelCallBackData = new NovelCallBackData(true, 13, null);
novelCallBackData.f = str;
novelCallBackData.C = i2;
if (!z) {
if (i7 == 0) {
i8 = 0;
}
i8 += i9;
}
novelCallBackData.E = i8;
novelCallBackData.L = stack;
novelDataListener.a(novelCallBackData);
}
if (iChapterSaveInteface != null) {
ChapterSaveCallBack chapterSaveCallBack = new ChapterSaveCallBack();
chapterSaveCallBack.f54193a = str;
chapterSaveCallBack.f54194b = 0;
iChapterSaveInteface.a(chapterSaveCallBack);
}
if (randomAccessFile4 != null) {
try {
randomAccessFile4.close();
} catch (Exception unused3) {
}
}
if (randomAccessFile3 != null) {
randomAccessFile3.close();
}
i4 = i7;
header = header2;
} catch (Throwable th12) {
th = th12;
i3 = i5;
header = header2;
randomAccessFile = null;
randomAccessFile2 = null;
if (i2 > 0) {
}
i4 = i3;
if (i4 <= 0) {
}
}
if (i4 <= 0) {
NovelCacheBase.this.a(new Header(str, str2, 2, i4, header.e));
return;
}
return;
}
i8 = size;
i9 = i5;
arrayList3 = arrayList6;
randomAccessFile3 = null;
i7 = 0;
}
randomAccessFile4 = null;
if (i2 > 0) {
}
if (iChapterSaveInteface != null) {
}
if (randomAccessFile4 != null) {
}
if (randomAccessFile3 != null) {
}
i4 = i7;
header = header2;
if (i4 <= 0) {
}
}
});
}
public void a(String str, NovelContentInfo novelContentInfo, boolean z, IContentSaveInteface iContentSaveInteface) {
a(str, novelContentInfo, z, iContentSaveInteface, 0, 0, 0, false, false, true, null);
}
public void a(String str, NovelContentInfo novelContentInfo, boolean z, IContentSaveInteface iContentSaveInteface, int i, int i2, int i3, boolean z2, boolean z3, boolean z4, Integer num) {
String str2;
NvQltRptBase nvQltRptBase;
String str3;
NvQltRptBase e;
NvQltRptBase a2;
a(novelContentInfo, z, i, i2, i3, z2, z3);
if (novelContentInfo == null) {
if (z) {
a2 = new NvQltRptBase(this.m.g, 7, str).c(com.tencent.connect.common.Constants.VIA_REPORT_TYPE_DATALINE).e("con=null");
a2.a("0");
}
if (a(iContentSaveInteface, i)) {
ContentSaveCallBack contentSaveCallBack = new ContentSaveCallBack();
contentSaveCallBack.f = 1;
contentSaveCallBack.f54195a = str;
contentSaveCallBack.f54196b = novelContentInfo.f54473b;
contentSaveCallBack.g = false;
contentSaveCallBack.h = i;
contentSaveCallBack.i = i3;
contentSaveCallBack.j = z2;
contentSaveCallBack.k = z3;
contentSaveCallBack.l = z4;
contentSaveCallBack.m = 2;
contentSaveCallBack.e = z ? 1 : 0;
iContentSaveInteface.a(contentSaveCallBack);
return;
}
return;
}
if (NovelUtils.a(novelContentInfo.m)) {
if (z) {
e = new NvQltRptBase(this.m.g, 7, str).c(com.tencent.connect.common.Constants.VIA_REPORT_TYPE_DATALINE).e("IsPayBook:" + novelContentInfo.m);
a2 = e.a(novelContentInfo);
}
if (a(iContentSaveInteface, i)) {
}
} else {
if (z) {
a(str, novelContentInfo);
}
if (novelContentInfo.f54474c <= 0) {
a(this.j, str).containsKey(Integer.valueOf(novelContentInfo.f54474c));
a(this.k, str).containsKey(Integer.valueOf(novelContentInfo.f54473b));
if (!NovelInfo.a(novelContentInfo.f) && z) {
str2 = "" + novelContentInfo.f54473b + "_" + novelContentInfo.e + "_" + novelContentInfo.l + "_" + novelContentInfo.h;
nvQltRptBase = new NvQltRptBase(this.m.g, 7, str);
str3 = com.tencent.connect.common.Constants.VIA_REPORT_TYPE_CHAT_AIO;
e = nvQltRptBase.c(str3).e(str2);
}
if (a(iContentSaveInteface, i)) {
}
} else {
if (!TextUtils.isEmpty(novelContentInfo.f54472a)) {
this.g.put(str + novelContentInfo.f54473b, novelContentInfo);
a(str, novelContentInfo, z, iContentSaveInteface, i, i3, z2, z3, z4, num);
return;
}
if (!NovelInfo.a(novelContentInfo.f) && z) {
str2 = "" + novelContentInfo.f54473b + "_" + novelContentInfo.f54474c + "_" + novelContentInfo.h;
nvQltRptBase = new NvQltRptBase(this.m.g, 7, str);
str3 = com.tencent.connect.common.Constants.VIA_REPORT_TYPE_CHAT_AUDIO;
e = nvQltRptBase.c(str3).e(str2);
}
if (a(iContentSaveInteface, i)) {
}
}
a2 = e.a(novelContentInfo);
}
a2.a("0");
if (a(iContentSaveInteface, i)) {
}
}
public void a(final String str, final ArrayList<NovelChapterInfo> arrayList, final INovelAsyncCallBack iNovelAsyncCallBack) {
this.f54233a.post(new Runnable() {
@Override
public void run() {
ArrayList arrayList2 = arrayList;
iNovelAsyncCallBack.a((arrayList2 == null || arrayList2.size() <= 0) ? NovelCacheBase.this.c(str) : arrayList);
}
});
}
public void a(final String str, boolean z) {
BrowserExecutorSupplier.BackgroundRunable backgroundRunable = new BrowserExecutorSupplier.BackgroundRunable() {
@Override
public void doRun() {
try {
FileUtils.a(NovelCacheBase.this.m.f54693b.a(str));
} catch (Exception unused) {
}
}
};
if (z) {
BrowserExecutorSupplier.postForIoTasks(backgroundRunable);
} else {
backgroundRunable.run();
}
if (a() < 4) {
a(str);
}
}
public boolean a(String str, int i) {
String str2;
StringBuilder sb;
String str3;
if (i == 1) {
sb = new StringBuilder();
sb.append(str);
sb.append(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
str3 = ".indx";
} else if (i == 2) {
sb = new StringBuilder();
sb.append(str);
sb.append(Constants.ACCEPT_TIME_SEPARATOR_SERVER);
str3 = ".newContent";
} else {
if (i != 3) {
str2 = "";
return a(str, str2);
}
sb = new StringBuilder();
sb.append(str);
sb.append("file_header");
str3 = ".header";
}
sb.append(str3);
str2 = sb.toString();
return a(str, str2);
}
public boolean a(String str, int i, int i2) {
if (a(str, 2)) {
return true;
}
if (a() < 4) {
if (a(str, i + ".json")) {
return true;
}
if (a(str, i2 + ".json")) {
return true;
}
}
StringBuilder sb = new StringBuilder();
sb.append(i2);
sb.append(".novel");
return a(str, sb.toString()) || i <= 0 || i2 <= 0;
}
public boolean a(String str, String str2) {
File a2;
try {
if (TextUtils.isEmpty(str2) || (a2 = this.m.f54693b.a(str)) == null) {
return false;
}
return new File(a2, str2).exists();
} catch (Exception unused) {
return false;
}
}
public boolean a(boolean z, String str, ArrayList<NovelChapterInfo> arrayList, int i, int i2) {
try {
boolean a2 = a() < 4 ? a(str, i, z, (i2 & 2) != 0, arrayList) : false;
for (int i3 = 4; i3 >= a() && !a2; i3--) {
try {
File c2 = c(str, i, i3);
if (c2 != null && c2.exists()) {
if ((i2 & 4) != 0) {
NovelContentInfo b2 = b(str, i, i3);
if (z) {
if (z) {
if (b2 != null) {
if (b2.k != 1) {
}
}
}
}
} else {
a2 = c2.length() > 0;
}
}
} catch (Throwable unused) {
return a2;
}
}
return !a2 ? i(str, i) : a2;
} catch (Throwable unused2) {
return false;
}
}
NovelContentInfo b(String str, int i, int i2) {
NvQltRptBase nvQltRptBase = new NvQltRptBase(this.m.g, 3, str + Constants.ACCEPT_TIME_SEPARATOR_SERVER + i);
nvQltRptBase.c().a(5, 10, str, Integer.valueOf(i), Integer.valueOf(i2));
if (i2 == 1) {
return f(str, i);
}
if (i2 == 2) {
return d(str, i, i2);
}
Integer b2 = b(str, i);
nvQltRptBase.c().a(5, 20, b2);
if (b2 != null) {
return d(str, b2.intValue(), i2);
}
return null;
}
public Integer b(String str, int i) {
ConcurrentHashMap<Integer, Integer> a2 = a(this.k, str);
boolean containsKey = a2.containsKey(Integer.valueOf(i));
Integer d2 = containsKey ? a2.get(Integer.valueOf(i)) : d(str, i);
new NvQltRptBase(this.m.g, 3, str + Constants.ACCEPT_TIME_SEPARATOR_SERVER + i).c().a(6, 10, str, Integer.valueOf(i), Boolean.valueOf(containsKey), d2, NovelStatUtils.a(2));
if (d2 != null) {
a2.put(Integer.valueOf(i), d2);
a(this.j, str).put(d2, Integer.valueOf(i));
}
return d2;
}
public JSONObject b(NovelContentInfo novelContentInfo, Integer num) throws JSONException {
JSONObject jSONObject = new JSONObject();
jSONObject.put("resourceid", novelContentInfo.f);
jSONObject.put("serialurl", novelContentInfo.f54475d);
jSONObject.put("serialid", novelContentInfo.f54473b);
jSONObject.put("serialmd5", novelContentInfo.e);
jSONObject.put("serialname", novelContentInfo.h);
jSONObject.put("booktitle", novelContentInfo.g);
jSONObject.put("contentOnline", novelContentInfo.k);
jSONObject.put("contentUuid", novelContentInfo.l);
jSONObject.put("seriallastmodifytime", novelContentInfo.j);
jSONObject.put("serialsitename", novelContentInfo.i);
jSONObject.put("chapterid", novelContentInfo.f54474c);
jSONObject.put("conpayret", novelContentInfo.m);
jSONObject.put("conpaymsg", novelContentInfo.n);
jSONObject.put("conpayprice", novelContentInfo.o);
jSONObject.put("conchpprice", novelContentInfo.r);
jSONObject.put("conpbookrice", novelContentInfo.s);
jSONObject.put("conpaybanlance", novelContentInfo.p);
jSONObject.put("conpaybanlancefree", novelContentInfo.q);
jSONObject.put("conpayintegrity", novelContentInfo.t);
jSONObject.put("concuruser", ((IAccount) SDKContext.getInstance().getService(IAccount.class)).getCurrentUserInfo().getQQorWxId());
jSONObject.put("serialcontent", a(novelContentInfo, jSONObject, num));
return jSONObject;
}
public boolean b(String str) {
String[] list;
try {
File a2 = this.m.f54693b.a(str);
if (a2 == null || !a2.isDirectory() || (list = a2.list()) == null) {
return false;
}
return list.length > 0;
} catch (Exception unused) {
return false;
}
}
public NovelContentInfo c(String str, int i) {
System.currentTimeMillis();
NovelContentInfo novelContentInfo = this.g.containsKey(str + i) ? this.g.get(str + i) : null;
if (novelContentInfo == null && a() < 4) {
novelContentInfo = h(str, i);
}
if (novelContentInfo == null) {
novelContentInfo = g(str, i);
}
for (byte b2 = 4; b2 >= a() && novelContentInfo == null; b2 = (byte) (b2 - 1)) {
novelContentInfo = b(str, i, b2);
}
return novelContentInfo;
}
File c(String str, int i, int i2) {
File a2 = this.m.f54693b.a(str);
if (i2 <= 2) {
return new File(a2, i + ".json");
}
Integer b2 = b(str, i);
if (b2 == null) {
return null;
}
if (i2 < 4) {
return new File(a2, b2 + ".json");
}
return new File(a2, b2 + ".novel");
}
public ArrayList<NovelChapterInfo> c(String str) {
Header header;
File file;
ArrayList<NovelChapterInfo> arrayList = new ArrayList<>();
RandomAccessFile randomAccessFile = null;
try {
header = d(str);
} catch (Throwable unused) {
header = null;
}
if (header == null) {
a((RandomAccessFile) null, "getChapters2:");
return arrayList;
}
try {
file = new File(this.m.f54693b.a(str), str + Constants.ACCEPT_TIME_SEPARATOR_SERVER + ".indx");
} catch (Throwable unused2) {
}
if (!file.exists()) {
a((RandomAccessFile) null, "getChapters2:");
return arrayList;
}
if (((int) file.length()) > 0) {
RandomAccessFile randomAccessFile2 = new RandomAccessFile(file, "r");
long j = 0;
try {
int i = header.f54276d;
while (i > 0) {
try {
randomAccessFile2.seek(j);
int readInt = randomAccessFile2.readInt();
int readInt2 = randomAccessFile2.readInt();
int readInt3 = randomAccessFile2.readInt();
if (readInt2 == 1) {
NovelChapterInfo a2 = a(randomAccessFile2, str, readInt3);
if (a2 == null) {
break;
}
arrayList.add(a2);
a(this.j, str).put(Integer.valueOf(a2.k), Integer.valueOf(a2.f54469b));
a(this.k, str).put(Integer.valueOf(a2.f54469b), Integer.valueOf(a2.k));
i--;
}
j += readInt + 4;
} catch (Throwable th) {
Logs.a("NovelCacheBase", th);
}
}
randomAccessFile = randomAccessFile2;
} catch (Throwable unused3) {
randomAccessFile = randomAccessFile2;
}
}
Collections.sort(arrayList, new MyComparator());
a(str, arrayList);
a(randomAccessFile, "getChapters2:");
if (arrayList.size() != header.f54276d) {
header.f54276d = arrayList.size();
a(header);
}
return arrayList;
}
public Header d(String str) {
RandomAccessFile randomAccessFile;
if (this.h.containsKey(str)) {
return this.h.get(str);
}
File file = new File(this.m.f54693b.a(str), str + "file_header.header");
RandomAccessFile exists = file.exists();
try {
if (exists == 0) {
Logs.e("NovelCacheBase", "header file miss:" + NovelUtils.c(1000));
return null;
}
try {
randomAccessFile = new RandomAccessFile(file, "r");
try {
Header header = new Header();
header.f54273a = randomAccessFile.readUTF();
header.f54274b = randomAccessFile.readUTF();
header.f54275c = randomAccessFile.readInt();
header.f54276d = randomAccessFile.readInt();
header.e = randomAccessFile.readInt();
this.h.put(str, header);
a(randomAccessFile, "getHeaderInfo2:");
return header;
} catch (Exception unused) {
e(str);
a(randomAccessFile, "getHeaderInfo2:");
return null;
}
} catch (Exception unused2) {
randomAccessFile = null;
} catch (Throwable th) {
th = th;
exists = 0;
a(exists, "getHeaderInfo2:");
throw th;
}
} catch (Throwable th2) {
th = th2;
}
}
public Integer d(String str, int i) {
RandomAccessFile randomAccessFile;
Integer num;
Integer num2;
NvQltRptBase nvQltRptBase = new NvQltRptBase(this.m.g, 3, str + Constants.ACCEPT_TIME_SEPARATOR_SERVER + i);
RandomAccessFile randomAccessFile2 = null;
try {
File file = new File(this.m.f54693b.a(str), str + Constants.ACCEPT_TIME_SEPARATOR_SERVER + ".indx");
if (file.exists()) {
randomAccessFile = new RandomAccessFile(file, "r");
try {
StringBuilder sb = new StringBuilder();
if (a(str, sb).containsKey(Integer.valueOf(i))) {
long j = a(str, sb).get(Integer.valueOf(i)).f54278b;
randomAccessFile.seek(j);
randomAccessFile.readInt();
int readInt = randomAccessFile.readInt();
int readInt2 = randomAccessFile.readInt();
nvQltRptBase.c().a(7, 20, Integer.valueOf(i), Long.valueOf(j), Integer.valueOf(readInt), Integer.valueOf(readInt2));
if (readInt == 1) {
num2 = Integer.valueOf(b(randomAccessFile, str, readInt2).k);
} else {
nvQltRptBase.c(com.tencent.connect.common.Constants.VIA_REPORT_TYPE_DATALINE).e("validate");
num2 = null;
}
num = num2;
} else {
nvQltRptBase.c().a(7, 30);
nvQltRptBase.c(com.tencent.connect.common.Constants.VIA_REPORT_TYPE_DATALINE).e("containsKey");
num = null;
}
try {
randomAccessFile.close();
} catch (Exception unused) {
}
return num;
} catch (Exception e) {
e = e;
randomAccessFile2 = randomAccessFile;
} catch (Throwable th) {
th = th;
if (randomAccessFile != null) {
}
throw th;
}
} else {
try {
try {
nvQltRptBase.c().a(7, 10);
nvQltRptBase.c(com.tencent.connect.common.Constants.VIA_REPORT_TYPE_JOININ_GROUP).e("2");
return null;
} catch (Exception e2) {
e = e2;
}
} catch (Throwable th2) {
th = th2;
randomAccessFile = randomAccessFile2;
if (randomAccessFile != null) {
try {
randomAccessFile.close();
} catch (Exception unused2) {
}
}
throw th;
}
}
} catch (Exception e3) {
e = e3;
randomAccessFile2 = null;
} catch (Throwable th3) {
th = th3;
randomAccessFile = null;
}
nvQltRptBase.c().a(7, "excp10", e.toString());
nvQltRptBase.c(com.tencent.connect.common.Constants.VIA_REPORT_TYPE_DATALINE).e(e.toString() + "@" + NovelStatUtils.a(e.getStackTrace()));
if (randomAccessFile2 != null) {
try {
randomAccessFile2.close();
} catch (Exception unused3) {
}
}
return null;
}
public NovelChapterInfo e(String str, int i) {
Header d2;
NovelChapterInfo novelChapterInfo = new NovelChapterInfo();
RandomAccessFile randomAccessFile = null;
try {
d2 = d(str);
} catch (Throwable unused) {
}
if (d2 == null) {
a((RandomAccessFile) null, "getChapter2:");
return novelChapterInfo;
}
int i2 = d2.f54276d;
if (i2 < i) {
a((RandomAccessFile) null, "getChapter2:");
return novelChapterInfo;
}
File file = new File(this.m.f54693b.a(str), str + Constants.ACCEPT_TIME_SEPARATOR_SERVER + ".indx");
if (!file.exists()) {
a((RandomAccessFile) null, "getChapter2:");
return novelChapterInfo;
}
if (((int) file.length()) > 0) {
RandomAccessFile randomAccessFile2 = new RandomAccessFile(file, "r");
long j = 0;
int i3 = 0;
while (true) {
if (i3 >= i2) {
break;
}
try {
randomAccessFile2.seek(j);
int readInt = randomAccessFile2.readInt();
int readInt2 = randomAccessFile2.readInt();
int readInt3 = randomAccessFile2.readInt();
if (readInt2 == 0) {
i3--;
} else if (readInt3 == i) {
novelChapterInfo = b(randomAccessFile2, str, i);
break;
}
j += readInt + 4;
i3++;
} catch (Throwable unused2) {
}
}
randomAccessFile2.close();
randomAccessFile = randomAccessFile2;
}
a(randomAccessFile, "getChapter2:");
return novelChapterInfo;
}
}