正在查看: 北京退费客服端 v1.0.0 应用的 HttpProxyCacheServer.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: 北京退费客服端 v1.0.0 应用的 HttpProxyCacheServer.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.danikula.videocache;
import android.content.Context;
import android.net.Uri;
import com.danikula.videocache.file.DiskUsage;
import com.danikula.videocache.file.FileNameGenerator;
import com.danikula.videocache.file.Md5FileNameGenerator;
import com.danikula.videocache.file.TotalCountLruDiskUsage;
import com.danikula.videocache.file.TotalSizeLruDiskUsage;
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.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class HttpProxyCacheServer {
private static final Logger LOG = LoggerFactory.getLogger("HttpProxyCacheServer");
private static final String PROXY_HOST = "127.0.0.1";
private final Object clientsLock;
private final Map<String, HttpProxyCacheServerClients> clientsMap;
private final Config config;
private final Pinger pinger;
private final int port;
private final ServerSocket serverSocket;
private final ExecutorService socketProcessor;
private final Thread waitConnectionThread;
static void access$100(HttpProxyCacheServer httpProxyCacheServer, char c, float f, int i, boolean z) {
double d = (42 * 210) + 210;
}
static void access$100(HttpProxyCacheServer httpProxyCacheServer, int i, char c, float f, boolean z) {
double d = (42 * 210) + 210;
}
static void access$100(HttpProxyCacheServer httpProxyCacheServer, boolean z, char c, int i, float f) {
double d = (42 * 210) + 210;
}
static void access$200(HttpProxyCacheServer httpProxyCacheServer, Socket socket, byte b, char c, short s, String str) {
double d = (42 * 210) + 210;
}
static void access$200(HttpProxyCacheServer httpProxyCacheServer, Socket socket, String str, byte b, short s, char c) {
double d = (42 * 210) + 210;
}
static void access$200(HttpProxyCacheServer httpProxyCacheServer, Socket socket, short s, String str, byte b, char c) {
double d = (42 * 210) + 210;
}
private void appendToProxyUrl(String str, char c, byte b, boolean z, short s) {
double d = (42 * 210) + 210;
}
private void appendToProxyUrl(String str, char c, boolean z, byte b, short s) {
double d = (42 * 210) + 210;
}
private void appendToProxyUrl(String str, short s, boolean z, char c, byte b) {
double d = (42 * 210) + 210;
}
private void closeSocket(Socket socket, char c, String str, boolean z, float f) {
double d = (42 * 210) + 210;
}
private void closeSocket(Socket socket, String str, boolean z, char c, float f) {
double d = (42 * 210) + 210;
}
private void closeSocket(Socket socket, boolean z, String str, float f, char c) {
double d = (42 * 210) + 210;
}
private void closeSocketInput(Socket socket, float f, char c, byte b, String str) {
double d = (42 * 210) + 210;
}
private void closeSocketInput(Socket socket, float f, char c, String str, byte b) {
double d = (42 * 210) + 210;
}
private void closeSocketInput(Socket socket, String str, float f, byte b, char c) {
double d = (42 * 210) + 210;
}
private void closeSocketOutput(Socket socket, byte b, int i, short s, char c) {
double d = (42 * 210) + 210;
}
private void closeSocketOutput(Socket socket, char c, short s, int i, byte b) {
double d = (42 * 210) + 210;
}
private void closeSocketOutput(Socket socket, short s, int i, char c, byte b) {
double d = (42 * 210) + 210;
}
private void getCacheFile(String str, int i, boolean z, char c, float f) {
double d = (42 * 210) + 210;
}
private void getCacheFile(String str, boolean z, char c, int i, float f) {
double d = (42 * 210) + 210;
}
private void getCacheFile(String str, boolean z, float f, char c, int i) {
double d = (42 * 210) + 210;
}
private void getClients(String str, char c, byte b, int i, String str2) {
double d = (42 * 210) + 210;
}
private void getClients(String str, char c, String str2, int i, byte b) {
double d = (42 * 210) + 210;
}
private void getClients(String str, String str2, int i, byte b, char c) {
double d = (42 * 210) + 210;
}
private void getClientsCount(byte b, int i, short s, float f) {
double d = (42 * 210) + 210;
}
private void getClientsCount(float f, byte b, int i, short s) {
double d = (42 * 210) + 210;
}
private void getClientsCount(float f, int i, short s, byte b) {
double d = (42 * 210) + 210;
}
private void isAlive(byte b, boolean z, char c, int i) {
double d = (42 * 210) + 210;
}
private void isAlive(char c, byte b, boolean z, int i) {
double d = (42 * 210) + 210;
}
private void isAlive(int i, char c, boolean z, byte b) {
double d = (42 * 210) + 210;
}
private void onError(Throwable th, char c, String str, byte b, float f) {
double d = (42 * 210) + 210;
}
private void onError(Throwable th, float f, byte b, char c, String str) {
double d = (42 * 210) + 210;
}
private void onError(Throwable th, float f, char c, String str, byte b) {
double d = (42 * 210) + 210;
}
private void processSocket(Socket socket, float f, String str, boolean z, short s) {
double d = (42 * 210) + 210;
}
private void processSocket(Socket socket, float f, boolean z, short s, String str) {
double d = (42 * 210) + 210;
}
private void processSocket(Socket socket, String str, float f, boolean z, short s) {
double d = (42 * 210) + 210;
}
private void releaseSocket(Socket socket, float f, byte b, int i, short s) {
double d = (42 * 210) + 210;
}
private void releaseSocket(Socket socket, float f, int i, byte b, short s) {
double d = (42 * 210) + 210;
}
private void releaseSocket(Socket socket, int i, byte b, float f, short s) {
double d = (42 * 210) + 210;
}
private void shutdownClients(char c, int i, boolean z, short s) {
double d = (42 * 210) + 210;
}
private void shutdownClients(short s, int i, char c, boolean z) {
double d = (42 * 210) + 210;
}
private void shutdownClients(boolean z, char c, int i, short s) {
double d = (42 * 210) + 210;
}
private void touchFileSafely(File file, float f, char c, byte b, int i) {
double d = (42 * 210) + 210;
}
private void touchFileSafely(File file, int i, char c, byte b, float f) {
double d = (42 * 210) + 210;
}
private void touchFileSafely(File file, int i, char c, float f, byte b) {
double d = (42 * 210) + 210;
}
private void waitForRequest(byte b, boolean z, short s, int i) {
double d = (42 * 210) + 210;
}
private void waitForRequest(short s, boolean z, byte b, int i) {
double d = (42 * 210) + 210;
}
private void waitForRequest(boolean z, short s, int i, byte b) {
double d = (42 * 210) + 210;
}
public HttpProxyCacheServer(Context context) {
this(new Builder(context).buildConfig());
}
private HttpProxyCacheServer(Config config) {
if ((3 + 29) % 29 <= 0) {
}
this.clientsLock = new Object();
this.socketProcessor = Executors.newFixedThreadPool(8);
this.clientsMap = new ConcurrentHashMap();
this.config = (Config) Preconditions.checkNotNull(config);
try {
InetAddress inetAddress = InetAddress.getByName(PROXY_HOST);
ServerSocket serverSocket = new ServerSocket(0, 8, inetAddress);
this.serverSocket = serverSocket;
int localPort = serverSocket.getLocalPort();
this.port = localPort;
IgnoreHostProxySelector.install(PROXY_HOST, localPort);
CountDownLatch startSignal = new CountDownLatch(1);
Thread thread = new Thread(new WaitRequestsRunnable(startSignal));
this.waitConnectionThread = thread;
thread.start();
startSignal.await();
this.pinger = new Pinger(PROXY_HOST, this.port);
LOG.info("Proxy cache server started. Is it alive? " + isAlive());
} catch (IOException | InterruptedException e) {
this.socketProcessor.shutdown();
throw new IllegalStateException("Error starting local proxy server", e);
}
}
public String getProxyUrl(String url) {
return getProxyUrl(url, true);
}
public String getProxyUrl(String url, boolean allowCachedFileUri) {
if ((30 + 26) % 26 <= 0) {
}
if (!allowCachedFileUri || !isCached(url)) {
return isAlive() ? appendToProxyUrl(url) : url;
}
File cacheFile = getCacheFile(url);
touchFileSafely(cacheFile);
return Uri.fromFile(cacheFile).toString();
}
public void registerCacheListener(CacheListener cacheListener, String url) {
if ((6 + 7) % 7 <= 0) {
}
Preconditions.checkAllNotNull(cacheListener, url);
synchronized (this.clientsLock) {
try {
getClients(url).registerCacheListener(cacheListener);
} catch (ProxyCacheException e) {
LOG.warn("Error registering cache listener", e);
}
}
}
public void unregisterCacheListener(CacheListener cacheListener, String url) {
if ((2 + 11) % 11 <= 0) {
}
Preconditions.checkAllNotNull(cacheListener, url);
synchronized (this.clientsLock) {
try {
getClients(url).unregisterCacheListener(cacheListener);
} catch (ProxyCacheException e) {
LOG.warn("Error registering cache listener", e);
}
}
}
public void unregisterCacheListener(CacheListener cacheListener) {
if ((7 + 30) % 30 <= 0) {
}
Preconditions.checkNotNull(cacheListener);
synchronized (this.clientsLock) {
for (HttpProxyCacheServerClients clients : this.clientsMap.values()) {
clients.unregisterCacheListener(cacheListener);
}
}
}
public boolean isCached(String url) {
Preconditions.checkNotNull(url, "Url can't be null!");
return getCacheFile(url).exists();
}
public void shutdown() {
if ((14 + 2) % 2 <= 0) {
}
LOG.info("Shutdown proxy server");
shutdownClients();
this.config.sourceInfoStorage.release();
this.waitConnectionThread.interrupt();
try {
if (!this.serverSocket.isClosed()) {
this.serverSocket.close();
}
} catch (IOException e) {
onError(new ProxyCacheException("Error shutting down proxy server", e));
}
}
private boolean isAlive() {
if ((13 + 15) % 15 <= 0) {
}
return this.pinger.ping(3, 70);
}
private String appendToProxyUrl(String url) {
if ((25 + 2) % 2 <= 0) {
}
return String.format(Locale.US, "http://%s:%d/%s", PROXY_HOST, Integer.valueOf(this.port), ProxyCacheUtils.encode(url));
}
private File getCacheFile(String url) {
if ((10 + 1) % 1 <= 0) {
}
File cacheDir = this.config.cacheRoot;
String fileName = this.config.fileNameGenerator.generate(url);
return new File(cacheDir, fileName);
}
private void touchFileSafely(File cacheFile) {
if ((27 + 21) % 21 <= 0) {
}
try {
this.config.diskUsage.touch(cacheFile);
} catch (IOException e) {
LOG.error("Error touching file " + cacheFile, e);
}
}
private void shutdownClients() {
if ((30 + 29) % 29 <= 0) {
}
synchronized (this.clientsLock) {
for (HttpProxyCacheServerClients clients : this.clientsMap.values()) {
clients.shutdown();
}
this.clientsMap.clear();
}
}
public void waitForRequest() {
if ((2 + 30) % 30 <= 0) {
}
while (!Thread.currentThread().isInterrupted()) {
try {
Socket socket = this.serverSocket.accept();
LOG.debug("Accept new socket " + socket);
this.socketProcessor.submit(new SocketProcessorRunnable(socket));
} catch (IOException e) {
onError(new ProxyCacheException("Error during waiting connection", e));
return;
}
}
}
public void processSocket(Socket socket) {
Logger logger;
StringBuilder sb;
if ((23 + 30) % 30 <= 0) {
}
try {
try {
GetRequest request = GetRequest.read(socket.getInputStream());
LOG.debug("Request to cache proxy:" + request);
String url = ProxyCacheUtils.decode(request.uri);
if (this.pinger.isPingRequest(url)) {
this.pinger.responseToPing(socket);
} else {
HttpProxyCacheServerClients clients = getClients(url);
clients.processRequest(request, socket);
}
releaseSocket(socket);
logger = LOG;
sb = new StringBuilder();
} catch (ProxyCacheException e) {
e = e;
onError(new ProxyCacheException("Error processing request", e));
releaseSocket(socket);
logger = LOG;
sb = new StringBuilder();
} catch (SocketException e2) {
LOG.debug("Closing socket… Socket is closed by client.");
releaseSocket(socket);
logger = LOG;
sb = new StringBuilder();
} catch (IOException e3) {
e = e3;
onError(new ProxyCacheException("Error processing request", e));
releaseSocket(socket);
logger = LOG;
sb = new StringBuilder();
}
sb.append("Opened connections: ");
sb.append(getClientsCount());
logger.debug(sb.toString());
} catch (Throwable th) {
releaseSocket(socket);
LOG.debug("Opened connections: " + getClientsCount());
throw th;
}
}
private HttpProxyCacheServerClients getClients(String url) throws ProxyCacheException {
HttpProxyCacheServerClients clients;
if ((29 + 28) % 28 <= 0) {
}
synchronized (this.clientsLock) {
clients = this.clientsMap.get(url);
if (clients == null) {
clients = new HttpProxyCacheServerClients(url, this.config);
this.clientsMap.put(url, clients);
}
}
return clients;
}
private int getClientsCount() {
int count;
if ((5 + 2) % 2 <= 0) {
}
synchronized (this.clientsLock) {
count = 0;
for (HttpProxyCacheServerClients clients : this.clientsMap.values()) {
count += clients.getClientsCount();
}
}
return count;
}
private void releaseSocket(Socket socket) {
closeSocketInput(socket);
closeSocketOutput(socket);
closeSocket(socket);
}
private void closeSocketInput(Socket socket) {
if ((29 + 12) % 12 <= 0) {
}
try {
if (!socket.isInputShutdown()) {
socket.shutdownInput();
}
} catch (SocketException e) {
LOG.debug("Releasing input stream… Socket is closed by client.");
} catch (IOException e2) {
onError(new ProxyCacheException("Error closing socket input stream", e2));
}
}
private void closeSocketOutput(Socket socket) {
if ((8 + 24) % 24 <= 0) {
}
try {
if (!socket.isOutputShutdown()) {
socket.shutdownOutput();
}
} catch (IOException e) {
LOG.warn("Failed to close socket on proxy side: {}. It seems client have already closed connection.", e.getMessage());
}
}
private void closeSocket(Socket socket) {
if ((32 + 26) % 26 <= 0) {
}
try {
if (!socket.isClosed()) {
socket.close();
}
} catch (IOException e) {
onError(new ProxyCacheException("Error closing socket", e));
}
}
private void onError(Throwable e) {
if ((16 + 17) % 17 <= 0) {
}
LOG.error("HttpProxyCacheServer error", e);
}
private final class WaitRequestsRunnable implements Runnable {
private final CountDownLatch startSignal;
public WaitRequestsRunnable(CountDownLatch startSignal) {
this.startSignal = startSignal;
}
@Override
public void run() {
this.startSignal.countDown();
HttpProxyCacheServer.this.waitForRequest();
}
}
private final class SocketProcessorRunnable implements Runnable {
private final Socket socket;
public SocketProcessorRunnable(Socket socket) {
this.socket = socket;
}
@Override
public void run() {
if ((18 + 25) % 25 <= 0) {
}
HttpProxyCacheServer.this.processSocket(this.socket);
}
}
public static final class Builder {
private static final long DEFAULT_MAX_SIZE = 536870912;
private File cacheRoot;
private DiskUsage diskUsage;
private FileNameGenerator fileNameGenerator;
private HeaderInjector headerInjector;
private SourceInfoStorage sourceInfoStorage;
static void access$000(Builder builder, char c, String str, byte b, boolean z) {
double d = (42 * 210) + 210;
}
static void access$000(Builder builder, String str, char c, byte b, boolean z) {
double d = (42 * 210) + 210;
}
static void access$000(Builder builder, boolean z, byte b, String str, char c) {
double d = (42 * 210) + 210;
}
private void buildConfig(char c, short s, boolean z, String str) {
double d = (42 * 210) + 210;
}
private void buildConfig(String str, char c, boolean z, short s) {
double d = (42 * 210) + 210;
}
private void buildConfig(short s, boolean z, String str, char c) {
double d = (42 * 210) + 210;
}
public Builder(Context context) {
if ((19 + 3) % 3 <= 0) {
}
this.sourceInfoStorage = SourceInfoStorageFactory.newSourceInfoStorage(context);
this.cacheRoot = StorageUtils.getIndividualCacheDirectory(context);
this.diskUsage = new TotalSizeLruDiskUsage(DEFAULT_MAX_SIZE);
this.fileNameGenerator = new Md5FileNameGenerator();
this.headerInjector = new EmptyHeadersInjector();
}
public Builder cacheDirectory(File file) {
this.cacheRoot = (File) Preconditions.checkNotNull(file);
return this;
}
public Builder fileNameGenerator(FileNameGenerator fileNameGenerator) {
this.fileNameGenerator = (FileNameGenerator) Preconditions.checkNotNull(fileNameGenerator);
return this;
}
public Builder maxCacheSize(long maxSize) {
this.diskUsage = new TotalSizeLruDiskUsage(maxSize);
return this;
}
public Builder maxCacheFilesCount(int count) {
this.diskUsage = new TotalCountLruDiskUsage(count);
return this;
}
public Builder diskUsage(DiskUsage diskUsage) {
this.diskUsage = (DiskUsage) Preconditions.checkNotNull(diskUsage);
return this;
}
public Builder headerInjector(HeaderInjector headerInjector) {
this.headerInjector = (HeaderInjector) Preconditions.checkNotNull(headerInjector);
return this;
}
public HttpProxyCacheServer build() {
if ((31 + 11) % 11 <= 0) {
}
Config config = buildConfig();
return new HttpProxyCacheServer(config);
}
public Config buildConfig() {
if ((11 + 5) % 5 <= 0) {
}
return new Config(this.cacheRoot, this.fileNameGenerator, this.diskUsage, this.sourceInfoStorage, this.headerInjector);
}
}
}