整点视频 v3.3.0版本的 MD5 值为:cba0457dc37421eed445b30f92de25d3
以下内容为反编译后的 h.java 源代码,内容仅作参考
package com.moqi.sdk.videocache;
import android.content.Context;
import android.net.Uri;
import com.moqi.sdk.utils.u;
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;
public class h {
private static final String j = "127.0.0.1";
private String a;
private final Object b;
private final ExecutorService c;
private final Map<String, i> d;
private final ServerSocket e;
private final int f;
private final Thread g;
private final e h;
private final l i;
public static final class b {
private static final long f = 536870912;
private File a;
private com.moqi.sdk.videocache.u.c d;
private com.moqi.sdk.videocache.s.a c = new com.moqi.sdk.videocache.s.h(f);
private com.moqi.sdk.videocache.s.c b = new com.moqi.sdk.videocache.s.f();
private com.moqi.sdk.videocache.t.b e = new com.moqi.sdk.videocache.t.a();
public b(Context context) {
this.d = com.moqi.sdk.videocache.u.d.a(context);
this.a = r.b(context);
}
public e b() {
return new e(this.a, this.b, this.c, this.d, this.e);
}
public b a(int i) {
this.c = new com.moqi.sdk.videocache.s.g(i);
return this;
}
public b a(long j) {
this.c = new com.moqi.sdk.videocache.s.h(j);
return this;
}
public b a(com.moqi.sdk.videocache.s.a aVar) {
this.c = (com.moqi.sdk.videocache.s.a) m.a(aVar);
return this;
}
public b a(com.moqi.sdk.videocache.s.c cVar) {
this.b = (com.moqi.sdk.videocache.s.c) m.a(cVar);
return this;
}
public b a(com.moqi.sdk.videocache.t.b bVar) {
this.e = (com.moqi.sdk.videocache.t.b) m.a(bVar);
return this;
}
public b a(File file) {
this.a = (File) m.a(file);
return this;
}
public h a() {
return new h(b());
}
}
public final class c implements Runnable {
private final Socket a;
public c(Socket socket) {
this.a = socket;
}
@Override
public void run() {
h.this.d(this.a);
}
}
private final class d implements Runnable {
private final CountDownLatch a;
public d(CountDownLatch countDownLatch) {
this.a = countDownLatch;
}
@Override
public void run() {
this.a.countDown();
h.this.e();
}
}
public h(Context context) {
this(new b(context).b());
}
private h(e eVar) {
this.a = "MoQi_HttpProxyCacheServer";
this.b = new Object();
this.c = Executors.newFixedThreadPool(8);
this.d = new ConcurrentHashMap();
this.h = (e) m.a(eVar);
try {
ServerSocket serverSocket = new ServerSocket(0, 8, InetAddress.getByName(j));
this.e = serverSocket;
int localPort = serverSocket.getLocalPort();
this.f = localPort;
k.a(j, localPort);
CountDownLatch countDownLatch = new CountDownLatch(1);
Thread thread = new Thread(new d(countDownLatch));
this.g = thread;
thread.start();
countDownLatch.await();
this.i = new l(j, localPort);
String str = this.a;
u.c(str, "Proxy cache server started. Is it alive? " + b());
} catch (IOException | InterruptedException e) {
this.c.shutdown();
throw new IllegalStateException("Error starting local proxy server", e);
}
}
private int a() {
int i;
synchronized (this.b) {
i = 0;
for (i iVar : this.d.values()) {
i += iVar.b();
}
}
return i;
}
private String a(String str) {
return String.format(Locale.US, "http://%s:%d/%s", j, Integer.valueOf(this.f), o.c(str));
}
private void a(File file) {
try {
this.h.c.a(file);
} catch (IOException e) {
String str = this.a;
u.c(str, e.getMessage() + "");
}
}
private void a(Throwable th) {
String str = this.a;
u.c(str, th.getMessage() + "");
}
private void a(Socket socket) {
try {
if (socket.isClosed()) {
return;
}
socket.close();
} catch (IOException e) {
a(new ProxyCacheException("Error closing socket", e));
}
}
private File b(String str) {
e eVar = this.h;
return new File(eVar.a, eVar.b.a(str));
}
private void b(Socket socket) {
try {
if (socket.isInputShutdown()) {
return;
}
socket.shutdownInput();
} catch (SocketException unused) {
u.c(this.a, "Releasing input stream… Socket is closed by client.");
} catch (IOException e) {
a(new ProxyCacheException("Error closing socket input stream", e));
}
}
private boolean b() {
return this.i.a(3, 70);
}
private i c(String str) throws ProxyCacheException {
i iVar;
synchronized (this.b) {
iVar = this.d.get(str);
if (iVar == null) {
iVar = new i(str, this.h);
this.d.put(str, iVar);
}
}
return iVar;
}
private void c(Socket socket) {
try {
if (socket.isOutputShutdown()) {
return;
}
socket.shutdownOutput();
} catch (IOException e) {
u.a(e);
}
}
private void d() {
synchronized (this.b) {
for (i iVar : this.d.values()) {
iVar.d();
}
this.d.clear();
}
}
public void d(Socket socket) {
String str;
StringBuilder sb;
try {
try {
f a2 = f.a(socket.getInputStream());
String str2 = this.a;
u.c(str2, "Request to cache proxy:" + a2);
String b2 = o.b(a2.a);
if (this.i.a(b2)) {
this.i.a(socket);
} else {
c(b2).a(a2, socket);
}
e(socket);
str = this.a;
sb = new StringBuilder();
} catch (ProxyCacheException e) {
e = e;
a(new ProxyCacheException("Error processing request", e));
e(socket);
str = this.a;
sb = new StringBuilder();
} catch (SocketException unused) {
u.c(this.a, "Closing socket… Socket is closed by client.");
e(socket);
str = this.a;
sb = new StringBuilder();
} catch (IOException e2) {
e = e2;
a(new ProxyCacheException("Error processing request", e));
e(socket);
str = this.a;
sb = new StringBuilder();
}
sb.append("Opened connections: ");
sb.append(a());
u.c(str, sb.toString());
} catch (Throwable th) {
e(socket);
String str3 = this.a;
u.c(str3, "Opened connections: " + a());
throw th;
}
}
public void e() {
while (!Thread.currentThread().isInterrupted()) {
try {
Socket accept = this.e.accept();
String str = this.a;
u.c(str, "Accept new socket " + accept);
this.c.submit(new c(accept));
} catch (IOException e) {
a(new ProxyCacheException("Error during waiting connection", e));
return;
}
}
}
private void e(Socket socket) {
b(socket);
c(socket);
a(socket);
}
public String a(String str, boolean z) {
if (!z || !e(str)) {
return b() ? a(str) : str;
}
File b2 = b(str);
a(b2);
return Uri.fromFile(b2).toString();
}
public void a(com.moqi.sdk.videocache.d dVar) {
m.a(dVar);
synchronized (this.b) {
for (i iVar : this.d.values()) {
iVar.b(dVar);
}
}
}
public void a(com.moqi.sdk.videocache.d dVar, String str) {
m.a(dVar, str);
synchronized (this.b) {
try {
c(str).a(dVar);
} catch (ProxyCacheException e) {
String str2 = this.a;
u.c(str2, e.getMessage() + "");
}
}
}
public void b(com.moqi.sdk.videocache.d dVar, String str) {
m.a(dVar, str);
synchronized (this.b) {
try {
c(str).b(dVar);
} catch (ProxyCacheException e) {
String str2 = this.a;
u.c(str2, e.getMessage() + "");
}
}
}
public void c() {
u.c(this.a, "Shutdown proxy server");
d();
this.h.d.b();
this.g.interrupt();
try {
if (this.e.isClosed()) {
return;
}
this.e.close();
} catch (IOException e) {
a(new ProxyCacheException("Error shutting down proxy server", e));
}
}
public String d(String str) {
return a(str, true);
}
public boolean e(String str) {
m.a(str, "Url can't be null!");
return b(str).exists();
}
}