花瓣 v4.6.12版本的 MD5 值为:6a3515d4d16d98931f1b3d25a91b257e
以下内容为反编译后的 h.java 源代码,内容仅作参考
package com.sigmob.sdk.videocache;
import android.content.Context;
import android.net.Uri;
import com.czhj.sdk.logger.SigmobLog;
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 a = "127.0.0.1";
private final Object b;
private final ExecutorService c;
private final Map<String, i> f11473d;
private final ServerSocket f11474e;
private final int f11475f;
private final Thread f11476g;
private final e f11477h;
private final m f11478i;
public static final class a {
private static final long a = 536870912;
private File b;
private com.sigmob.sdk.videocache.sourcestorage.c f11480e;
private com.sigmob.sdk.videocache.file.a f11479d = new com.sigmob.sdk.videocache.file.h(a);
private com.sigmob.sdk.videocache.file.c c = new com.sigmob.sdk.videocache.file.f();
private com.sigmob.sdk.videocache.headers.b f11481f = new com.sigmob.sdk.videocache.headers.a();
public a(Context context) {
this.f11480e = com.sigmob.sdk.videocache.sourcestorage.d.a(context);
this.b = u.a(context);
}
public e b() {
return new e(this.b, this.c, this.f11479d, this.f11480e, this.f11481f);
}
public a a(int i2) {
this.f11479d = new com.sigmob.sdk.videocache.file.g(i2);
return this;
}
public a a(long j) {
this.f11479d = new com.sigmob.sdk.videocache.file.h(j);
return this;
}
public a a(com.sigmob.sdk.videocache.file.a aVar) {
this.f11479d = (com.sigmob.sdk.videocache.file.a) n.a(aVar);
return this;
}
public a a(com.sigmob.sdk.videocache.file.c cVar) {
this.c = (com.sigmob.sdk.videocache.file.c) n.a(cVar);
return this;
}
public a a(com.sigmob.sdk.videocache.headers.b bVar) {
this.f11481f = (com.sigmob.sdk.videocache.headers.b) n.a(bVar);
return this;
}
public a a(File file) {
this.b = (File) n.a(file);
return this;
}
public h a() {
return new h(b());
}
}
public final class b implements Runnable {
private final Socket b;
public b(Socket socket) {
this.b = socket;
}
@Override
public void run() {
h.this.a(this.b);
}
}
private final class c implements Runnable {
private final CountDownLatch b;
public c(CountDownLatch countDownLatch) {
this.b = countDownLatch;
}
@Override
public void run() {
this.b.countDown();
h.this.d();
}
}
public h(Context context) {
this(new a(context).b());
}
private h(e eVar) {
this.b = new Object();
this.c = Executors.newFixedThreadPool(8);
this.f11473d = new ConcurrentHashMap();
this.f11477h = (e) n.a(eVar);
try {
ServerSocket serverSocket = new ServerSocket(0, 8, InetAddress.getByName(a));
this.f11474e = serverSocket;
int localPort = serverSocket.getLocalPort();
this.f11475f = localPort;
k.a(a, localPort);
CountDownLatch countDownLatch = new CountDownLatch(1);
Thread thread = new Thread(new c(countDownLatch));
this.f11476g = thread;
thread.start();
countDownLatch.await();
this.f11478i = new m(a, this.f11475f);
SigmobLog.i("Proxy cache server started. Is it alive? " + b());
} catch (IOException | InterruptedException e2) {
this.c.shutdown();
throw new IllegalStateException("Error starting local proxy server", e2);
}
}
private void a(File file) {
try {
this.f11477h.c.a(file);
} catch (IOException e2) {
SigmobLog.e("Error touching file " + file, e2);
}
}
private void a(Throwable th) {
SigmobLog.e("HttpProxyCacheServer error", th);
}
public void a(Socket socket) {
StringBuilder sb;
try {
try {
f a2 = f.a(socket.getInputStream());
SigmobLog.d("Request to cache proxy:" + a2);
String c2 = q.c(a2.a);
if (this.f11478i.a(c2)) {
this.f11478i.a(socket);
} else {
f(c2).a(a2, socket);
}
b(socket);
sb = new StringBuilder();
} catch (p e2) {
e = e2;
a(new p("Error processing request", e));
b(socket);
sb = new StringBuilder();
} catch (SocketException unused) {
SigmobLog.d("Closing socket… Socket is closed by client.");
b(socket);
sb = new StringBuilder();
} catch (IOException e3) {
e = e3;
a(new p("Error processing request", e));
b(socket);
sb = new StringBuilder();
}
sb.append("Opened connections: ");
sb.append(e());
SigmobLog.d(sb.toString());
} catch (Throwable th) {
b(socket);
SigmobLog.d("Opened connections: " + e());
throw th;
}
}
private void b(Socket socket) {
c(socket);
d(socket);
e(socket);
}
private boolean b() {
return this.f11478i.a(3, 70);
}
private void c() {
synchronized (this.b) {
for (i iVar : this.f11473d.values()) {
iVar.a();
}
this.f11473d.clear();
}
}
private void c(Socket socket) {
try {
if (socket.isInputShutdown()) {
return;
}
socket.shutdownInput();
} catch (SocketException unused) {
SigmobLog.d("Releasing input stream… Socket is closed by client.");
} catch (IOException unused2) {
}
}
public void d() {
while (!Thread.currentThread().isInterrupted()) {
try {
Socket accept = this.f11474e.accept();
SigmobLog.d("Accept new socket " + accept);
this.c.submit(new b(accept));
} catch (IOException e2) {
a(new p("Error during waiting connection", e2));
return;
}
}
}
private void d(Socket socket) {
try {
if (socket.isOutputShutdown()) {
return;
}
socket.shutdownOutput();
} catch (IOException unused) {
}
}
private int e() {
int i2;
synchronized (this.b) {
i2 = 0;
for (i iVar : this.f11473d.values()) {
i2 += iVar.b();
}
}
return i2;
}
private String e(String str) {
return String.format(Locale.US, "http://%s:%d/%s", a, Integer.valueOf(this.f11475f), q.b(str));
}
private void e(Socket socket) {
try {
if (socket.isClosed()) {
return;
}
socket.close();
} catch (IOException unused) {
}
}
private i f(String str) throws p {
i iVar;
synchronized (this.b) {
iVar = this.f11473d.get(str);
if (iVar == null) {
iVar = new i(str, this.f11477h);
this.f11473d.put(str, iVar);
}
}
return iVar;
}
public String a(String str) {
return a(str, true);
}
public String a(String str, boolean z) {
if (!z || !b(str)) {
return b() ? e(str) : str;
}
File c2 = c(str);
a(c2);
return Uri.fromFile(c2).toString();
}
public void a() {
SigmobLog.i("Shutdown proxy server");
c();
this.f11477h.f11467d.a();
this.f11476g.interrupt();
try {
if (this.f11474e.isClosed()) {
return;
}
this.f11474e.close();
} catch (IOException e2) {
a(new p("Error shutting down proxy server", e2));
}
}
public void a(d dVar) {
n.a(dVar);
synchronized (this.b) {
for (i iVar : this.f11473d.values()) {
iVar.b(dVar);
}
}
}
public void a(d dVar, String str) {
n.a(dVar, str);
synchronized (this.b) {
try {
f(str).a(dVar);
} catch (p e2) {
SigmobLog.w("Error registering cache listener", e2);
}
}
}
public void b(d dVar, String str) {
n.a(dVar, str);
synchronized (this.b) {
try {
f(str).b(dVar);
} catch (p e2) {
SigmobLog.w("Error registering cache listener", e2);
}
}
}
public boolean b(String str) {
n.a(str, "Url can't be null!");
return c(str).exists();
}
public File c(String str) {
e eVar = this.f11477h;
return new File(eVar.a, eVar.b.a(str));
}
public void d(String str) {
synchronized (this.b) {
i iVar = this.f11473d.get(str);
if (iVar != null) {
iVar.a();
}
}
}
}