中建乐购 v3.2.2版本的 MD5 值为:0553721e6bc6ba8dd67004696a555b81
以下内容为反编译后的 k.java 源代码,内容仅作参考
package com.danikula.videocache;
import android.text.TextUtils;
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 org.apache.http.protocol.HTTP;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class k implements r {
private static final Logger f6050a = LoggerFactory.getLogger("HttpUrlSource");
private static final int f6051b = 5;
private final cx.c f6052c;
private s f6053d;
private HttpURLConnection f6054e;
private InputStream f6055f;
public k(String str) {
this(str, cx.d.a());
}
public k(String str, cx.c cVar) {
this.f6052c = (cx.c) n.a(cVar);
s a2 = cVar.a(str);
this.f6053d = a2 == null ? new s(str, -2147483648L, p.a(str)) : a2;
}
public k(k kVar) {
this.f6053d = kVar.f6053d;
this.f6052c = kVar.f6052c;
}
@Override
public synchronized long a() throws ProxyCacheException {
if (this.f6053d.f6082b == -2147483648L) {
e();
}
return this.f6053d.f6082b;
}
@Override
public void a(long j2) throws ProxyCacheException {
try {
this.f6054e = a(j2, -1);
String contentType = this.f6054e.getContentType();
this.f6055f = new BufferedInputStream(this.f6054e.getInputStream(), 8192);
this.f6053d = new s(this.f6053d.f6081a, a(this.f6054e, j2, this.f6054e.getResponseCode()), contentType);
this.f6052c.a(this.f6053d.f6081a, this.f6053d);
} catch (IOException e2) {
throw new ProxyCacheException("Error opening connection for " + this.f6053d.f6081a + " with offset " + j2, e2);
}
}
private long a(HttpURLConnection httpURLConnection, long j2, int i2) throws IOException {
long a2 = a(httpURLConnection);
return i2 == 200 ? a2 : i2 == 206 ? a2 + j2 : this.f6053d.f6082b;
}
private long a(HttpURLConnection httpURLConnection) {
String headerField = httpURLConnection.getHeaderField(HTTP.CONTENT_LEN);
if (headerField == null) {
return -1L;
}
return Long.parseLong(headerField);
}
@Override
public void b() throws ProxyCacheException {
if (this.f6054e != null) {
try {
this.f6054e.disconnect();
} catch (ArrayIndexOutOfBoundsException e2) {
f6050a.error("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 :(", (Throwable) e2);
} catch (IllegalArgumentException | NullPointerException 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.", e3);
}
}
}
@Override
public int a(byte[] bArr) throws ProxyCacheException {
if (this.f6055f == null) {
throw new ProxyCacheException("Error reading data from " + this.f6053d.f6081a + ": connection is absent!");
}
try {
return this.f6055f.read(bArr, 0, bArr.length);
} catch (InterruptedIOException e2) {
throw new InterruptedProxyCacheException("Reading source " + this.f6053d.f6081a + " is interrupted", e2);
} catch (IOException e3) {
throw new ProxyCacheException("Error reading data from " + this.f6053d.f6081a, e3);
}
}
private void e() throws ProxyCacheException {
InputStream inputStream;
long a2;
String contentType;
f6050a.debug("Read content info from " + this.f6053d.f6081a);
?? r0 = 0;
InputStream inputStream2 = null;
try {
try {
r0 = a(0L, 10000);
try {
a2 = a(r0);
contentType = r0.getContentType();
inputStream = r0.getInputStream();
} catch (IOException e2) {
e = e2;
}
} catch (Throwable th) {
th = th;
inputStream = inputStream2;
}
try {
this.f6053d = new s(this.f6053d.f6081a, a2, contentType);
this.f6052c.a(this.f6053d.f6081a, this.f6053d);
Logger logger = f6050a;
?? sb = new StringBuilder();
sb.append("Source info fetched: ");
?? r3 = this.f6053d;
sb.append(r3);
logger.debug(sb.toString());
p.a(inputStream);
r0 = r0;
inputStream2 = r3;
if (r0 == 0) {
return;
}
} catch (IOException e3) {
e = e3;
inputStream2 = inputStream;
f6050a.error("Error fetching info from " + this.f6053d.f6081a, (Throwable) e);
p.a(inputStream2);
r0 = r0;
inputStream2 = inputStream2;
if (r0 == 0) {
return;
}
r0.disconnect();
} catch (Throwable th2) {
th = th2;
p.a(inputStream);
if (r0 != 0) {
r0.disconnect();
}
throw th;
}
} catch (IOException e4) {
e = e4;
r0 = 0;
} catch (Throwable th3) {
th = th3;
r0 = 0;
inputStream = null;
}
r0.disconnect();
}
private HttpURLConnection a(long j2, int i2) throws IOException, ProxyCacheException {
String str;
HttpURLConnection httpURLConnection;
boolean z2;
String str2 = this.f6053d.f6081a;
int i3 = 0;
do {
Logger logger = f6050a;
StringBuilder sb = new StringBuilder();
sb.append("Open connection ");
int i4 = (j2 > 0L ? 1 : (j2 == 0L ? 0 : -1));
if (i4 > 0) {
str = " with offset " + j2;
} else {
str = "";
}
sb.append(str);
sb.append(" to ");
sb.append(str2);
logger.debug(sb.toString());
httpURLConnection = (HttpURLConnection) new URL(str2).openConnection();
if (i4 > 0) {
httpURLConnection.setRequestProperty("Range", "bytes=" + j2 + "-");
}
if (i2 > 0) {
httpURLConnection.setConnectTimeout(i2);
httpURLConnection.setReadTimeout(i2);
}
int responseCode = httpURLConnection.getResponseCode();
z2 = responseCode == 301 || responseCode == 302 || responseCode == 303;
if (z2) {
str2 = httpURLConnection.getHeaderField("Location");
i3++;
httpURLConnection.disconnect();
}
if (i3 > 5) {
throw new ProxyCacheException("Too many redirects: " + i3);
}
} while (z2);
return httpURLConnection;
}
public synchronized String c() throws ProxyCacheException {
if (TextUtils.isEmpty(this.f6053d.f6083c)) {
e();
}
return this.f6053d.f6083c;
}
public String d() {
return this.f6053d.f6081a;
}
public String toString() {
return "HttpUrlSource{sourceInfo='" + this.f6053d + "}";
}
}