中建乐购 v3.2.2版本的 MD5 值为:0553721e6bc6ba8dd67004696a555b81
以下内容为反编译后的 i.java 源代码,内容仅作参考
package com.danikula.videocache;
import android.content.Context;
import android.net.Uri;
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 i {
private static final Logger f6023a = LoggerFactory.getLogger("HttpProxyCacheServer");
private static final String f6024b = "127.0.0.1";
private final Object f6025c;
private final ExecutorService f6026d;
private final Map<String, j> f6027e;
private final ServerSocket f6028f;
private final int f6029g;
private final Thread f6030h;
private final f f6031i;
private final m f6032j;
public i(Context context) {
this(new a(context).b());
}
private i(f fVar) {
this.f6025c = new Object();
this.f6026d = Executors.newFixedThreadPool(8);
this.f6027e = new ConcurrentHashMap();
this.f6031i = (f) n.a(fVar);
try {
this.f6028f = new ServerSocket(0, 8, InetAddress.getByName(f6024b));
this.f6029g = this.f6028f.getLocalPort();
l.a(f6024b, this.f6029g);
CountDownLatch countDownLatch = new CountDownLatch(1);
this.f6030h = new Thread(new c(countDownLatch));
this.f6030h.start();
countDownLatch.await();
this.f6032j = new m(f6024b, this.f6029g);
Logger logger = f6023a;
logger.info("Proxy cache server started. Is it alive? " + b());
} catch (IOException | InterruptedException e2) {
this.f6026d.shutdown();
throw new IllegalStateException("Error starting local proxy server", e2);
}
}
public String a(String str) {
return a(str, true);
}
public String a(String str, boolean z2) {
if (!z2 || !b(str)) {
return b() ? c(str) : str;
}
File d2 = d(str);
a(d2);
return Uri.fromFile(d2).toString();
}
public void a(e eVar, String str) {
n.a(eVar, str);
synchronized (this.f6025c) {
try {
e(str).a(eVar);
} catch (ProxyCacheException e2) {
f6023a.warn("Error registering cache listener", (Throwable) e2);
}
}
}
public void b(e eVar, String str) {
n.a(eVar, str);
synchronized (this.f6025c) {
try {
e(str).b(eVar);
} catch (ProxyCacheException e2) {
f6023a.warn("Error registering cache listener", (Throwable) e2);
}
}
}
public void a(e eVar) {
n.a(eVar);
synchronized (this.f6025c) {
for (j jVar : this.f6027e.values()) {
jVar.b(eVar);
}
}
}
public boolean b(String str) {
n.a(str, "Url can't be null!");
return d(str).exists();
}
public void a() {
f6023a.info("Shutdown proxy server");
c();
this.f6031i.f6013d.a();
this.f6030h.interrupt();
try {
if (this.f6028f.isClosed()) {
return;
}
this.f6028f.close();
} catch (IOException e2) {
a(new ProxyCacheException("Error shutting down proxy server", e2));
}
}
private boolean b() {
return this.f6032j.a(3, 70);
}
private String c(String str) {
return String.format(Locale.US, "http://%s:%d/%s", f6024b, Integer.valueOf(this.f6029g), p.b(str));
}
private File d(String str) {
return new File(this.f6031i.f6010a, this.f6031i.f6011b.a(str));
}
private void a(File file) {
try {
this.f6031i.f6012c.a(file);
} catch (IOException e2) {
Logger logger = f6023a;
logger.error("Error touching file " + file, (Throwable) e2);
}
}
private void c() {
synchronized (this.f6025c) {
for (j jVar : this.f6027e.values()) {
jVar.a();
}
this.f6027e.clear();
}
}
public void d() {
while (!Thread.currentThread().isInterrupted()) {
try {
Socket accept = this.f6028f.accept();
Logger logger = f6023a;
logger.debug("Accept new socket " + accept);
this.f6026d.submit(new b(accept));
} catch (IOException e2) {
a(new ProxyCacheException("Error during waiting connection", e2));
return;
}
}
}
public void a(Socket socket) {
Logger logger;
StringBuilder sb;
try {
try {
try {
g a2 = g.a(socket.getInputStream());
Logger logger2 = f6023a;
logger2.debug("Request to cache proxy:" + a2);
String c2 = p.c(a2.f6016a);
if (this.f6032j.a(c2)) {
this.f6032j.a(socket);
} else {
e(c2).a(a2, socket);
}
b(socket);
logger = f6023a;
sb = new StringBuilder();
} catch (SocketException unused) {
f6023a.debug("Closing socket… Socket is closed by client.");
b(socket);
logger = f6023a;
sb = new StringBuilder();
}
} catch (ProxyCacheException | IOException e2) {
a(new ProxyCacheException("Error processing request", e2));
b(socket);
logger = f6023a;
sb = new StringBuilder();
}
sb.append("Opened connections: ");
sb.append(e());
logger.debug(sb.toString());
} catch (Throwable th) {
b(socket);
Logger logger3 = f6023a;
logger3.debug("Opened connections: " + e());
throw th;
}
}
private j e(String str) throws ProxyCacheException {
j jVar;
synchronized (this.f6025c) {
jVar = this.f6027e.get(str);
if (jVar == null) {
jVar = new j(str, this.f6031i);
this.f6027e.put(str, jVar);
}
}
return jVar;
}
private int e() {
int i2;
synchronized (this.f6025c) {
i2 = 0;
for (j jVar : this.f6027e.values()) {
i2 += jVar.b();
}
}
return i2;
}
private void b(Socket socket) {
c(socket);
d(socket);
e(socket);
}
private void c(Socket socket) {
try {
if (socket.isInputShutdown()) {
return;
}
socket.shutdownInput();
} catch (SocketException unused) {
f6023a.debug("Releasing input stream… Socket is closed by client.");
} catch (IOException e2) {
a(new ProxyCacheException("Error closing socket input stream", e2));
}
}
private void d(Socket socket) {
try {
if (socket.isOutputShutdown()) {
return;
}
socket.shutdownOutput();
} catch (IOException e2) {
f6023a.warn("Failed to close socket on proxy side: {}. It seems client have already closed connection.", e2.getMessage());
}
}
private void e(Socket socket) {
try {
if (socket.isClosed()) {
return;
}
socket.close();
} catch (IOException e2) {
a(new ProxyCacheException("Error closing socket", e2));
}
}
private void a(Throwable th) {
f6023a.error("HttpProxyCacheServer error", th);
}
private final class c implements Runnable {
private final CountDownLatch f6041b;
public c(CountDownLatch countDownLatch) {
this.f6041b = countDownLatch;
}
@Override
public void run() {
this.f6041b.countDown();
i.this.d();
}
}
public final class b implements Runnable {
private final Socket f6039b;
public b(Socket socket) {
this.f6039b = socket;
}
@Override
public void run() {
i.this.a(this.f6039b);
}
}
public static final class a {
private static final long f6033a = 536870912;
private File f6034b;
private cx.c f6037e;
private cw.a f6036d = new cw.h(536870912);
private cw.c f6035c = new cw.f();
public a(Context context) {
this.f6037e = cx.d.a(context);
this.f6034b = t.a(context);
}
public a a(File file) {
this.f6034b = (File) n.a(file);
return this;
}
public a a(cw.c cVar) {
this.f6035c = (cw.c) n.a(cVar);
return this;
}
public a a(long j2) {
this.f6036d = new cw.h(j2);
return this;
}
public a a(int i2) {
this.f6036d = new cw.g(i2);
return this;
}
public a a(cw.a aVar) {
this.f6036d = (cw.a) n.a(aVar);
return this;
}
public i a() {
return new i(b());
}
public f b() {
return new f(this.f6034b, this.f6035c, this.f6036d, this.f6037e);
}
}
}