51黑料 v2.0版本的 MD5 值为:cc00ad70c70d95f274d15d4654c16262
以下内容为反编译后的 g.java 源代码,内容仅作参考
package g.e.a;
import android.net.Uri;
import android.text.TextUtils;
import g.e.a.l;
import g.e.a.r.e;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
public class g {
public final Object a = new Object();
public final ExecutorService b = Executors.newFixedThreadPool(8);
public final Map<String, h> c = new ConcurrentHashMap();
public final ServerSocket f2577d;
public final int f2578e;
public final Thread f2579f;
public final g.e.a.c f2580g;
public final l f2581h;
public final class b implements Runnable {
public final Socket c;
public b(Socket socket) {
this.c = socket;
}
@Override
public void run() {
String sb;
String str;
g gVar = g.this;
Socket socket = this.c;
Objects.requireNonNull(gVar);
try {
try {
d a = d.a(socket.getInputStream());
String b = o.b(a.a);
Objects.requireNonNull(gVar.f2581h);
if ("ping".equals(b)) {
gVar.f2581h.b(socket);
} else {
gVar.a(b).c(a, socket);
}
gVar.f(socket);
str = "Opened connections: " + gVar.b();
if (str == null) {
}
} finally {
gVar.f(socket);
sb = "Opened connections: " + gVar.b();
if (sb != null) {
TextUtils.isEmpty(sb);
}
}
} catch (n e2) {
e = e2;
gVar.e(new n("Error processing request", e));
gVar.f(socket);
str = "Opened connections: " + gVar.b();
if (str == null) {
}
} catch (SocketException unused) {
} catch (IOException e3) {
e = e3;
gVar.e(new n("Error processing request", e));
gVar.f(socket);
str = "Opened connections: " + gVar.b();
if (str == null) {
}
}
}
}
public final class c implements Runnable {
public final CountDownLatch c;
public c(CountDownLatch countDownLatch) {
this.c = countDownLatch;
}
@Override
public void run() {
this.c.countDown();
g gVar = g.this;
Objects.requireNonNull(gVar);
while (!Thread.currentThread().isInterrupted()) {
try {
gVar.b.submit(new b(gVar.f2577d.accept()));
} catch (IOException e2) {
gVar.e(new n("Error during waiting connection", e2));
return;
}
}
}
}
public g(g.e.a.c cVar, a aVar) {
this.f2580g = cVar;
try {
ServerSocket serverSocket = new ServerSocket(0, 8, InetAddress.getByName("127.0.0.1"));
this.f2577d = serverSocket;
int localPort = serverSocket.getLocalPort();
this.f2578e = localPort;
List<Proxy> list = j.f2590d;
ProxySelector.setDefault(new j(ProxySelector.getDefault(), "127.0.0.1", localPort));
CountDownLatch countDownLatch = new CountDownLatch(1);
Thread thread = new Thread(new c(countDownLatch));
this.f2579f = thread;
thread.start();
countDownLatch.await();
this.f2581h = new l("127.0.0.1", localPort);
String str = "Proxy cache server started. Is it alive? " + d();
if (str != null) {
TextUtils.isEmpty(str);
}
} catch (IOException | InterruptedException e2) {
this.b.shutdown();
throw new IllegalStateException("Error starting local proxy server", e2);
}
}
public final h a(String str) {
h hVar;
synchronized (this.a) {
hVar = this.c.get(str);
if (hVar == null) {
hVar = new h(str, this.f2580g);
this.c.put(str, hVar);
}
}
return hVar;
}
public final int b() {
int i2;
synchronized (this.a) {
i2 = 0;
for (h hVar : this.c.values()) {
i2 += hVar.a.get();
}
}
return i2;
}
public String c(String str) {
Objects.requireNonNull(str, "Url can't be null!");
g.e.a.c cVar = this.f2580g;
if (new File(cVar.a, cVar.b.a(str)).exists()) {
g.e.a.c cVar2 = this.f2580g;
File file = new File(cVar2.a, cVar2.b.a(str));
try {
g.e.a.r.e eVar = (g.e.a.r.e) this.f2580g.c;
eVar.a.submit(new e.a(file));
} catch (IOException e2) {
f.a("Error touching file " + file, e2);
}
return Uri.fromFile(file).toString();
} else if (d()) {
Locale locale = Locale.US;
Object[] objArr = new Object[3];
objArr[0] = "127.0.0.1";
objArr[1] = Integer.valueOf(this.f2578e);
try {
objArr[2] = URLEncoder.encode(str, "utf-8");
return String.format(locale, "http://%s:%d/%s", objArr);
} catch (UnsupportedEncodingException e3) {
throw new RuntimeException("Error encoding url", e3);
}
} else {
return str;
}
}
public final boolean d() {
l lVar = this.f2581h;
Objects.requireNonNull(lVar);
int i2 = 70;
int i3 = 0;
while (i3 < 3) {
try {
} catch (InterruptedException e2) {
e = e2;
f.a("Error pinging server due to unexpected error", e);
} catch (ExecutionException e3) {
e = e3;
f.a("Error pinging server due to unexpected error", e);
} catch (TimeoutException unused) {
f.b("HttpProxyCacheDebuger", "Error pinging server (attempt: " + i3 + ", timeout: " + i2 + "). ");
}
if (((Boolean) lVar.a.submit(new l.b(null)).get(i2, TimeUnit.MILLISECONDS)).booleanValue()) {
return true;
}
i3++;
i2 *= 2;
}
Locale locale = Locale.US;
Object[] objArr = new Object[3];
objArr[0] = Integer.valueOf(i3);
objArr[1] = Integer.valueOf(i2 / 2);
try {
objArr[2] = ProxySelector.getDefault().select(new URI(lVar.a()));
String format = String.format(locale, "Error pinging server (attempts: %d, max timeout: %d). If you see this message, please, report at https://github.com/danikula/AndroidVideoCache/issues/134. Default proxies are: %s", objArr);
f.a(format, new n(format));
return false;
} catch (URISyntaxException e4) {
throw new IllegalStateException(e4);
}
}
public final void e(Throwable th) {
TextUtils.isEmpty(th.getMessage());
}
public final void f(Socket socket) {
try {
if (!socket.isInputShutdown()) {
socket.shutdownInput();
}
} catch (SocketException | IOException unused) {
}
try {
if (!socket.isOutputShutdown()) {
socket.shutdownOutput();
}
} catch (IOException e2) {
f.b("Failed to close socket on proxy side: {}. It seems client have already closed connection.", e2.getMessage());
}
try {
if (socket.isClosed()) {
return;
}
socket.close();
} catch (IOException unused2) {
}
}
public void g(g.e.a.b bVar) {
synchronized (this.a) {
for (h hVar : this.c.values()) {
hVar.f2584d.remove(bVar);
}
}
}
}