jimu-decompiled/sources/com/baidu/cloud/videocache/n.java
2025-05-13 19:24:51 +02:00

292 lines
12 KiB
Java

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 + "}";
}
}