package com.jingdong.manto.network.common; import android.text.TextUtils; import com.google.common.net.HttpHeaders; import com.jd.sentry.performance.network.instrumentation.okhttp3.ShooterOkhttp3Instrumentation; import com.jingdong.manto.network.mantorequests.b; import java.io.File; import java.util.concurrent.TimeUnit; import okhttp3.Call; import okhttp3.Interceptor; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; import okio.BufferedSink; import okio.BufferedSource; import okio.Okio; public class c { private static OkHttpClient.Builder a; /* access modifiers changed from: private */ public static final class a implements Interceptor { final b a; public a(b bVar) { this.a = bVar; } @Override // okhttp3.Interceptor public Response intercept(Interceptor.Chain chain) { Response proceed = chain.proceed(chain.request()); return proceed.newBuilder().body(new e(proceed.body(), this.a)).build(); } } private static String a(String str) { return "https://service.vapp.jd.com/" + str + "/1/page-frame.html"; } private static String a(Response response) { String header = response.header(HttpHeaders.CONTENT_DISPOSITION); if (TextUtils.isEmpty(header)) { return ""; } String[] split = header.split("; "); return split.length > 1 ? split[1].replace("filename=", "").replace("\"", "") : ""; } private static OkHttpClient.Builder a() { if (a == null) { a = ShooterOkhttp3Instrumentation.builderInit(new OkHttpClient.Builder()).readTimeout(30, TimeUnit.SECONDS).connectTimeout(15, TimeUnit.SECONDS).writeTimeout(60, TimeUnit.SECONDS); } return a; } /* JADX WARNING: Removed duplicated region for block: B:33:0x013b */ /* JADX WARNING: Removed duplicated region for block: B:35:0x0140 */ public static void a(com.jingdong.manto.network.mantorequests.a aVar, boolean z, String str, b bVar) { Throwable th; File file; StringBuilder sb; File file2; File file3 = null; try { Call newCall = ShooterOkhttp3Instrumentation.newCall(a().addNetworkInterceptor(new a(bVar)).build(), new Request.Builder().get().url(aVar.a()).addHeader("mimeType", "application/octet-stream").addHeader("referer", a(str)).build()); String b = aVar.b(); String c2 = aVar.c(); Response execute = newCall.execute(); if (execute.isSuccessful()) { if (TextUtils.isEmpty(c2)) { c2 = a(execute); } if (TextUtils.isEmpty(b)) { b = com.jingdong.manto.c.a().getFilesDir().getAbsolutePath() + File.pathSeparator + "manto"; } BufferedSource source = execute.body().source(); if (c2.indexOf(".") >= 0) { sb = new StringBuilder(); sb.append(c2.substring(0, c2.lastIndexOf("."))); sb.append("_"); sb.append(System.currentTimeMillis()); sb.append(c2.substring(c2.lastIndexOf("."))); } else { sb = new StringBuilder(); sb.append(c2); sb.append(System.currentTimeMillis()); } file = new File(b, sb.toString()); try { file.delete(); file.getParentFile().mkdirs(); file.createNewFile(); BufferedSink buffer = Okio.buffer(Okio.sink(file)); source.readAll(buffer); buffer.flush(); source.close(); buffer.close(); file2 = new File(b, c2); } catch (Throwable th2) { th = th2; if (file3 != null) { } if (file != null) { } bVar.a(th); } try { if (file2.exists()) { if (!z) { file.delete(); bVar.a(new b(aVar, file2.getParent(), file2.getName())); } } file.renameTo(file2); bVar.a(new b(aVar, file2.getParent(), file2.getName())); } catch (Throwable th3) { th = th3; file3 = file2; if (file3 != null) { file3.delete(); } if (file != null) { file.delete(); } bVar.a(th); } } else { bVar.a(new Exception(String.format("An error occurred when download file %s", c2))); } } catch (Throwable th4) { th = th4; file = null; if (file3 != null) { } if (file != null) { } bVar.a(th); } } }