整点视频 v3.3.0版本的 MD5 值为:cba0457dc37421eed445b30f92de25d3

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


package com.kwad.sdk.core.videocache;

import android.content.Context;
import android.net.Uri;
import com.kwad.sdk.core.network.a.a;
import com.kwad.sdk.core.threads.GlobalThreadPools;
import com.kwad.sdk.export.proxy.AdHttpResponseListener;
import com.kwad.sdk.utils.ap;
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 aBP;
    private final ExecutorService aBQ;
    private final Map<String, g> aBR;
    private final ServerSocket aBS;
    private final Thread aBT;
    private final com.kwad.sdk.core.videocache.c aBU;
    private final int port;

    public static final class a {
        private File aBB;
        private com.kwad.sdk.core.videocache.d.c aBE;
        private int aBG;
        private Context context;
        private int aBH = 0;
        private com.kwad.sdk.core.videocache.a.a aBD = new com.kwad.sdk.core.videocache.a.g(536870912);
        private com.kwad.sdk.core.videocache.a.c aBC = new com.kwad.sdk.core.videocache.a.f();
        private com.kwad.sdk.core.videocache.b.b aBF = new com.kwad.sdk.core.videocache.b.a();

        public a(Context context) {
            this.context = context;
            this.aBB = o.bk(context);
        }

        private com.kwad.sdk.core.videocache.c Gq() {
            return new com.kwad.sdk.core.videocache.c(this.aBB, this.aBC, this.aBD, this.aBE, this.aBF, this.aBG, this.aBH);
        }

        public final f Gp() {
            this.aBE = com.kwad.sdk.core.videocache.d.d.j(this.context, this.aBH);
            return new f(Gq(), (byte) 0);
        }

        public final a as(long j) {
            this.aBD = new com.kwad.sdk.core.videocache.a.g(536870912L);
            return this;
        }

        public final a dp(int i) {
            this.aBG = i;
            return this;
        }

        public final a dq(int i) {
            this.aBH = i;
            return this;
        }
    }

    public final class b implements Runnable {
        private final Socket aBV;

        public b(Socket socket) {
            this.aBV = socket;
        }

        @Override
        public final void run() {
            com.kwad.sdk.core.e.c.d("HttpProxyCacheServer", "schedule SocketProcessorRunnable run");
            f.this.a(this.aBV);
        }
    }

    final class c implements Runnable {
        private final CountDownLatch aBX;

        public c(CountDownLatch countDownLatch) {
            this.aBX = countDownLatch;
        }

        @Override
        public final void run() {
            try {
                this.aBX.countDown();
                f.this.Gn();
            } catch (Throwable th) {
                com.kwad.sdk.core.e.c.printStackTrace(th);
            }
        }
    }

    f(com.kwad.sdk.core.videocache.c cVar, byte b2) {
        this(cVar);
    }

    public void Gn() {
        while (!Thread.currentThread().isInterrupted()) {
            try {
                Socket accept = this.aBS.accept();
                com.kwad.sdk.core.e.c.d("HttpProxyCacheServer", "Accept new socket " + accept);
                this.aBQ.submit(new b(accept));
            } catch (IOException e) {
                onError(new ProxyCacheException("Error during waiting connection", e));
                return;
            }
        }
    }

    private int Go() {
        int i;
        synchronized (this.aBP) {
            i = 0;
            for (g gVar : this.aBR.values()) {
                i += gVar.Go();
            }
        }
        return i;
    }

    private File T(String str) {
        com.kwad.sdk.core.videocache.c cVar = this.aBU;
        return new File(cVar.aBB, cVar.aBC.generate(str));
    }

    private void b(Socket socket) {
        c(socket);
        d(socket);
        e(socket);
    }

    private void c(Socket socket) {
        try {
            if (socket.isInputShutdown()) {
                return;
            }
            socket.shutdownInput();
        } catch (SocketException unused) {
            com.kwad.sdk.core.e.c.d("HttpProxyCacheServer", "Releasing input stream… Socket is closed by client.");
        } catch (IOException e) {
            onError(new ProxyCacheException("Error closing socket input stream", e));
        }
    }

    private static void d(Socket socket) {
        try {
            if (socket.isOutputShutdown()) {
                return;
            }
            socket.shutdownOutput();
        } catch (IOException unused) {
            com.kwad.sdk.core.e.c.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 String eE(String str) {
        return String.format(Locale.US, "http://%s:%d/%s", "127.0.0.1", Integer.valueOf(this.port), l.encode(str));
    }

    private File eF(String str) {
        File file = this.aBU.aBB;
        return new File(file, this.aBU.aBC.generate(str) + ".download");
    }

    private g eG(String str) {
        g gVar;
        synchronized (this.aBP) {
            gVar = this.aBR.get(str);
            if (gVar == null) {
                gVar = new g(str, this.aBU);
                this.aBR.put(str, gVar);
            }
        }
        return gVar;
    }

    private String f(String str, boolean z) {
        if (T(str).exists()) {
            File T = T(str);
            r(T);
            return Uri.fromFile(T).toString();
        }
        return eE(str);
    }

    private static void onError(Throwable th) {
        com.kwad.sdk.core.e.c.printStackTraceOnly(th);
    }

    private void r(File file) {
        try {
            this.aBU.aBD.s(file);
        } catch (IOException unused) {
            com.kwad.sdk.core.e.c.e("HttpProxyCacheServer", "Error touching file " + file);
        }
    }

    public final String eA(String str) {
        return f(str, true);
    }

    public final boolean eB(String str) {
        ap.ax(str, "Url can't be null!");
        return T(str).exists();
    }

    public final boolean eC(String str) {
        ap.ax(str, "Url can't be null!");
        return eF(str).exists() || T(str).exists();
    }

    public final boolean eD(String str) {
        g gVar = this.aBR.get(str);
        if (gVar != null) {
            gVar.shutdown();
            this.aBR.remove(str);
            return true;
        }
        return false;
    }

    private f(com.kwad.sdk.core.videocache.c cVar) {
        this.aBP = new Object();
        this.aBQ = GlobalThreadPools.FG();
        this.aBR = new ConcurrentHashMap();
        this.aBU = (com.kwad.sdk.core.videocache.c) ap.checkNotNull(cVar);
        try {
            ServerSocket serverSocket = new ServerSocket(0, 8, InetAddress.getByName("127.0.0.1"));
            this.aBS = 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.aBT = thread;
            thread.start();
            countDownLatch.await();
        } catch (IOException | InterruptedException e) {
            this.aBQ.shutdown();
            throw new IllegalStateException("Error starting local proxy server", e);
        }
    }

    public final boolean a(String str, long j, a.C0335a c0335a, AdHttpResponseListener adHttpResponseListener) {
        com.kwad.sdk.core.e.c.d("HttpProxyCacheServer", "preloadSync preloadUrl " + str);
        if (eB(str)) {
            return true;
        }
        return com.kwad.sdk.core.network.a.a.a(eE(str), null, c0335a, j, adHttpResponseListener);
    }

    public void a(Socket socket) {
        StringBuilder sb;
        ?? r0 = "Opened connections: ";
        try {
            try {
                d b2 = d.b(socket.getInputStream());
                com.kwad.sdk.core.e.c.d("HttpProxyCacheServer", "Request to cache proxy:" + b2);
                eG(l.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.c.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 = Go();
            sb.append((int) r0);
            socket = sb.toString();
            com.kwad.sdk.core.e.c.d("HttpProxyCacheServer", socket);
        } catch (Throwable th) {
            b(socket);
            com.kwad.sdk.core.e.c.d("HttpProxyCacheServer", ((String) r0) + Go());
            throw th;
        }
    }
}