50度灰 v5.8.2版本的 MD5 值为:9fe3d350fdc75fa1a3ec45509fa0107e
以下内容为反编译后的 k.java 源代码,内容仅作参考
package com.danikula.videocache;
import android.text.TextUtils;
import com.lzy.okgo.model.HttpHeaders;
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;
public class k implements q {
private static final int f2259a = 5;
private final com.danikula.videocache.v.c f2260b;
private final com.danikula.videocache.u.b f2261c;
private r f2262d;
private HttpURLConnection f2263e;
private InputStream f2264f;
public k(String str) {
this(str, com.danikula.videocache.v.d.a());
}
private void b() throws ProxyCacheException {
HttpURLConnection httpURLConnection;
?? r0 = 0;
InputStream inputStream = null;
try {
try {
httpURLConnection = g(0L, 10000);
try {
long c2 = c(httpURLConnection);
String contentType = httpURLConnection.getContentType();
inputStream = httpURLConnection.getInputStream();
r rVar = new r(this.f2262d.f2285a, c2, contentType);
this.f2262d = rVar;
this.f2260b.b(rVar.f2285a, rVar);
p.c(inputStream);
r0 = httpURLConnection;
} catch (IOException e2) {
e = e2;
h.f("Error fetching info from " + this.f2262d.f2285a, e);
p.c(inputStream);
r0 = httpURLConnection;
if (httpURLConnection == null) {
return;
}
r0.disconnect();
}
} catch (Throwable th) {
th = th;
p.c(inputStream);
if (r0 != 0) {
r0.disconnect();
}
throw th;
}
} catch (IOException e3) {
e = e3;
httpURLConnection = null;
} catch (Throwable th2) {
th = th2;
r0 = 0;
p.c(inputStream);
if (r0 != 0) {
}
throw th;
}
r0.disconnect();
}
private long c(HttpURLConnection httpURLConnection) {
String headerField = httpURLConnection.getHeaderField("Content-Length");
if (headerField == null) {
return -1L;
}
return Long.parseLong(headerField);
}
private void f(HttpURLConnection httpURLConnection, String str) {
Map<String, String> a2 = this.f2261c.a(str);
if (a2 == null) {
return;
}
h.e("****** injectCustomHeaders ****** :" + a2.size());
for (Map.Entry<String, String> entry : a2.entrySet()) {
httpURLConnection.setRequestProperty(entry.getKey(), entry.getValue());
}
}
private HttpURLConnection g(long j, int i) throws IOException, ProxyCacheException {
HttpURLConnection httpURLConnection;
boolean z;
String str = this.f2262d.f2285a;
int i2 = 0;
do {
httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
f(httpURLConnection, str);
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) {
str = httpURLConnection.getHeaderField(HttpHeaders.HEAD_KEY_LOCATION);
i2++;
httpURLConnection.disconnect();
}
if (i2 > 5) {
throw new ProxyCacheException("Too many redirects: " + i2);
}
} while (z);
return httpURLConnection;
}
private long h(HttpURLConnection httpURLConnection, long j, int i) throws IOException {
long c2 = c(httpURLConnection);
return i == 200 ? c2 : i == 206 ? c2 + j : this.f2262d.f2286b;
}
@Override
public void a(long j) throws ProxyCacheException {
try {
HttpURLConnection g2 = g(j, -1);
this.f2263e = g2;
String contentType = g2.getContentType();
this.f2264f = new BufferedInputStream(this.f2263e.getInputStream(), 8192);
HttpURLConnection httpURLConnection = this.f2263e;
r rVar = new r(this.f2262d.f2285a, h(httpURLConnection, j, httpURLConnection.getResponseCode()), contentType);
this.f2262d = rVar;
this.f2260b.b(rVar.f2285a, rVar);
} catch (IOException e2) {
throw new ProxyCacheException("Error opening connection for " + this.f2262d.f2285a + " with offset " + j, e2);
}
}
@Override
public void close() throws ProxyCacheException {
HttpURLConnection httpURLConnection = this.f2263e;
if (httpURLConnection != null) {
try {
httpURLConnection.disconnect();
} catch (ArrayIndexOutOfBoundsException e2) {
h.f("Error closing connection correctly. Should happen only on Android L. If anybody know how to fix it, please visit https://github.com/danikula/AndroidVideoCache/issues/88. Until good solution is not know, just ignore this issue :(", e2);
} catch (IllegalArgumentException 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);
} catch (NullPointerException e4) {
e = e4;
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);
}
}
}
public synchronized String d() throws ProxyCacheException {
if (TextUtils.isEmpty(this.f2262d.f2287c)) {
b();
}
return this.f2262d.f2287c;
}
public String e() {
return this.f2262d.f2285a;
}
@Override
public synchronized long length() throws ProxyCacheException {
if (this.f2262d.f2286b == -2147483648L) {
b();
}
return this.f2262d.f2286b;
}
@Override
public int read(byte[] bArr) throws ProxyCacheException {
InputStream inputStream = this.f2264f;
if (inputStream != null) {
try {
return inputStream.read(bArr, 0, bArr.length);
} catch (InterruptedIOException e2) {
throw new InterruptedProxyCacheException("Reading source " + this.f2262d.f2285a + " is interrupted", e2);
} catch (IOException e3) {
throw new ProxyCacheException("Error reading data from " + this.f2262d.f2285a, e3);
}
}
throw new ProxyCacheException("Error reading data from " + this.f2262d.f2285a + ": connection is absent!");
}
public String toString() {
return "HttpUrlSource{sourceInfo='" + this.f2262d + com.alipay.sdk.util.g.f1548d;
}
public k(String str, com.danikula.videocache.v.c cVar) {
this(str, cVar, new com.danikula.videocache.u.a());
}
public k(String str, com.danikula.videocache.v.c cVar, com.danikula.videocache.u.b bVar) {
this.f2260b = (com.danikula.videocache.v.c) n.d(cVar);
this.f2261c = (com.danikula.videocache.u.b) n.d(bVar);
r a2 = cVar.a(str);
this.f2262d = a2 == null ? new r(str, -2147483648L, p.g(str)) : a2;
}
public k(k kVar) {
this.f2262d = kVar.f2262d;
this.f2260b = kVar.f2260b;
this.f2261c = kVar.f2261c;
}
}