中建乐购 v3.2.3版本的 MD5 值为:3856d0da11f056931d64951d23a4b3b8
以下内容为反编译后的 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 f6096a = LoggerFactory.getLogger("HttpUrlSource");
private static final int f6097b = 5;
private final di.c f6098c;
private s f6099d;
private HttpURLConnection f6100e;
private InputStream f6101f;
public k(String str) {
this(str, di.d.a());
}
public k(String str, di.c cVar) {
this.f6098c = (di.c) n.a(cVar);
s a2 = cVar.a(str);
this.f6099d = a2 == null ? new s(str, -2147483648L, p.a(str)) : a2;
}
public k(k kVar) {
this.f6099d = kVar.f6099d;
this.f6098c = kVar.f6098c;
}
@Override
public synchronized long a() throws ProxyCacheException {
if (this.f6099d.f6128b == -2147483648L) {
e();
}
return this.f6099d.f6128b;
}
@Override
public void a(long j2) throws ProxyCacheException {
try {
this.f6100e = a(j2, -1);
String contentType = this.f6100e.getContentType();
this.f6101f = new BufferedInputStream(this.f6100e.getInputStream(), 8192);
this.f6099d = new s(this.f6099d.f6127a, a(this.f6100e, j2, this.f6100e.getResponseCode()), contentType);
this.f6098c.a(this.f6099d.f6127a, this.f6099d);
} catch (IOException e2) {
throw new ProxyCacheException("Error opening connection for " + this.f6099d.f6127a + " 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.f6099d.f6128b;
}
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.f6100e != null) {
try {
this.f6100e.disconnect();
} catch (ArrayIndexOutOfBoundsException e2) {
f6096a.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.f6101f == null) {
throw new ProxyCacheException("Error reading data from " + this.f6099d.f6127a + ": connection is absent!");
}
try {
return this.f6101f.read(bArr, 0, bArr.length);
} catch (InterruptedIOException e2) {
throw new InterruptedProxyCacheException("Reading source " + this.f6099d.f6127a + " is interrupted", e2);
} catch (IOException e3) {
throw new ProxyCacheException("Error reading data from " + this.f6099d.f6127a, e3);
}
}
private void e() throws ProxyCacheException {
InputStream inputStream;
long a2;
String contentType;
f6096a.debug("Read content info from " + this.f6099d.f6127a);
?? 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.f6099d = new s(this.f6099d.f6127a, a2, contentType);
this.f6098c.a(this.f6099d.f6127a, this.f6099d);
Logger logger = f6096a;
?? sb = new StringBuilder();
sb.append("Source info fetched: ");
?? r3 = this.f6099d;
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;
f6096a.error("Error fetching info from " + this.f6099d.f6127a, (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.f6099d.f6127a;
int i3 = 0;
do {
Logger logger = f6096a;
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.f6099d.f6129c)) {
e();
}
return this.f6099d.f6129c;
}
public String d() {
return this.f6099d.f6127a;
}
public String toString() {
return "HttpUrlSource{sourceInfo='" + this.f6099d + "}";
}
}