花瓣 v4.6.12版本的 MD5 值为:6a3515d4d16d98931f1b3d25a91b257e
以下内容为反编译后的 f.java 源代码,内容仅作参考
package com.kwad.sdk.core.videocache;
import android.content.Context;
import android.net.Uri;
import com.facebook.common.statfs.StatFsHelper;
import com.kwad.sdk.core.network.kwai.a;
import com.kwad.sdk.utils.an;
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;
public final class f {
private final Object aks;
private final ExecutorService akt;
private final Map<String, g> aku;
private final ServerSocket akv;
private final Thread akw;
private final com.kwad.sdk.core.videocache.c akx;
private final int port;
public static final class a {
private File akg;
private com.kwad.sdk.core.videocache.c.b akj;
private com.kwad.sdk.core.videocache.kwai.a aki = new com.kwad.sdk.core.videocache.kwai.g(536870912);
private com.kwad.sdk.core.videocache.kwai.c akh = new com.kwad.sdk.core.videocache.kwai.f();
private com.kwad.sdk.core.videocache.a.b akk = new com.kwad.sdk.core.videocache.a.a();
public a(Context context) {
this.akj = com.kwad.sdk.core.videocache.c.c.bx(context);
this.akg = n.bu(context);
}
private com.kwad.sdk.core.videocache.c xV() {
return new com.kwad.sdk.core.videocache.c(this.akg, this.akh, this.aki, this.akj, this.akk);
}
public final a S(long j) {
this.aki = new com.kwad.sdk.core.videocache.kwai.g(StatFsHelper.DEFAULT_DISK_RED_LEVEL_IN_BYTES);
return this;
}
public final f xU() {
return new f(xV(), (byte) 0);
}
}
public final class b implements Runnable {
private final Socket aky;
public b(Socket socket) {
this.aky = socket;
}
@Override
public final void run() {
com.kwad.sdk.core.e.b.d("HttpProxyCacheServer", "schedule SocketProcessorRunnable run");
f.this.a(this.aky);
}
}
final class c implements Runnable {
private final CountDownLatch akA;
public c(CountDownLatch countDownLatch) {
this.akA = countDownLatch;
}
@Override
public final void run() {
try {
this.akA.countDown();
f.this.xS();
} catch (Throwable th) {
com.kwad.sdk.core.e.b.printStackTrace(th);
}
}
}
private f(com.kwad.sdk.core.videocache.c cVar) {
this.aks = new Object();
this.akt = com.kwad.sdk.core.threads.b.xv();
this.aku = new ConcurrentHashMap();
this.akx = (com.kwad.sdk.core.videocache.c) an.checkNotNull(cVar);
try {
ServerSocket serverSocket = new ServerSocket(0, 8, InetAddress.getByName("127.0.0.1"));
this.akv = serverSocket;
int localPort = serverSocket.getLocalPort();
this.port = localPort;
i.install("127.0.0.1", localPort);
CountDownLatch countDownLatch = new CountDownLatch(1);
Thread thread = new Thread(new c(countDownLatch));
this.akw = thread;
thread.start();
countDownLatch.await();
} catch (IOException | InterruptedException e2) {
this.akt.shutdown();
throw new IllegalStateException("Error starting local proxy server", e2);
}
}
f(com.kwad.sdk.core.videocache.c cVar, byte b2) {
this(cVar);
}
public void a(Socket socket) {
StringBuilder sb;
?? r0 = "Opened connections: ";
try {
try {
d b2 = d.b(socket.getInputStream());
com.kwad.sdk.core.e.b.d("HttpProxyCacheServer", "Request to cache proxy:" + b2);
cR(k.decode(b2.uri)).a(b2, socket);
b(socket);
sb = new StringBuilder("Opened connections: ");
} catch (ProxyCacheException e2) {
e = e2;
onError(new ProxyCacheException("Error processing request", e));
b(socket);
sb = new StringBuilder("Opened connections: ");
} catch (SocketException e3) {
com.kwad.sdk.core.e.b.d("HttpProxyCacheServer", "Closing socket… Socket is closed by client.");
e3.printStackTrace();
b(socket);
sb = new StringBuilder("Opened connections: ");
} catch (IOException e4) {
e = e4;
onError(new ProxyCacheException("Error processing request", e));
b(socket);
sb = new StringBuilder("Opened connections: ");
}
r0 = xT();
sb.append((int) r0);
socket = sb.toString();
com.kwad.sdk.core.e.b.d("HttpProxyCacheServer", socket);
} catch (Throwable th) {
b(socket);
com.kwad.sdk.core.e.b.d("HttpProxyCacheServer", ((String) r0) + xT());
throw th;
}
}
private String b(String str, boolean z) {
if (bb(str).exists()) {
File bb = bb(str);
m(bb);
return Uri.fromFile(bb).toString();
}
return cP(str);
}
private void b(Socket socket) {
c(socket);
d(socket);
e(socket);
}
private File bb(String str) {
com.kwad.sdk.core.videocache.c cVar = this.akx;
return new File(cVar.akg, cVar.akh.generate(str));
}
private void c(Socket socket) {
try {
if (socket.isInputShutdown()) {
return;
}
socket.shutdownInput();
} catch (SocketException unused) {
com.kwad.sdk.core.e.b.d("HttpProxyCacheServer", "Releasing input stream… Socket is closed by client.");
} catch (IOException e2) {
onError(new ProxyCacheException("Error closing socket input stream", e2));
}
}
private boolean cM(String str) {
an.ae(str, "Url can't be null!");
return bb(str).exists();
}
private String cP(String str) {
return String.format(Locale.US, "http://%s:%d/%s", "127.0.0.1", Integer.valueOf(this.port), k.encode(str));
}
private File cQ(String str) {
File file = this.akx.akg;
return new File(file, this.akx.akh.generate(str) + ".download");
}
private g cR(String str) {
g gVar;
synchronized (this.aks) {
gVar = this.aku.get(str);
if (gVar == null) {
gVar = new g(str, this.akx);
this.aku.put(str, gVar);
}
}
return gVar;
}
private static void d(Socket socket) {
try {
if (socket.isOutputShutdown()) {
return;
}
socket.shutdownOutput();
} catch (IOException unused) {
com.kwad.sdk.core.e.b.w("HttpProxyCacheServer", "Failed to close socket on proxy side: {}. It seems client have already closed connection.");
}
}
private void e(Socket socket) {
try {
if (socket.isClosed()) {
return;
}
socket.close();
} catch (IOException e2) {
onError(new ProxyCacheException("Error closing socket", e2));
}
}
private void m(File file) {
try {
this.akx.aki.n(file);
} catch (IOException unused) {
com.kwad.sdk.core.e.b.e("HttpProxyCacheServer", "Error touching file " + file);
}
}
private static void onError(Throwable th) {
com.kwad.sdk.core.e.b.printStackTraceOnly(th);
}
public void xS() {
while (!Thread.currentThread().isInterrupted()) {
try {
Socket accept = this.akv.accept();
com.kwad.sdk.core.e.b.d("HttpProxyCacheServer", "Accept new socket " + accept);
this.akt.submit(new b(accept));
} catch (IOException e2) {
onError(new ProxyCacheException("Error during waiting connection", e2));
return;
}
}
}
private int xT() {
int i2;
synchronized (this.aks) {
i2 = 0;
for (g gVar : this.aku.values()) {
i2 += gVar.xT();
}
}
return i2;
}
public final boolean a(String str, int i2, a.C0558a c0558a) {
com.kwad.sdk.core.e.b.d("HttpProxyCacheServer", "preloadSync preloadUrl " + str);
if (cM(str)) {
return true;
}
return com.kwad.sdk.core.network.kwai.a.a(cP(str), null, c0558a, i2);
}
public final String cL(String str) {
return b(str, true);
}
public final boolean cN(String str) {
an.ae(str, "Url can't be null!");
return cQ(str).exists() || bb(str).exists();
}
public final boolean cO(String str) {
g gVar = this.aku.get(str);
if (gVar != null) {
gVar.shutdown();
this.aku.remove(str);
return true;
}
return false;
}
}