Initial commit

This commit is contained in:
2025-05-13 19:24:51 +02:00
commit a950f49678
10604 changed files with 932663 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
package com.baidu.cloud.videocache;
/* loaded from: classes.dex */
public interface Cache {
int a(byte[] bArr, long j, int i);
void a();
void a(byte[] bArr, int i);
long available();
boolean b();
void close();
}

View File

@@ -0,0 +1,8 @@
package com.baidu.cloud.videocache;
import java.io.File;
/* loaded from: classes.dex */
public interface CacheListener {
void a(File file, String str, int i);
}

View File

@@ -0,0 +1,74 @@
package com.baidu.cloud.videocache;
import android.content.Context;
import java.io.File;
/* loaded from: classes.dex */
public final class ProxyCacheManager implements CacheListener {
private static ProxyCacheManager d;
private g a;
private CacheListener b;
private File c;
private g a(Context context) {
i iVar = new i(context.getApplicationContext());
iVar.a(a(context, this.c));
return iVar.a();
}
private File a(Context context, File file) {
if (file == null || (!file.exists() && !file.mkdirs())) {
file = ad.a(context);
}
this.c = file;
return file;
}
public static synchronized ProxyCacheManager b() {
ProxyCacheManager proxyCacheManager;
synchronized (ProxyCacheManager.class) {
if (d == null) {
d = new ProxyCacheManager();
}
proxyCacheManager = d;
}
return proxyCacheManager;
}
public static g b(Context context) {
g gVar = b().a;
if (gVar != null) {
return gVar;
}
ProxyCacheManager b = b();
g a = b().a(context);
b.a = a;
return a;
}
public String a(Context context, String str) {
if (!str.startsWith("http") || str.contains("127.0.0.1")) {
return str;
}
g b = b(context.getApplicationContext());
String a = b.a(str);
b.a(this, str);
return a;
}
public void a() {
g gVar = this.a;
if (gVar != null) {
gVar.a(this);
}
}
public void a(CacheListener cacheListener) {
this.b = cacheListener;
}
@Override // com.baidu.cloud.videocache.CacheListener
public void a(File file, String str, int i) {
this.b.a(file, str, i);
}
}

View File

@@ -0,0 +1,12 @@
package com.baidu.cloud.videocache;
/* loaded from: classes.dex */
public interface Source {
void a(long j);
void close();
long length();
int read(byte[] bArr);
}

View File

@@ -0,0 +1,28 @@
package com.baidu.cloud.videocache;
import com.baidu.cloud.videocache.file.DiskUsage;
import com.baidu.cloud.videocache.file.FileNameGenerator;
import com.baidu.cloud.videocache.headers.HeaderInjector;
import com.baidu.cloud.videocache.sourcestorage.SourceInfoStorage;
import java.io.File;
/* loaded from: classes.dex */
class a {
public final File a;
public final FileNameGenerator b;
public final DiskUsage c;
public final SourceInfoStorage d;
public final HeaderInjector e;
a(File file, FileNameGenerator fileNameGenerator, DiskUsage diskUsage, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector) {
this.a = file;
this.b = fileNameGenerator;
this.c = diskUsage;
this.d = sourceInfoStorage;
this.e = headerInjector;
}
File a(String str) {
return new File(this.a, this.b.a(str));
}
}

View File

@@ -0,0 +1,18 @@
package com.baidu.cloud.videocache;
/* loaded from: classes.dex */
public class aa {
public final String a;
public long b;
public final String c;
public aa(String str, long j, String str2) {
this.a = str;
this.b = j;
this.c = str2;
}
public String toString() {
return "SourceInfo{url='" + this.a + "', length=" + this.b + ", mime='" + this.c + "'}";
}
}

View File

@@ -0,0 +1,44 @@
package com.baidu.cloud.videocache;
import android.content.Context;
import android.os.Environment;
import java.io.File;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/* loaded from: classes.dex */
final class ab {
private static final Logger a = LoggerFactory.getLogger("StorageUtils");
public static File a(Context context) {
return new File(a(context, true), "video-cache");
}
private static File a(Context context, boolean z) {
String str;
try {
str = Environment.getExternalStorageState();
} catch (NullPointerException unused) {
str = "";
}
File b = (z && "mounted".equals(str)) ? b(context) : null;
if (b == null) {
b = context.getCacheDir();
}
if (b != null) {
return b;
}
String str2 = "/data/data/" + context.getPackageName() + "/cache/";
a.warn("Can't define system cache directory! '" + str2 + "%s' will be used.");
return new File(str2);
}
private static File b(Context context) {
File file = new File(new File(new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data"), context.getPackageName()), "cache");
if (file.exists() || file.mkdirs()) {
return file;
}
a.warn("Unable to create external cache directory");
return null;
}
}

View File

@@ -0,0 +1,138 @@
package com.baidu.cloud.videocache;
import android.net.Uri;
import android.text.TextUtils;
/* loaded from: classes.dex */
public class ac {
public static Uri a(String str, String str2) {
return Uri.parse(b(str, str2));
}
private static String a(StringBuilder sb, int i, int i2) {
int i3;
int i4;
if (i >= i2) {
return sb.toString();
}
if (sb.charAt(i) == '/') {
i++;
}
int i5 = i;
int i6 = i2;
while (true) {
for (int i7 = i5; i7 <= i6; i7++) {
if (i7 == i6) {
i3 = i7;
} else if (sb.charAt(i7) == '/') {
i3 = i7 + 1;
}
int i8 = i5 + 1;
if (i7 == i8 && sb.charAt(i5) == '.') {
sb.delete(i5, i3);
i6 -= i3 - i5;
} else {
if (i7 == i5 + 2 && sb.charAt(i5) == '.' && sb.charAt(i8) == '.') {
i4 = sb.lastIndexOf("/", i5 - 2) + 1;
int i9 = i4 > i ? i4 : i;
sb.delete(i9, i3);
i6 -= i3 - i9;
} else {
i4 = i7 + 1;
}
i5 = i4;
}
}
return sb.toString();
}
}
private static int[] a(String str) {
int i;
int[] iArr = new int[4];
if (TextUtils.isEmpty(str)) {
iArr[0] = -1;
return iArr;
}
int length = str.length();
int indexOf = str.indexOf("#");
if (indexOf != -1) {
length = indexOf;
}
int indexOf2 = str.indexOf("?");
if (indexOf2 == -1 || indexOf2 > length) {
indexOf2 = length;
}
int indexOf3 = str.indexOf("/");
if (indexOf3 == -1 && indexOf3 > indexOf2) {
indexOf3 = indexOf2;
}
int indexOf4 = str.indexOf(":");
if (indexOf4 > indexOf3) {
indexOf4 = -1;
}
int i2 = indexOf4 + 2;
if (i2 < indexOf2 && str.charAt(indexOf4 + 1) == '/' && str.charAt(i2) == '/') {
i = str.indexOf(47, indexOf4 + 3);
if (i == -1 || i > indexOf2) {
i = indexOf2;
}
} else {
i = indexOf4 + 1;
}
iArr[0] = indexOf4;
iArr[1] = i;
iArr[2] = indexOf2;
iArr[3] = length;
return iArr;
}
private static String b(String str, String str2) {
StringBuilder sb = new StringBuilder();
if (str == null) {
str = "";
}
if (str2 == null) {
str2 = "";
}
int[] a = a(str2);
if (a[0] != -1) {
sb.append(str2);
a(sb, a[1], a[2]);
return sb.toString();
}
int[] a2 = a(str);
if (a[3] == 0) {
sb.append((CharSequence) str, 0, a2[3]);
sb.append(str2);
return sb.toString();
}
if (a[2] == 0) {
sb.append((CharSequence) str, 0, a2[2]);
sb.append(str2);
return sb.toString();
}
if (a[1] != 0) {
int i = a2[0] + 1;
sb.append((CharSequence) str, 0, i);
sb.append(str2);
return a(sb, a[1] + i, i + a[2]);
}
if (str2.charAt(a[1]) == '/') {
sb.append((CharSequence) str, 0, a2[1]);
sb.append(str2);
return a(sb, a2[1], a2[1] + a[2]);
}
if (a2[0] + 2 < a2[1] && a2[1] == a2[2]) {
sb.append((CharSequence) str, 0, a2[1]);
sb.append('/');
sb.append(str2);
return a(sb, a2[1], a2[1] + a[2] + 1);
}
int lastIndexOf = str.lastIndexOf(47, a2[2] - 1);
int i2 = lastIndexOf == -1 ? a2[1] : lastIndexOf + 1;
sb.append((CharSequence) str, 0, i2);
sb.append(str2);
return a(sb, a2[1], i2 + a[2]);
}
}

View File

@@ -0,0 +1,24 @@
package com.baidu.cloud.videocache;
import android.content.Context;
import java.io.File;
import java.util.Locale;
/* loaded from: classes.dex */
public class ad {
public static int a(String str) {
String b = b(str);
if (b.endsWith(".m3u8")) {
return 1;
}
return b.endsWith(".mpd") ? 2 : 0;
}
public static File a(Context context) {
return new File(context.getExternalCacheDir(), "video-cache");
}
public static String b(String str) {
return str == null ? "" : str.toLowerCase(Locale.US);
}
}

View File

@@ -0,0 +1,58 @@
package com.baidu.cloud.videocache;
import android.text.TextUtils;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/* loaded from: classes.dex */
class b {
private static final Pattern d = Pattern.compile("[R,r]ange:[ ]?bytes=(\\d*)-");
private static final Pattern e = Pattern.compile("GET /(.*) HTTP");
public final String a;
public final long b;
public final boolean c;
public b(String str) {
t.a(str);
long a = a(str);
this.b = Math.max(0L, a);
this.c = a >= 0;
this.a = b(str);
}
private long a(String str) {
Matcher matcher = d.matcher(str);
if (matcher.find()) {
return Long.parseLong(matcher.group(1));
}
return -1L;
}
public static b a(InputStream inputStream) {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
StringBuilder sb = new StringBuilder();
while (true) {
String readLine = bufferedReader.readLine();
if (TextUtils.isEmpty(readLine)) {
return new b(sb.toString());
}
sb.append(readLine);
sb.append('\n');
}
}
private String b(String str) {
Matcher matcher = e.matcher(str);
if (matcher.find()) {
return matcher.group(1);
}
throw new IllegalArgumentException("Invalid request `" + str + "`: url not found!");
}
public String toString() {
return "GetRequest{rangeOffset=" + this.b + ", partial=" + this.c + ", uri='" + this.a + "'}";
}
}

View File

@@ -0,0 +1,58 @@
package com.baidu.cloud.videocache;
import android.net.Uri;
import android.text.TextUtils;
import java.util.Scanner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/* loaded from: classes.dex */
public class c {
private static final Logger a = LoggerFactory.getLogger("HlsPlaylistUtil");
private static String a(String str, String str2, String str3) {
if (str3 == null || str3.isEmpty()) {
return str3;
}
Uri a2 = ac.a(str, str2);
return TextUtils.isEmpty(a2.toString()) ? str3 : str3.replace(str2, z.b(a2.toString()));
}
private static boolean a(Scanner scanner) {
return scanner != null && scanner.hasNextLine() && "#EXTM3U".equals(scanner.nextLine());
}
public static byte[] a(byte[] bArr, String str) {
if (bArr == null || bArr.length == 0) {
return null;
}
String trim = new String(bArr).trim();
Scanner scanner = new Scanner(trim);
if (!a(scanner)) {
a.debug("Input does not start with the #EXTM3U.url :" + str);
return null;
}
char c = 65535;
while (scanner.hasNextLine()) {
String trim2 = scanner.nextLine().trim();
if (c == 65535) {
if (trim2.startsWith("#EXT-X-STREAM-INF")) {
c = 1;
} else if (trim2.startsWith("#EXT-X-TARGETDURATION") || trim2.startsWith("#EXT-X-MEDIA-SEQUENCE") || trim2.startsWith("#EXTINF") || trim2.startsWith("#EXT-X-KEY") || trim2.startsWith("#EXT-X-BYTERANGE") || trim2.equals("#EXT-X-DISCONTINUITY") || trim2.equals("#EXT-X-DISCONTINUITY-SEQUENCE") || trim2.equals("#EXT-X-ENDLIST")) {
c = 2;
}
}
if (c == 1) {
if (trim2.startsWith("#EXT-X-STREAM-INF")) {
trim2 = scanner.nextLine();
trim = a(str, trim2, trim);
}
} else if (c == 2 && !trim2.startsWith("#")) {
trim = a(str, trim2, trim);
}
}
scanner.close();
a.debug("Convert completed:\n" + trim);
return trim.getBytes();
}
}

View File

@@ -0,0 +1,135 @@
package com.baidu.cloud.videocache;
import com.ubt.jimu.unity.bluetooth.UnityActivity;
import java.io.BufferedOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/* loaded from: classes.dex */
public class d extends f {
private static final Logger o = LoggerFactory.getLogger("HlsProxyCache");
private e m;
private b n;
public d(e eVar, com.baidu.cloud.videocache.file.a aVar) {
super(eVar, aVar);
this.m = eVar;
}
private void f() {
long j;
Throwable th;
long j2 = -1;
try {
this.m.a(0L);
j2 = this.m.length();
byte[] bArr = new byte[UnityActivity.BLOCKLY_TYPE_NONE];
byte[] bArr2 = new byte[(int) this.m.length()];
j = 0;
int i = 0;
while (true) {
try {
int read = this.m.read(bArr);
if (read != -1) {
synchronized (this.d) {
if (d()) {
return;
}
System.arraycopy(bArr, 0, bArr2, i, read);
i += read;
}
j += read;
a(j, j2);
} else {
if (!d() && i == this.m.length()) {
byte[] a = c.a(bArr2, this.m.b());
this.k.a(a, a.length);
this.m.b(a.length);
}
c();
b();
o.debug("Read hls file to cache. available is" + this.k.available());
}
} catch (Throwable th2) {
th = th2;
try {
this.e.incrementAndGet();
a(th);
return;
} finally {
e();
a(j, j2);
}
}
}
} catch (Throwable th3) {
j = 0;
th = th3;
}
}
@Override // com.baidu.cloud.videocache.f
public void a(b bVar, Socket socket) {
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(socket.getOutputStream());
this.n = bVar;
o.info("Hls request: {\n" + bVar + "}");
long j = bVar.b;
if (a(bVar)) {
a(bufferedOutputStream, j);
} else {
b(bufferedOutputStream, j);
}
}
@Override // com.baidu.cloud.videocache.f
protected void a(OutputStream outputStream, long j) {
if (!this.k.b() && !d()) {
f();
}
if (this.k.b() && this.h != 100) {
this.h = 100;
a(100);
}
byte[] bArr = new byte[UnityActivity.BLOCKLY_TYPE_NONE];
outputStream.write(b(this.n).getBytes("UTF-8"));
while (true) {
int a = this.k.a(bArr, j, bArr.length);
if (a == -1) {
outputStream.flush();
return;
} else {
outputStream.write(bArr, 0, a);
j += a;
}
}
}
@Override // com.baidu.cloud.videocache.f
protected void b(OutputStream outputStream, long j) {
e eVar = new e(this.m);
try {
eVar.a((int) j);
byte[] bArr = new byte[UnityActivity.BLOCKLY_TYPE_NONE];
byte[] bArr2 = new byte[(int) this.m.length()];
int i = 0;
while (true) {
int read = eVar.read(bArr);
if (read == -1) {
byte[] a = c.a(bArr2, this.m.b());
this.m.b(a.length);
outputStream.write(b(this.n).getBytes("UTF-8"));
outputStream.write(a, 0, a.length);
outputStream.flush();
o.info("Read from source bytes " + i);
return;
}
System.arraycopy(bArr, 0, bArr2, i, read);
i += read;
}
} finally {
eVar.close();
}
}
}

View File

@@ -0,0 +1,21 @@
package com.baidu.cloud.videocache;
import com.baidu.cloud.videocache.headers.HeaderInjector;
import com.baidu.cloud.videocache.sourcestorage.SourceInfoStorage;
/* loaded from: classes.dex */
public class e extends n {
public e(n nVar) {
super(nVar);
}
public e(String str, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector) {
super(str, sourceInfoStorage, headerInjector);
}
public void b(long j) {
aa aaVar = this.c;
aaVar.b = j;
this.a.a(aaVar.a, aaVar);
}
}

View File

@@ -0,0 +1,102 @@
package com.baidu.cloud.videocache;
import android.text.TextUtils;
import com.ubt.jimu.unity.bluetooth.UnityActivity;
import java.io.BufferedOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Locale;
/* loaded from: classes.dex */
class f extends u {
private final n j;
protected final com.baidu.cloud.videocache.file.a k;
private CacheListener l;
public f(n nVar, com.baidu.cloud.videocache.file.a aVar) {
super(nVar, aVar);
this.k = aVar;
this.j = nVar;
}
protected String a(String str, Object... objArr) {
return String.format(Locale.US, str, objArr);
}
@Override // com.baidu.cloud.videocache.u
protected void a(int i) {
CacheListener cacheListener = this.l;
if (cacheListener != null) {
cacheListener.a(this.k.b, this.j.b(), i);
}
}
public void a(CacheListener cacheListener) {
this.l = cacheListener;
}
public void a(b bVar, Socket socket) {
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(socket.getOutputStream());
bufferedOutputStream.write(b(bVar).getBytes("UTF-8"));
long j = bVar.b;
if (a(bVar)) {
a(bufferedOutputStream, j);
} else {
b(bufferedOutputStream, j);
}
}
protected void a(OutputStream outputStream, long j) {
byte[] bArr = new byte[UnityActivity.BLOCKLY_TYPE_NONE];
while (true) {
int a = a(bArr, j, bArr.length);
if (a == -1) {
outputStream.flush();
return;
} else {
outputStream.write(bArr, 0, a);
j += a;
}
}
}
protected boolean a(b bVar) {
long length = this.j.length();
return (((length > 0L ? 1 : (length == 0L ? 0 : -1)) > 0) && bVar.c && ((float) bVar.b) > ((float) this.k.available()) + (((float) length) * 0.2f)) ? false : true;
}
protected String b(b bVar) {
String a = this.j.a();
boolean z = !TextUtils.isEmpty(a);
long available = this.k.b() ? this.k.available() : this.j.length();
boolean z2 = available >= 0;
long j = bVar.c ? available - bVar.b : available;
boolean z3 = z2 && bVar.c;
StringBuilder sb = new StringBuilder();
sb.append(bVar.c ? "HTTP/1.1 206 PARTIAL CONTENT\n" : "HTTP/1.1 200 OK\n");
sb.append("Accept-Ranges: bytes\n");
sb.append(z2 ? a("Content-Length: %d\n", Long.valueOf(j)) : "");
sb.append(z3 ? a("Content-Range: bytes %d-%d/%d\n", Long.valueOf(bVar.b), Long.valueOf(available - 1), Long.valueOf(available)) : "");
sb.append(z ? a("Content-Type: %s\n", a) : "");
sb.append("\n");
return sb.toString();
}
protected void b(OutputStream outputStream, long j) {
n nVar = new n(this.j);
try {
nVar.a((int) j);
byte[] bArr = new byte[UnityActivity.BLOCKLY_TYPE_NONE];
while (true) {
int read = nVar.read(bArr);
if (read == -1) {
outputStream.flush();
return;
}
outputStream.write(bArr, 0, read);
}
} finally {
nVar.close();
}
}
}

View File

@@ -0,0 +1,8 @@
package com.baidu.cloud.videocache.file;
import java.io.File;
/* loaded from: classes.dex */
public interface DiskUsage {
void a(File file);
}

View File

@@ -0,0 +1,6 @@
package com.baidu.cloud.videocache.file;
/* loaded from: classes.dex */
public interface FileNameGenerator {
String a(String str);
}

View File

@@ -0,0 +1,105 @@
package com.baidu.cloud.videocache.file;
import com.baidu.cloud.videocache.Cache;
import com.baidu.cloud.videocache.x;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
/* loaded from: classes.dex */
public class a implements Cache {
private final DiskUsage a;
public File b;
private RandomAccessFile c;
public a(File file, DiskUsage diskUsage) {
File file2;
try {
if (diskUsage == null) {
throw new NullPointerException();
}
this.a = diskUsage;
b.a(file.getParentFile());
boolean exists = file.exists();
if (exists) {
file2 = file;
} else {
file2 = new File(file.getParentFile(), file.getName() + ".download");
}
this.b = file2;
this.c = new RandomAccessFile(this.b, exists ? "r" : "rw");
} catch (IOException e) {
throw new x("Error using file " + file + " as disc cache", e);
}
}
private boolean a(File file) {
return file.getName().endsWith(".download");
}
@Override // com.baidu.cloud.videocache.Cache
public synchronized int a(byte[] bArr, long j, int i) {
try {
this.c.seek(j);
} catch (IOException e) {
throw new x(String.format("Error reading %d bytes with offset %d from file[%d bytes] to buffer[%d bytes]", Integer.valueOf(i), Long.valueOf(j), Long.valueOf(available()), Integer.valueOf(bArr.length)), e);
}
return this.c.read(bArr, 0, i);
}
@Override // com.baidu.cloud.videocache.Cache
public synchronized void a() {
if (b()) {
return;
}
close();
File file = new File(this.b.getParentFile(), this.b.getName().substring(0, this.b.getName().length() - 9));
if (!this.b.renameTo(file)) {
throw new x("Error renaming file " + this.b + " to " + file + " for completion!");
}
this.b = file;
try {
this.c = new RandomAccessFile(this.b, "r");
this.a.a(this.b);
} catch (IOException e) {
throw new x("Error opening " + this.b + " as disc cache", e);
}
}
@Override // com.baidu.cloud.videocache.Cache
public synchronized void a(byte[] bArr, int i) {
try {
if (b()) {
throw new x("Error append cache: cache file " + this.b + " is completed!");
}
this.c.seek(available());
this.c.write(bArr, 0, i);
} catch (IOException e) {
throw new x(String.format("Error writing %d bytes to %s from buffer with size %d", Integer.valueOf(i), this.c, Integer.valueOf(bArr.length)), e);
}
}
@Override // com.baidu.cloud.videocache.Cache
public synchronized long available() {
try {
} catch (IOException e) {
throw new x("Error reading length of file " + this.b, e);
}
return (int) this.c.length();
}
@Override // com.baidu.cloud.videocache.Cache
public synchronized boolean b() {
return !a(this.b);
}
@Override // com.baidu.cloud.videocache.Cache
public synchronized void close() {
try {
this.c.close();
this.a.a(this.b);
} catch (IOException e) {
throw new x("Error closing file " + this.b, e);
}
}
}

View File

@@ -0,0 +1,76 @@
package com.baidu.cloud.videocache.file;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/* loaded from: classes.dex */
class b {
private static final Logger a = LoggerFactory.getLogger("Files");
static void a(File file) {
if (!file.exists()) {
if (!file.mkdirs()) {
throw new IOException(String.format("Directory %s can't be created", file.getAbsolutePath()));
}
} else {
if (file.isDirectory()) {
return;
}
throw new IOException("File " + file + " is not directory!");
}
}
static List b(File file) {
LinkedList linkedList = new LinkedList();
File[] listFiles = file.listFiles();
if (listFiles == null) {
return linkedList;
}
List asList = Arrays.asList(listFiles);
Collections.sort(asList, new d());
return asList;
}
static void c(File file) {
if (file.exists()) {
long currentTimeMillis = System.currentTimeMillis();
if (file.setLastModified(currentTimeMillis)) {
return;
}
d(file);
if (file.lastModified() < currentTimeMillis) {
a.warn("Last modified date {} is not set for file {}", new Date(file.lastModified()), file.getAbsolutePath());
}
}
}
static void d(File file) {
long length = file.length();
if (length == 0) {
e(file);
return;
}
RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rwd");
long j = length - 1;
randomAccessFile.seek(j);
byte readByte = randomAccessFile.readByte();
randomAccessFile.seek(j);
randomAccessFile.write(readByte);
randomAccessFile.close();
}
private static void e(File file) {
if (file.delete() && file.createNewFile()) {
return;
}
throw new IOException("Error recreate zero-size file " + file);
}
}

View File

@@ -0,0 +1,23 @@
package com.baidu.cloud.videocache.file;
import java.io.File;
import java.util.Comparator;
/* loaded from: classes.dex */
final class d implements Comparator {
private d() {
}
private int a(long j, long j2) {
if (j < j2) {
return -1;
}
return j == j2 ? 0 : 1;
}
@Override // java.util.Comparator
/* renamed from: a, reason: merged with bridge method [inline-methods] */
public int compare(File file, File file2) {
return a(file.lastModified(), file2.lastModified());
}
}

View File

@@ -0,0 +1,56 @@
package com.baidu.cloud.videocache.file;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/* loaded from: classes.dex */
public abstract class e implements DiskUsage {
private static final Logger b = LoggerFactory.getLogger("LruDiskUsage");
private final ExecutorService a = Executors.newSingleThreadExecutor();
private void a(List list) {
long b2 = b(list);
int size = list.size();
Iterator it = list.iterator();
while (it.hasNext()) {
File file = (File) it.next();
if (!a(file, b2, size)) {
long length = file.length();
if (file.delete()) {
size--;
b2 -= length;
b.info("Cache file " + file + " is deleted because it exceeds cache limit");
} else {
b.error("Error deleting file " + file + " for trimming cache");
}
}
}
}
private long b(List list) {
Iterator it = list.iterator();
long j = 0;
while (it.hasNext()) {
j += ((File) it.next()).length();
}
return j;
}
/* JADX INFO: Access modifiers changed from: private */
public void b(File file) {
b.c(file);
a(b.b(file.getParentFile()));
}
@Override // com.baidu.cloud.videocache.file.DiskUsage
public void a(File file) {
this.a.submit(new f(this, file));
}
protected abstract boolean a(File file, long j, int i);
}

View File

@@ -0,0 +1,22 @@
package com.baidu.cloud.videocache.file;
import java.io.File;
import java.util.concurrent.Callable;
/* loaded from: classes.dex */
class f implements Callable {
private final File a;
final /* synthetic */ e b;
public f(e eVar, File file) {
this.b = eVar;
this.a = file;
}
@Override // java.util.concurrent.Callable
/* renamed from: a, reason: merged with bridge method [inline-methods] */
public Void call() {
this.b.b(this.a);
return null;
}
}

View File

@@ -0,0 +1,20 @@
package com.baidu.cloud.videocache.file;
import java.io.File;
/* loaded from: classes.dex */
public class g extends e {
private final long c;
public g(long j) {
if (j <= 0) {
throw new IllegalArgumentException("Max size must be positive number!");
}
this.c = j;
}
@Override // com.baidu.cloud.videocache.file.e
protected boolean a(File file, long j, int i) {
return j <= this.c;
}
}

View File

@@ -0,0 +1,11 @@
package com.baidu.cloud.videocache.file;
import com.baidu.cloud.videocache.z;
/* loaded from: classes.dex */
public class h implements FileNameGenerator {
@Override // com.baidu.cloud.videocache.file.FileNameGenerator
public String a(String str) {
return z.b(str);
}
}

View File

@@ -0,0 +1,246 @@
package com.baidu.cloud.videocache;
import android.net.Uri;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/* loaded from: classes.dex */
public class g {
private static final Logger i = LoggerFactory.getLogger("HttpProxyCacheServer");
private final Object a;
private final ExecutorService b;
private final Map c;
private final ServerSocket d;
private final int e;
private Thread f;
private final a g;
private final q h;
private g(a aVar) {
this.a = new Object();
this.b = Executors.newFixedThreadPool(8);
this.c = new ConcurrentHashMap();
t.a(aVar);
this.g = aVar;
try {
this.d = new ServerSocket(0, 8, InetAddress.getByName("127.0.0.1"));
this.e = this.d.getLocalPort();
o.a("127.0.0.1", this.e);
a();
this.h = new q("127.0.0.1", this.e);
i.info("Proxy cache server started. Is it alive? " + b());
} catch (IOException | InterruptedException e) {
this.b.shutdown();
throw new IllegalStateException("Error starting local proxy server", e);
}
}
private void a() {
CountDownLatch countDownLatch = new CountDownLatch(1);
this.f = new Thread(new k(this, countDownLatch));
this.f.start();
countDownLatch.await();
}
private void a(File file) {
try {
this.g.c.a(file);
} catch (IOException e) {
i.error("Error touching file " + file, e);
}
}
private void a(Throwable th) {
i.error("HttpProxyCacheServer error", th);
}
/* JADX INFO: Access modifiers changed from: private */
public void a(Socket socket) {
Logger logger;
StringBuilder sb;
try {
try {
b a = b.a(socket.getInputStream());
i.debug("Request to cache proxy:" + a);
String c = z.c(a.a);
if (this.h.a(c)) {
this.h.a(socket);
} else {
e(c).a(a, socket);
}
b(socket);
logger = i;
sb = new StringBuilder();
} catch (x e) {
e = e;
a(new x("Error processing request", e));
b(socket);
logger = i;
sb = new StringBuilder();
} catch (SocketException unused) {
i.debug("Closing socket… Socket is closed by client.");
b(socket);
logger = i;
sb = new StringBuilder();
} catch (IOException e2) {
e = e2;
a(new x("Error processing request", e));
b(socket);
logger = i;
sb = new StringBuilder();
}
sb.append("Opened connections: ");
sb.append(d());
logger.debug(sb.toString());
} catch (Throwable th) {
b(socket);
i.debug("Opened connections: " + d());
throw th;
}
}
private void b(Socket socket) {
c(socket);
d(socket);
e(socket);
}
private boolean b() {
return this.h.a(3, 70);
}
private String c(String str) {
return String.format(Locale.US, "http://%s:%d/%s", "127.0.0.1", Integer.valueOf(this.e), z.b(str));
}
/* JADX INFO: Access modifiers changed from: private */
public void c() {
while (!Thread.currentThread().isInterrupted()) {
try {
Socket accept = this.d.accept();
i.debug("Accept new socket " + accept);
this.b.submit(new j(this, accept));
} catch (IOException e) {
a(new x("Error during waiting connection", e));
return;
}
}
}
private void c(Socket socket) {
try {
if (socket.isInputShutdown()) {
return;
}
socket.shutdownInput();
} catch (SocketException unused) {
i.debug("Releasing input stream… Socket is closed by client.");
} catch (IOException e) {
a(new x("Error closing socket input stream", e));
}
}
private int d() {
int i2;
synchronized (this.a) {
i2 = 0;
Iterator it = this.c.values().iterator();
while (it.hasNext()) {
i2 += ((l) it.next()).a();
}
}
return i2;
}
private File d(String str) {
a aVar = this.g;
return new File(aVar.a, aVar.b.a(str));
}
private void d(Socket socket) {
try {
if (socket.isOutputShutdown()) {
return;
}
socket.shutdownOutput();
} catch (IOException e) {
i.warn("Failed to close socket on proxy side: {}. It seems client have already closed connection.", e.getMessage());
}
}
private l e(String str) {
l lVar;
synchronized (this.a) {
lVar = (l) this.c.get(str);
if (lVar == null) {
lVar = new l(str, this.g);
this.c.put(str, lVar);
}
}
return lVar;
}
private void e(Socket socket) {
try {
if (socket.isClosed()) {
return;
}
socket.close();
} catch (IOException e) {
a(new x("Error closing socket", e));
}
}
public String a(String str) {
int a = ad.a(str);
return (a == 1 || a == 2) ? a(str, false) : a(str, true);
}
public String a(String str, boolean z) {
if (!z || !b(str)) {
return b() ? c(str) : str;
}
File d = d(str);
a(d);
return Uri.fromFile(d).toString();
}
public void a(CacheListener cacheListener) {
t.a(cacheListener);
synchronized (this.a) {
Iterator it = this.c.values().iterator();
while (it.hasNext()) {
((l) it.next()).b(cacheListener);
}
}
}
public void a(CacheListener cacheListener, String str) {
t.a(cacheListener, str);
synchronized (this.a) {
try {
e(str).a(cacheListener);
} catch (x e) {
i.warn("Error registering cache listener", e);
}
}
}
public boolean b(String str) {
t.a(str, "Url can't be null!");
return d(str).exists();
}
}

View File

@@ -0,0 +1,8 @@
package com.baidu.cloud.videocache.headers;
import java.util.Map;
/* loaded from: classes.dex */
public interface HeaderInjector {
Map a(String str);
}

View File

@@ -0,0 +1,12 @@
package com.baidu.cloud.videocache.headers;
import java.util.HashMap;
import java.util.Map;
/* loaded from: classes.dex */
public class a implements HeaderInjector {
@Override // com.baidu.cloud.videocache.headers.HeaderInjector
public Map a(String str) {
return new HashMap();
}
}

View File

@@ -0,0 +1,36 @@
package com.baidu.cloud.videocache;
import android.content.Context;
import com.baidu.cloud.videocache.file.DiskUsage;
import com.baidu.cloud.videocache.file.FileNameGenerator;
import com.baidu.cloud.videocache.headers.HeaderInjector;
import com.baidu.cloud.videocache.sourcestorage.SourceInfoStorage;
import java.io.File;
/* loaded from: classes.dex */
public final class i {
private File a;
private SourceInfoStorage d;
private DiskUsage c = new com.baidu.cloud.videocache.file.g(536870912);
private FileNameGenerator b = new com.baidu.cloud.videocache.file.h();
private HeaderInjector e = new com.baidu.cloud.videocache.headers.a();
public i(Context context) {
this.d = com.baidu.cloud.videocache.sourcestorage.c.a(context);
this.a = ab.a(context);
}
private a b() {
return new a(this.a, this.b, this.c, this.d, this.e);
}
public g a() {
return new g(b());
}
public i a(File file) {
t.a(file);
this.a = file;
return this;
}
}

View File

@@ -0,0 +1,19 @@
package com.baidu.cloud.videocache;
import java.net.Socket;
/* loaded from: classes.dex */
final class j implements Runnable {
private final Socket a;
final /* synthetic */ g b;
public j(g gVar, Socket socket) {
this.b = gVar;
this.a = socket;
}
@Override // java.lang.Runnable
public void run() {
this.b.a(this.a);
}
}

View File

@@ -0,0 +1,20 @@
package com.baidu.cloud.videocache;
import java.util.concurrent.CountDownLatch;
/* loaded from: classes.dex */
final class k implements Runnable {
private final CountDownLatch a;
final /* synthetic */ g b;
public k(g gVar, CountDownLatch countDownLatch) {
this.b = gVar;
this.a = countDownLatch;
}
@Override // java.lang.Runnable
public void run() {
this.a.countDown();
this.b.c();
}
}

View File

@@ -0,0 +1,63 @@
package com.baidu.cloud.videocache;
import java.net.Socket;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;
/* loaded from: classes.dex */
final class l {
private final String b;
private volatile f c;
private final CacheListener e;
private final a f;
private final AtomicInteger a = new AtomicInteger(0);
private final List d = new CopyOnWriteArrayList();
public l(String str, a aVar) {
t.a(str);
this.b = str;
t.a(aVar);
this.f = aVar;
this.e = new m(str, this.d);
}
private synchronized void b() {
this.c = this.c == null ? d() : this.c;
}
private synchronized void c() {
if (this.a.decrementAndGet() <= 0) {
this.c.a();
this.c = null;
}
}
private f d() {
f a = y.a(this.b, this.f);
a.a(this.e);
return a;
}
public int a() {
return this.a.get();
}
public void a(CacheListener cacheListener) {
this.d.add(cacheListener);
}
public void a(b bVar, Socket socket) {
b();
try {
this.a.incrementAndGet();
this.c.a(bVar, socket);
} finally {
c();
}
}
public void b(CacheListener cacheListener) {
this.d.remove(cacheListener);
}
}

View File

@@ -0,0 +1,36 @@
package com.baidu.cloud.videocache;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import java.io.File;
import java.util.Iterator;
import java.util.List;
/* loaded from: classes.dex */
final class m extends Handler implements CacheListener {
private final String a;
private final List b;
public m(String str, List list) {
super(Looper.getMainLooper());
this.a = str;
this.b = list;
}
@Override // com.baidu.cloud.videocache.CacheListener
public void a(File file, String str, int i) {
Message obtainMessage = obtainMessage();
obtainMessage.arg1 = i;
obtainMessage.obj = file;
sendMessage(obtainMessage);
}
@Override // android.os.Handler
public void handleMessage(Message message) {
Iterator it = this.b.iterator();
while (it.hasNext()) {
((CacheListener) it.next()).a((File) message.obj, this.a, message.arg1);
}
}
}

View File

@@ -0,0 +1,291 @@
package com.baidu.cloud.videocache;
import android.text.TextUtils;
import com.baidu.cloud.videocache.headers.HeaderInjector;
import com.baidu.cloud.videocache.sourcestorage.SourceInfoStorage;
import com.ubt.jimu.unity.bluetooth.UnityActivity;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/* loaded from: classes.dex */
public class n implements Source {
private static final Logger f = LoggerFactory.getLogger("HttpUrlSource");
protected final SourceInfoStorage a;
private final HeaderInjector b;
protected aa c;
private HttpURLConnection d;
private InputStream e;
public n(n nVar) {
this.c = nVar.c;
this.a = nVar.a;
this.b = nVar.b;
}
public n(String str) {
this(str, com.baidu.cloud.videocache.sourcestorage.c.a());
}
public n(String str, SourceInfoStorage sourceInfoStorage) {
this(str, sourceInfoStorage, new com.baidu.cloud.videocache.headers.a());
}
public n(String str, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector) {
t.a(sourceInfoStorage);
this.a = sourceInfoStorage;
t.a(headerInjector);
this.b = headerInjector;
aa aaVar = sourceInfoStorage.get(str);
this.c = aaVar == null ? new aa(str, -2147483648L, z.a(str)) : aaVar;
}
private long a(HttpURLConnection httpURLConnection) {
String headerField = httpURLConnection.getHeaderField("Content-Length");
if (headerField == null) {
return -1L;
}
return Long.parseLong(headerField);
}
private long a(HttpURLConnection httpURLConnection, long j, int i) {
long a = a(httpURLConnection);
return i == 200 ? a : i == 206 ? a + j : this.c.b;
}
private HttpURLConnection a(long j, int i) {
String str;
HttpURLConnection httpURLConnection;
boolean z;
String str2 = this.c.a;
int i2 = 0;
do {
Logger logger = f;
StringBuilder sb = new StringBuilder();
sb.append("Open connection ");
if (j > 0) {
str = " with offset " + j;
} else {
str = "";
}
sb.append(str);
sb.append(" to ");
sb.append(str2);
logger.debug(sb.toString());
httpURLConnection = (HttpURLConnection) new URL(str2).openConnection();
a(httpURLConnection, str2);
if (j > 0) {
httpURLConnection.setRequestProperty("Range", "bytes=" + j + "-");
}
if (i > 0) {
httpURLConnection.setConnectTimeout(i);
httpURLConnection.setReadTimeout(i);
}
int responseCode = httpURLConnection.getResponseCode();
z = responseCode == 301 || responseCode == 302 || responseCode == 303;
if (z) {
str2 = httpURLConnection.getHeaderField("Location");
i2++;
httpURLConnection.disconnect();
}
if (i2 > 5) {
throw new x("Too many redirects: " + i2);
}
} while (z);
return httpURLConnection;
}
private void a(HttpURLConnection httpURLConnection, String str) {
for (Map.Entry entry : this.b.a(str).entrySet()) {
httpURLConnection.setRequestProperty((String) entry.getKey(), (String) entry.getValue());
}
}
/* JADX WARN: Code restructure failed: missing block: B:10:0x008e, code lost:
return;
*/
/* JADX WARN: Code restructure failed: missing block: B:17:0x0089, code lost:
if (r0 == null) goto L25;
*/
/* JADX WARN: Code restructure failed: missing block: B:7:0x0060, code lost:
if (r0 != null) goto L19;
*/
/* JADX WARN: Code restructure failed: missing block: B:8:0x008b, code lost:
r0.disconnect();
r0 = r0;
*/
/* JADX WARN: Multi-variable type inference failed */
/* JADX WARN: Removed duplicated region for block: B:22:0x0094 */
/* JADX WARN: Type inference failed for: r0v1 */
/* JADX WARN: Type inference failed for: r0v12 */
/* JADX WARN: Type inference failed for: r0v13 */
/* JADX WARN: Type inference failed for: r0v14 */
/* JADX WARN: Type inference failed for: r0v2 */
/* JADX WARN: Type inference failed for: r0v4, types: [java.net.HttpURLConnection] */
/* JADX WARN: Type inference failed for: r0v5 */
/* JADX WARN: Type inference failed for: r0v7 */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
private void c() {
/*
r7 = this;
org.slf4j.Logger r0 = com.baidu.cloud.videocache.n.f
java.lang.StringBuilder r1 = new java.lang.StringBuilder
r1.<init>()
java.lang.String r2 = "Read content info from "
r1.append(r2)
com.baidu.cloud.videocache.aa r2 = r7.c
java.lang.String r2 = r2.a
r1.append(r2)
java.lang.String r1 = r1.toString()
r0.debug(r1)
r0 = 0
r2 = 10000(0x2710, float:1.4013E-41)
r3 = 0
java.net.HttpURLConnection r0 = r7.a(r0, r2) // Catch: java.lang.Throwable -> L67 java.io.IOException -> L6a
long r1 = r7.a(r0) // Catch: java.lang.Throwable -> L63 java.io.IOException -> L65
java.lang.String r4 = r0.getContentType() // Catch: java.lang.Throwable -> L63 java.io.IOException -> L65
java.io.InputStream r3 = r0.getInputStream() // Catch: java.lang.Throwable -> L63 java.io.IOException -> L65
com.baidu.cloud.videocache.aa r5 = new com.baidu.cloud.videocache.aa // Catch: java.lang.Throwable -> L63 java.io.IOException -> L65
com.baidu.cloud.videocache.aa r6 = r7.c // Catch: java.lang.Throwable -> L63 java.io.IOException -> L65
java.lang.String r6 = r6.a // Catch: java.lang.Throwable -> L63 java.io.IOException -> L65
r5.<init>(r6, r1, r4) // Catch: java.lang.Throwable -> L63 java.io.IOException -> L65
r7.c = r5 // Catch: java.lang.Throwable -> L63 java.io.IOException -> L65
com.baidu.cloud.videocache.sourcestorage.SourceInfoStorage r1 = r7.a // Catch: java.lang.Throwable -> L63 java.io.IOException -> L65
com.baidu.cloud.videocache.aa r2 = r7.c // Catch: java.lang.Throwable -> L63 java.io.IOException -> L65
java.lang.String r2 = r2.a // Catch: java.lang.Throwable -> L63 java.io.IOException -> L65
com.baidu.cloud.videocache.aa r4 = r7.c // Catch: java.lang.Throwable -> L63 java.io.IOException -> L65
r1.a(r2, r4) // Catch: java.lang.Throwable -> L63 java.io.IOException -> L65
org.slf4j.Logger r1 = com.baidu.cloud.videocache.n.f // Catch: java.lang.Throwable -> L63 java.io.IOException -> L65
java.lang.StringBuilder r2 = new java.lang.StringBuilder // Catch: java.lang.Throwable -> L63 java.io.IOException -> L65
r2.<init>() // Catch: java.lang.Throwable -> L63 java.io.IOException -> L65
java.lang.String r4 = "Source info fetched: "
r2.append(r4) // Catch: java.lang.Throwable -> L63 java.io.IOException -> L65
com.baidu.cloud.videocache.aa r4 = r7.c // Catch: java.lang.Throwable -> L63 java.io.IOException -> L65
r2.append(r4) // Catch: java.lang.Throwable -> L63 java.io.IOException -> L65
java.lang.String r2 = r2.toString() // Catch: java.lang.Throwable -> L63 java.io.IOException -> L65
r1.debug(r2) // Catch: java.lang.Throwable -> L63 java.io.IOException -> L65
com.baidu.cloud.videocache.z.a(r3)
if (r0 == 0) goto L8e
goto L8b
L63:
r1 = move-exception
goto L8f
L65:
r1 = move-exception
goto L6c
L67:
r1 = move-exception
r0 = r3
goto L8f
L6a:
r1 = move-exception
r0 = r3
L6c:
org.slf4j.Logger r2 = com.baidu.cloud.videocache.n.f // Catch: java.lang.Throwable -> L63
java.lang.StringBuilder r4 = new java.lang.StringBuilder // Catch: java.lang.Throwable -> L63
r4.<init>() // Catch: java.lang.Throwable -> L63
java.lang.String r5 = "Error fetching info from "
r4.append(r5) // Catch: java.lang.Throwable -> L63
com.baidu.cloud.videocache.aa r5 = r7.c // Catch: java.lang.Throwable -> L63
java.lang.String r5 = r5.a // Catch: java.lang.Throwable -> L63
r4.append(r5) // Catch: java.lang.Throwable -> L63
java.lang.String r4 = r4.toString() // Catch: java.lang.Throwable -> L63
r2.error(r4, r1) // Catch: java.lang.Throwable -> L63
com.baidu.cloud.videocache.z.a(r3)
if (r0 == 0) goto L8e
L8b:
r0.disconnect()
L8e:
return
L8f:
com.baidu.cloud.videocache.z.a(r3)
if (r0 == 0) goto L97
r0.disconnect()
L97:
throw r1
*/
throw new UnsupportedOperationException("Method not decompiled: com.baidu.cloud.videocache.n.c():void");
}
public synchronized String a() {
if (TextUtils.isEmpty(this.c.c)) {
c();
}
return this.c.c;
}
@Override // com.baidu.cloud.videocache.Source
public void a(long j) {
try {
this.d = a(j, -1);
String contentType = this.d.getContentType();
this.e = new BufferedInputStream(this.d.getInputStream(), UnityActivity.BLOCKLY_TYPE_NONE);
this.c = new aa(this.c.a, a(this.d, j, this.d.getResponseCode()), contentType);
this.a.a(this.c.a, this.c);
} catch (IOException e) {
throw new x("Error opening connection for " + this.c.a + " with offset " + j, e);
}
}
public String b() {
return this.c.a;
}
@Override // com.baidu.cloud.videocache.Source
public void close() {
HttpURLConnection httpURLConnection = this.d;
if (httpURLConnection != null) {
try {
httpURLConnection.disconnect();
} catch (ArrayIndexOutOfBoundsException e) {
f.error("Error closing connection correctly. Should happen only on Android L. If anybody know how to fix it, please visithttps://github.com/danikula/AndroidVideoCache/issues/88. Until good solution is not know, just ignore this issue :(", e);
} catch (IllegalArgumentException e2) {
e = e2;
throw new RuntimeException("Wait... but why? WTF!? Really shouldn't happen any more after fixing https://github.com/danikula/AndroidVideoCache/issues/43. If you read it on your device log, please, notify me danikula@gmail.com or create issue here https://github.com/danikula/AndroidVideoCache/issues.", e);
} catch (NullPointerException e3) {
e = e3;
throw new RuntimeException("Wait... but why? WTF!? Really shouldn't happen any more after fixing https://github.com/danikula/AndroidVideoCache/issues/43. If you read it on your device log, please, notify me danikula@gmail.com or create issue here https://github.com/danikula/AndroidVideoCache/issues.", e);
}
}
}
@Override // com.baidu.cloud.videocache.Source
public synchronized long length() {
if (this.c.b == -2147483648L) {
c();
}
return this.c.b;
}
@Override // com.baidu.cloud.videocache.Source
public int read(byte[] bArr) {
InputStream inputStream = this.e;
if (inputStream == null) {
throw new x("Error reading data from " + this.c.a + ": connection is absent!");
}
try {
return inputStream.read(bArr, 0, bArr.length);
} catch (InterruptedIOException e) {
throw new p("Reading source " + this.c.a + " is interrupted", e);
} catch (IOException e2) {
throw new x("Error reading data from " + this.c.a, e2);
}
}
public String toString() {
return "HttpUrlSource{sourceInfo='" + this.c + "}";
}
}

View File

@@ -0,0 +1,39 @@
package com.baidu.cloud.videocache;
import java.io.IOException;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.SocketAddress;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
/* loaded from: classes.dex */
class o extends ProxySelector {
private static final List d = Arrays.asList(Proxy.NO_PROXY);
private final ProxySelector a;
private final String b;
private final int c;
o(ProxySelector proxySelector, String str, int i) {
t.a(proxySelector);
this.a = proxySelector;
t.a(str);
this.b = str;
this.c = i;
}
static void a(String str, int i) {
ProxySelector.setDefault(new o(ProxySelector.getDefault(), str, i));
}
@Override // java.net.ProxySelector
public void connectFailed(URI uri, SocketAddress socketAddress, IOException iOException) {
this.a.connectFailed(uri, socketAddress, iOException);
}
@Override // java.net.ProxySelector
public List select(URI uri) {
return this.b.equals(uri.getHost()) && this.c == uri.getPort() ? d : this.a.select(uri);
}
}

View File

@@ -0,0 +1,8 @@
package com.baidu.cloud.videocache;
/* loaded from: classes.dex */
public class p extends x {
public p(String str, Throwable th) {
super(str, th);
}
}

View File

@@ -0,0 +1,99 @@
package com.baidu.cloud.videocache;
import java.io.OutputStream;
import java.net.ProxySelector;
import java.net.Socket;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/* loaded from: classes.dex */
class q {
private static final Logger d = LoggerFactory.getLogger("Pinger");
private final ExecutorService a = Executors.newSingleThreadExecutor();
private final String b;
private final int c;
q(String str, int i) {
t.a(str);
this.b = str;
this.c = i;
}
private List a() {
try {
return ProxySelector.getDefault().select(new URI(c()));
} catch (URISyntaxException e) {
throw new IllegalStateException(e);
}
}
/* JADX INFO: Access modifiers changed from: private */
public boolean b() {
n nVar = new n(c());
try {
byte[] bytes = "ping ok".getBytes();
nVar.a(0L);
byte[] bArr = new byte[bytes.length];
nVar.read(bArr);
boolean equals = Arrays.equals(bytes, bArr);
d.info("Ping response: `" + new String(bArr) + "`, pinged? " + equals);
return equals;
} catch (x e) {
d.error("Error reading ping response", e);
return false;
} finally {
nVar.close();
}
}
private String c() {
return String.format(Locale.US, "http://%s:%d/%s", this.b, Integer.valueOf(this.c), "ping");
}
void a(Socket socket) {
OutputStream outputStream = socket.getOutputStream();
outputStream.write("HTTP/1.1 200 OK\n\n".getBytes());
outputStream.write("ping ok".getBytes());
}
boolean a(int i, int i2) {
t.a(i >= 1);
t.a(i2 > 0);
int i3 = i2;
int i4 = 0;
while (i4 < i) {
try {
} catch (InterruptedException e) {
e = e;
d.error("Error pinging server due to unexpected error", e);
} catch (ExecutionException e2) {
e = e2;
d.error("Error pinging server due to unexpected error", e);
} catch (TimeoutException unused) {
d.warn("Error pinging server (attempt: " + i4 + ", timeout: " + i3 + "). ");
}
if (((Boolean) this.a.submit(new s(this)).get(i3, TimeUnit.MILLISECONDS)).booleanValue()) {
return true;
}
i4++;
i3 *= 2;
}
String format = String.format(Locale.US, "Error pinging server (attempts: %d, max timeout: %d). If you see this message, please, report athttps://github.com/danikula/AndroidVideoCache/issues/134. Default proxies are: %s", Integer.valueOf(i4), Integer.valueOf(i3 / 2), a());
d.error(format, new x(format));
return false;
}
boolean a(String str) {
return "ping".equals(str);
}
}

View File

@@ -0,0 +1,20 @@
package com.baidu.cloud.videocache;
import java.util.concurrent.Callable;
/* loaded from: classes.dex */
class s implements Callable {
final /* synthetic */ q a;
private s(q qVar) {
this.a = qVar;
}
@Override // java.util.concurrent.Callable
/* renamed from: a, reason: merged with bridge method [inline-methods] */
public Boolean call() {
boolean b;
b = this.a.b();
return Boolean.valueOf(b);
}
}

View File

@@ -0,0 +1,10 @@
package com.baidu.cloud.videocache.sourcestorage;
import com.baidu.cloud.videocache.aa;
/* loaded from: classes.dex */
public interface SourceInfoStorage {
void a(String str, aa aaVar);
aa get(String str);
}

View File

@@ -0,0 +1,87 @@
package com.baidu.cloud.videocache.sourcestorage;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import com.baidu.cloud.media.player.misc.IMediaFormat;
import com.baidu.cloud.videocache.aa;
import com.baidu.cloud.videocache.t;
import com.liulishuo.filedownloader.model.FileDownloadModel;
/* loaded from: classes.dex */
class a extends SQLiteOpenHelper implements SourceInfoStorage {
private static final String[] a = {FileDownloadModel.ID, "url", "length", IMediaFormat.KEY_MIME};
a(Context context) {
super(context, "AndroidVideoCache.db", (SQLiteDatabase.CursorFactory) null, 1);
t.a(context);
}
private ContentValues a(aa aaVar) {
ContentValues contentValues = new ContentValues();
contentValues.put("url", aaVar.a);
contentValues.put("length", Long.valueOf(aaVar.b));
contentValues.put(IMediaFormat.KEY_MIME, aaVar.c);
return contentValues;
}
private aa a(Cursor cursor) {
return new aa(cursor.getString(cursor.getColumnIndexOrThrow("url")), cursor.getLong(cursor.getColumnIndexOrThrow("length")), cursor.getString(cursor.getColumnIndexOrThrow(IMediaFormat.KEY_MIME)));
}
@Override // com.baidu.cloud.videocache.sourcestorage.SourceInfoStorage
public void a(String str, aa aaVar) {
t.a(str, aaVar);
boolean z = get(str) != null;
ContentValues a2 = a(aaVar);
if (z) {
getWritableDatabase().update("SourceInfo", a2, "url=?", new String[]{str});
} else {
getWritableDatabase().insert("SourceInfo", null, a2);
}
}
@Override // com.baidu.cloud.videocache.sourcestorage.SourceInfoStorage
public aa get(String str) {
t.a(str);
Cursor cursor = null;
r0 = null;
aa a2 = null;
try {
Cursor query = getReadableDatabase().query("SourceInfo", a, "url=?", new String[]{str}, null, null, null);
if (query != null) {
try {
if (query.moveToFirst()) {
a2 = a(query);
}
} catch (Throwable th) {
cursor = query;
th = th;
if (cursor != null) {
cursor.close();
}
throw th;
}
}
if (query != null) {
query.close();
}
return a2;
} catch (Throwable th2) {
th = th2;
}
}
@Override // android.database.sqlite.SQLiteOpenHelper
public void onCreate(SQLiteDatabase sQLiteDatabase) {
t.a(sQLiteDatabase);
sQLiteDatabase.execSQL("CREATE TABLE SourceInfo (_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,url TEXT NOT NULL,mime TEXT,length INTEGER);");
}
@Override // android.database.sqlite.SQLiteOpenHelper
public void onUpgrade(SQLiteDatabase sQLiteDatabase, int i, int i2) {
throw new IllegalStateException("Should not be called. There is no any migration");
}
}

View File

@@ -0,0 +1,15 @@
package com.baidu.cloud.videocache.sourcestorage;
import com.baidu.cloud.videocache.aa;
/* loaded from: classes.dex */
public class b implements SourceInfoStorage {
@Override // com.baidu.cloud.videocache.sourcestorage.SourceInfoStorage
public void a(String str, aa aaVar) {
}
@Override // com.baidu.cloud.videocache.sourcestorage.SourceInfoStorage
public aa get(String str) {
return null;
}
}

View File

@@ -0,0 +1,14 @@
package com.baidu.cloud.videocache.sourcestorage;
import android.content.Context;
/* loaded from: classes.dex */
public class c {
public static SourceInfoStorage a() {
return new b();
}
public static SourceInfoStorage a(Context context) {
return new a(context);
}
}

View File

@@ -0,0 +1,38 @@
package com.baidu.cloud.videocache;
/* loaded from: classes.dex */
public final class t {
public static Object a(Object obj) {
if (obj != null) {
return obj;
}
throw new NullPointerException();
}
public static Object a(Object obj, String str) {
if (obj != null) {
return obj;
}
throw new NullPointerException(str);
}
static void a(boolean z) {
if (!z) {
throw new IllegalArgumentException();
}
}
static void a(boolean z, String str) {
if (!z) {
throw new IllegalArgumentException(str);
}
}
public static void a(Object... objArr) {
for (Object obj : objArr) {
if (obj == null) {
throw new NullPointerException();
}
}
}
}

View File

@@ -0,0 +1,175 @@
package com.baidu.cloud.videocache;
import com.ubt.jimu.unity.bluetooth.UnityActivity;
import java.lang.Thread;
import java.util.concurrent.atomic.AtomicInteger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/* loaded from: classes.dex */
class u {
private static final Logger i = LoggerFactory.getLogger("ProxyCache");
private final Source a;
private final Cache b;
protected final AtomicInteger e;
private volatile Thread f;
private volatile boolean g;
private final Object c = new Object();
protected final Object d = new Object();
protected volatile int h = -1;
public u(Source source, Cache cache) {
t.a(source);
this.a = source;
t.a(cache);
this.b = cache;
this.e = new AtomicInteger();
}
private void f() {
int i2 = this.e.get();
if (i2 < 1) {
return;
}
this.e.set(0);
throw new x("Error reading source " + i2 + " times");
}
private synchronized void g() {
boolean z = (this.f == null || this.f.getState() == Thread.State.TERMINATED) ? false : true;
if (!this.g && !this.b.b() && !z) {
this.f = new Thread(new w(this), "Source reader for " + this.a);
this.f.start();
}
}
private void h() {
synchronized (this.c) {
try {
try {
this.c.wait(1000L);
} catch (InterruptedException e) {
throw new x("Waiting source data is interrupted!", e);
}
} catch (Throwable th) {
throw th;
}
}
}
/* JADX INFO: Access modifiers changed from: private */
public void i() {
long j = -1;
long j2 = 0;
try {
j2 = this.b.available();
this.a.a(j2);
j = this.a.length();
byte[] bArr = new byte[UnityActivity.BLOCKLY_TYPE_NONE];
while (true) {
int read = this.a.read(bArr);
if (read == -1) {
c();
b();
break;
}
synchronized (this.d) {
if (d()) {
return;
} else {
this.b.a(bArr, read);
}
}
j2 += read;
a(j2, j);
}
} finally {
try {
} finally {
}
}
}
public int a(byte[] bArr, long j, int i2) {
z.a(bArr, j, i2);
while (!this.b.b() && this.b.available() < i2 + j && !this.g) {
g();
h();
f();
}
int a = this.b.a(bArr, j, i2);
if (this.b.b() && this.h != 100) {
this.h = 100;
a(100);
}
return a;
}
public void a() {
synchronized (this.d) {
i.debug("Shutdown proxy for " + this.a);
try {
this.g = true;
if (this.f != null) {
this.f.interrupt();
}
this.b.close();
} catch (x e) {
a(e);
}
}
}
protected void a(int i2) {
throw null;
}
protected void a(long j, long j2) {
b(j, j2);
synchronized (this.c) {
this.c.notifyAll();
}
}
protected final void a(Throwable th) {
if (th instanceof p) {
i.debug("ProxyCache is interrupted");
} else {
i.error("ProxyCache error", th);
}
}
protected void b() {
this.h = 100;
a(this.h);
}
protected void b(long j, long j2) {
int i2 = (j2 > 0L ? 1 : (j2 == 0L ? 0 : -1)) == 0 ? 100 : (int) ((j / j2) * 100.0f);
boolean z = i2 != this.h;
if ((j2 >= 0) && z) {
a(i2);
}
this.h = i2;
}
protected void c() {
synchronized (this.d) {
if (!d() && this.b.available() == this.a.length()) {
this.b.a();
}
}
}
protected boolean d() {
return Thread.currentThread().isInterrupted() || this.g;
}
protected void e() {
try {
this.a.close();
} catch (x e) {
a(new x("Error closing source " + this.a, e));
}
}
}

View File

@@ -0,0 +1,15 @@
package com.baidu.cloud.videocache;
/* loaded from: classes.dex */
class w implements Runnable {
final /* synthetic */ u a;
private w(u uVar) {
this.a = uVar;
}
@Override // java.lang.Runnable
public void run() {
this.a.i();
}
}

View File

@@ -0,0 +1,12 @@
package com.baidu.cloud.videocache;
/* loaded from: classes.dex */
public class x extends Exception {
public x(String str) {
super(str + ". Version: 2.7.1");
}
public x(String str, Throwable th) {
super(str + ". Version: 2.7.1", th);
}
}

View File

@@ -0,0 +1,17 @@
package com.baidu.cloud.videocache;
/* loaded from: classes.dex */
public class y {
public static f a(String str, a aVar) {
t.a(str);
t.a(aVar);
int a = ad.a(str);
if (a == 0) {
return new f(new n(str, aVar.d, aVar.e), new com.baidu.cloud.videocache.file.a(aVar.a(str), aVar.c));
}
if (a == 1) {
return new d(new e(str, aVar.d, aVar.e), new com.baidu.cloud.videocache.file.a(aVar.a(str), aVar.c));
}
throw new x("Unsupported media type: " + a);
}
}

View File

@@ -0,0 +1,57 @@
package com.baidu.cloud.videocache;
import android.text.TextUtils;
import android.webkit.MimeTypeMap;
import java.io.Closeable;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/* loaded from: classes.dex */
public class z {
private static final Logger a = LoggerFactory.getLogger("ProxyCacheUtils");
static String a(String str) {
MimeTypeMap singleton = MimeTypeMap.getSingleton();
String fileExtensionFromUrl = MimeTypeMap.getFileExtensionFromUrl(str);
if (TextUtils.isEmpty(fileExtensionFromUrl)) {
return null;
}
return singleton.getMimeTypeFromExtension(fileExtensionFromUrl);
}
static void a(Closeable closeable) {
if (closeable != null) {
try {
closeable.close();
} catch (IOException e) {
a.error("Error closing resource", e);
}
}
}
static void a(byte[] bArr, long j, int i) {
t.a(bArr, "Buffer must be not null!");
t.a(j >= 0, "Data offset must be positive!");
t.a(i >= 0 && i <= bArr.length, "Length must be in range [0..buffer.length]");
}
public static String b(String str) {
try {
return URLEncoder.encode(str, "utf-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Error encoding url", e);
}
}
static String c(String str) {
try {
return URLDecoder.decode(str, "utf-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Error decoding url", e);
}
}
}