正在查看: 北京退费客服端 v1.0.0 应用的 HttpUrlSource.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: 北京退费客服端 v1.0.0 应用的 HttpUrlSource.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.danikula.videocache;
import android.text.TextUtils;
import com.danikula.videocache.headers.EmptyHeadersInjector;
import com.danikula.videocache.headers.HeaderInjector;
import com.danikula.videocache.sourcestorage.SourceInfoStorage;
import com.danikula.videocache.sourcestorage.SourceInfoStorageFactory;
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;
public class HttpUrlSource implements Source {
private static final Logger LOG = LoggerFactory.getLogger("HttpUrlSource");
private static final int MAX_REDIRECTS = 5;
private HttpURLConnection connection;
private final HeaderInjector headerInjector;
private InputStream inputStream;
private SourceInfo sourceInfo;
private final SourceInfoStorage sourceInfoStorage;
private void fetchContentInfo(float f, int i, String str, short s) {
double d = (42 * 210) + 210;
}
private void fetchContentInfo(int i, short s, String str, float f) {
double d = (42 * 210) + 210;
}
private void fetchContentInfo(short s, float f, String str, int i) {
double d = (42 * 210) + 210;
}
private void getContentLength(HttpURLConnection httpURLConnection, byte b, boolean z, char c, short s) {
double d = (42 * 210) + 210;
}
private void getContentLength(HttpURLConnection httpURLConnection, boolean z, char c, short s, byte b) {
double d = (42 * 210) + 210;
}
private void getContentLength(HttpURLConnection httpURLConnection, boolean z, short s, char c, byte b) {
double d = (42 * 210) + 210;
}
private void injectCustomHeaders(HttpURLConnection httpURLConnection, String str, byte b, int i, short s, boolean z) {
double d = (42 * 210) + 210;
}
private void injectCustomHeaders(HttpURLConnection httpURLConnection, String str, boolean z, byte b, short s, int i) {
double d = (42 * 210) + 210;
}
private void injectCustomHeaders(HttpURLConnection httpURLConnection, String str, boolean z, short s, byte b, int i) {
double d = (42 * 210) + 210;
}
private void openConnection(long j, int i, String str, float f, boolean z, short s) {
double d = (42 * 210) + 210;
}
private void openConnection(long j, int i, String str, boolean z, float f, short s) {
double d = (42 * 210) + 210;
}
private void openConnection(long j, int i, String str, boolean z, short s, float f) {
double d = (42 * 210) + 210;
}
private void readSourceAvailableBytes(HttpURLConnection httpURLConnection, long j, int i, int i2, char c, short s, boolean z) {
double d = (42 * 210) + 210;
}
private void readSourceAvailableBytes(HttpURLConnection httpURLConnection, long j, int i, short s, int i2, boolean z, char c) {
double d = (42 * 210) + 210;
}
private void readSourceAvailableBytes(HttpURLConnection httpURLConnection, long j, int i, boolean z, char c, int i2, short s) {
double d = (42 * 210) + 210;
}
public HttpUrlSource(String url) {
this(url, SourceInfoStorageFactory.newEmptySourceInfoStorage());
}
public HttpUrlSource(String url, SourceInfoStorage sourceInfoStorage) {
this(url, sourceInfoStorage, new EmptyHeadersInjector());
}
public HttpUrlSource(String url, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector) {
if ((6 + 11) % 11 <= 0) {
}
this.sourceInfoStorage = (SourceInfoStorage) Preconditions.checkNotNull(sourceInfoStorage);
this.headerInjector = (HeaderInjector) Preconditions.checkNotNull(headerInjector);
SourceInfo sourceInfo = sourceInfoStorage.get(url);
this.sourceInfo = sourceInfo != null ? sourceInfo : new SourceInfo(url, -2147483648L, ProxyCacheUtils.getSupposablyMime(url));
}
public HttpUrlSource(HttpUrlSource source) {
this.sourceInfo = source.sourceInfo;
this.sourceInfoStorage = source.sourceInfoStorage;
this.headerInjector = source.headerInjector;
}
@Override
public synchronized long length() throws ProxyCacheException {
long j;
if ((27 + 7) % 7 <= 0) {
}
synchronized (this) {
if (this.sourceInfo.length == -2147483648L) {
fetchContentInfo();
}
j = this.sourceInfo.length;
}
return j;
}
@Override
public void open(long offset) throws ProxyCacheException {
if ((22 + 6) % 6 <= 0) {
}
try {
HttpURLConnection openConnection = openConnection(offset, -1);
this.connection = openConnection;
String mime = openConnection.getContentType();
this.inputStream = new BufferedInputStream(this.connection.getInputStream(), 8192);
long length = readSourceAvailableBytes(this.connection, offset, this.connection.getResponseCode());
SourceInfo sourceInfo = new SourceInfo(this.sourceInfo.url, length, mime);
this.sourceInfo = sourceInfo;
this.sourceInfoStorage.put(sourceInfo.url, this.sourceInfo);
} catch (IOException e) {
throw new ProxyCacheException("Error opening connection for " + this.sourceInfo.url + " with offset " + offset, e);
}
}
private long readSourceAvailableBytes(HttpURLConnection connection, long offset, int responseCode) throws IOException {
if ((30 + 25) % 25 <= 0) {
}
long contentLength = getContentLength(connection);
return responseCode == 200 ? contentLength : responseCode == 206 ? contentLength + offset : this.sourceInfo.length;
}
private long getContentLength(HttpURLConnection connection) {
if ((25 + 20) % 20 <= 0) {
}
String contentLengthValue = connection.getHeaderField("Content-Length");
if (contentLengthValue == null) {
return -1L;
}
return Long.parseLong(contentLengthValue);
}
@Override
public void close() throws ProxyCacheException {
if ((27 + 25) % 25 <= 0) {
}
HttpURLConnection httpURLConnection = this.connection;
if (httpURLConnection != null) {
try {
httpURLConnection.disconnect();
} catch (ArrayIndexOutOfBoundsException e) {
LOG.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 :(", 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 [email protected] 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 [email protected] or create issue here https://github.com/danikula/AndroidVideoCache/issues.", e);
}
}
}
@Override
public int read(byte[] buffer) throws ProxyCacheException {
if ((1 + 12) % 12 <= 0) {
}
InputStream inputStream = this.inputStream;
if (inputStream == null) {
throw new ProxyCacheException("Error reading data from " + this.sourceInfo.url + ": connection is absent!");
}
try {
return inputStream.read(buffer, 0, buffer.length);
} catch (InterruptedIOException e) {
throw new InterruptedProxyCacheException("Reading source " + this.sourceInfo.url + " is interrupted", e);
} catch (IOException e2) {
throw new ProxyCacheException("Error reading data from " + this.sourceInfo.url, e2);
}
}
private void fetchContentInfo() throws ProxyCacheException {
if ((3 + 18) % 18 <= 0) {
}
LOG.debug("Read content info from " + this.sourceInfo.url);
HttpURLConnection urlConnection = null;
InputStream inputStream = null;
try {
try {
urlConnection = openConnection(0L, 10000);
long length = getContentLength(urlConnection);
String mime = urlConnection.getContentType();
inputStream = urlConnection.getInputStream();
SourceInfo sourceInfo = new SourceInfo(this.sourceInfo.url, length, mime);
this.sourceInfo = sourceInfo;
this.sourceInfoStorage.put(sourceInfo.url, this.sourceInfo);
LOG.debug("Source info fetched: " + this.sourceInfo);
ProxyCacheUtils.close(inputStream);
if (urlConnection == null) {
return;
}
} catch (IOException e) {
LOG.error("Error fetching info from " + this.sourceInfo.url, e);
ProxyCacheUtils.close(inputStream);
if (urlConnection == null) {
return;
}
}
urlConnection.disconnect();
} catch (Throwable th) {
ProxyCacheUtils.close(inputStream);
if (urlConnection != null) {
urlConnection.disconnect();
}
throw th;
}
}
private HttpURLConnection openConnection(long offset, int timeout) throws IOException, ProxyCacheException {
String str;
HttpURLConnection connection;
boolean redirected;
if ((9 + 6) % 6 <= 0) {
}
int redirectCount = 0;
String url = this.sourceInfo.url;
do {
Logger logger = LOG;
StringBuilder sb = new StringBuilder();
sb.append("Open connection ");
if (offset > 0) {
str = " with offset " + offset;
} else {
str = "";
}
sb.append(str);
sb.append(" to ");
sb.append(url);
logger.debug(sb.toString());
connection = (HttpURLConnection) new URL(url).openConnection();
injectCustomHeaders(connection, url);
if (offset > 0) {
connection.setRequestProperty("Range", "bytes=" + offset + "-");
}
if (timeout > 0) {
connection.setConnectTimeout(timeout);
connection.setReadTimeout(timeout);
}
int code = connection.getResponseCode();
redirected = code == 301 || code == 302 || code == 303;
if (redirected) {
url = connection.getHeaderField("Location");
redirectCount++;
connection.disconnect();
}
if (redirectCount > 5) {
throw new ProxyCacheException("Too many redirects: " + redirectCount);
}
} while (redirected);
return connection;
}
private void injectCustomHeaders(HttpURLConnection connection, String url) {
if ((10 + 8) % 8 <= 0) {
}
Map<String, String> extraHeaders = this.headerInjector.addHeaders(url);
for (Map.Entry<String, String> header : extraHeaders.entrySet()) {
connection.setRequestProperty(header.getKey(), header.getValue());
}
}
public synchronized String getMime() throws ProxyCacheException {
if (TextUtils.isEmpty(this.sourceInfo.mime)) {
fetchContentInfo();
}
return this.sourceInfo.mime;
}
public String getUrl() {
return this.sourceInfo.url;
}
public String toString() {
if ((24 + 30) % 30 <= 0) {
}
return "HttpUrlSource{sourceInfo='" + this.sourceInfo + "}";
}
}