b.java 源代码
package com.xiaomi.miui.pushads.sdk;
import android.content.Context;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
class b {
public static int a(Context context, File file, String str, h hVar) {
int i;
String str2 = file.getAbsolutePath() + "/" + m110a(str);
InputStream inputStream = null;
try {
if (new File(str2).exists()) {
i = 0;
} else {
d.a("从sever 下载文件 debug 模式");
inputStream = a(str);
i = a(context, str2, inputStream);
}
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (Exception unused) {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e2) {
e2.printStackTrace();
}
}
i = -1;
} catch (Throwable th) {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e3) {
e3.printStackTrace();
}
}
throw th;
}
if (i == 0) {
hVar.a(str2);
}
return i;
}
private static int a(Context context, String str, InputStream inputStream) {
File file;
int read;
int i = -1;
if (inputStream == null) {
return -1;
}
FileOutputStream fileOutputStream = null;
try {
try {
file = new File(str + "_" + System.currentTimeMillis());
try {
FileOutputStream fileOutputStream2 = new FileOutputStream(file);
try {
byte[] bArr = new byte[i.a];
while (true) {
boolean m112a = f.m112a(context);
read = inputStream.read(bArr);
if (read == -1 || !m112a) {
break;
}
fileOutputStream2.write(bArr, 0, read);
}
fileOutputStream2.flush();
if (read == -1) {
file.renameTo(new File(str));
i = 0;
}
fileOutputStream2.close();
if (file.exists()) {
file.delete();
}
} catch (Exception unused) {
fileOutputStream = fileOutputStream2;
fileOutputStream.close();
if (file.exists()) {
file.delete();
}
return i;
} catch (Throwable th) {
th = th;
fileOutputStream = fileOutputStream2;
try {
fileOutputStream.close();
if (file.exists()) {
file.delete();
}
} catch (IOException e) {
e.printStackTrace();
}
throw th;
}
} catch (Exception unused2) {
} catch (Throwable th2) {
th = th2;
}
} catch (IOException e2) {
e2.printStackTrace();
}
} catch (Exception unused3) {
file = null;
} catch (Throwable th3) {
th = th3;
file = null;
}
return i;
}
private static InputStream a(String str) {
try {
return ((HttpURLConnection) new URL(str).openConnection()).getInputStream();
} catch (IOException unused) {
return null;
}
}
private static String m110a(String str) {
int lastIndexOf = str.lastIndexOf("/");
return str.substring(lastIndexOf < 0 ? 0 : lastIndexOf + 1);
}
}