笔 趣 阁 破 解 版2023 v4.18.00版本的 MD5 值为:35c48a89f5572ff5a659afd7c5a81cad

以下内容为反编译后的 f.java 源代码,内容仅作参考


package com.kwad.sdk.core.videocache;

import android.content.Context;
import android.net.Uri;
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 {
    public final Object aks;
    public final ExecutorService akt;
    public final Map<String, g> aku;
    public final ServerSocket akv;
    public final Thread akw;
    public final com.kwad.sdk.core.videocache.c akx;
    public final int port;

    public static final class a {
        public File akg;
        public com.kwad.sdk.core.videocache.c.b akj;
        public com.kwad.sdk.core.videocache.kwai.a aki = new com.kwad.sdk.core.videocache.kwai.g(536870912);
        public com.kwad.sdk.core.videocache.kwai.c akh = new com.kwad.sdk.core.videocache.kwai.f();
        public 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(b.g.a.i0.a.f2651d);
            return this;
        }

        public final f xU() {
            return new f(xV(), (byte) 0);
        }
    }

    public final class b implements Runnable {
        public 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);
        }
    }

    public final class c implements Runnable {
        public 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);
            }
        }
    }

    public 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 e) {
            this.akt.shutdown();
            throw new IllegalStateException("Error starting local proxy server", e);
        }
    }

    public 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 e) {
                e = e;
                onError(new ProxyCacheException("Error processing request", e));
                b(socket);
                sb = new StringBuilder("Opened connections: ");
            } catch (SocketException e2) {
                com.kwad.sdk.core.e.b.d("HttpProxyCacheServer", "Closing socket… Socket is closed by client.");
                e2.printStackTrace();
                b(socket);
                sb = new StringBuilder("Opened connections: ");
            } catch (IOException e3) {
                e = e3;
                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 e) {
            onError(new ProxyCacheException("Error closing socket input stream", e));
        }
    }

    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;
    }

    public 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 e) {
            onError(new ProxyCacheException("Error closing socket", e));
        }
    }

    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);
        }
    }

    public 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 e) {
                onError(new ProxyCacheException("Error during waiting connection", e));
                return;
            }
        }
    }

    private int xT() {
        int i;
        synchronized (this.aks) {
            i = 0;
            for (g gVar : this.aku.values()) {
                i += gVar.xT();
            }
        }
        return i;
    }

    public final boolean a(String str, int i, a.C0333a c0333a) {
        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, c0333a, i);
    }

    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;
    }
}