50度灰 v5.8.2版本的 MD5 值为:9fe3d350fdc75fa1a3ec45509fa0107e

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


package com.danikula.videocache;

import android.content.Context;
import android.net.Uri;
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 i {
    private static final String f2234a = "127.0.0.1";
    private final Object f2235b;
    private final ExecutorService f2236c;
    private final Map<String, j> f2237d;
    private final ServerSocket f2238e;
    private final int f2239f;
    private final Thread f2240g;
    private final e h;
    private final m i;

    public static final class b {
        private static final long f2241a = 536870912;
        private File f2242b;
        private com.danikula.videocache.v.c f2245e;
        private com.danikula.videocache.t.a f2244d = new com.danikula.videocache.t.h(536870912);
        private com.danikula.videocache.t.c f2243c = new com.danikula.videocache.t.f();
        private com.danikula.videocache.u.b f2246f = new com.danikula.videocache.u.a();

        public b(Context context) {
            this.f2245e = com.danikula.videocache.v.d.b(context);
            this.f2242b = s.c(context);
        }

        public e c() {
            return new e(this.f2242b, this.f2243c, this.f2244d, this.f2245e, this.f2246f);
        }

        public i b() {
            return new i(c());
        }

        public b d(File file) {
            this.f2242b = (File) n.d(file);
            return this;
        }

        public b e(com.danikula.videocache.t.a aVar) {
            this.f2244d = (com.danikula.videocache.t.a) n.d(aVar);
            return this;
        }

        public b f(com.danikula.videocache.t.c cVar) {
            this.f2243c = (com.danikula.videocache.t.c) n.d(cVar);
            return this;
        }

        public b g(com.danikula.videocache.u.b bVar) {
            this.f2246f = (com.danikula.videocache.u.b) n.d(bVar);
            return this;
        }

        public b h(int i) {
            this.f2244d = new com.danikula.videocache.t.g(i);
            return this;
        }

        public b i(long j) {
            this.f2244d = new com.danikula.videocache.t.h(j);
            return this;
        }
    }

    public final class c implements Runnable {
        private final Socket f2247a;

        public c(Socket socket) {
            this.f2247a = socket;
        }

        @Override
        public void run() {
            i.this.o(this.f2247a);
        }
    }

    private final class d implements Runnable {
        private final CountDownLatch f2249a;

        public d(CountDownLatch countDownLatch) {
            this.f2249a = countDownLatch;
        }

        @Override
        public void run() {
            this.f2249a.countDown();
            i.this.w();
        }
    }

    private String c(String str) {
        return String.format(Locale.US, "http://%s:%d/%s", f2234a, Integer.valueOf(this.f2239f), p.f(str));
    }

    private void d(Socket socket) {
        try {
            if (socket.isClosed()) {
                return;
            }
            socket.close();
        } catch (IOException unused) {
        }
    }

    private void e(Socket socket) {
        try {
            if (socket.isInputShutdown()) {
                return;
            }
            socket.shutdownInput();
        } catch (SocketException | IOException unused) {
        }
    }

    private void f(Socket socket) {
        try {
            if (socket.isOutputShutdown()) {
                return;
            }
            socket.shutdownOutput();
        } catch (IOException e2) {
            h.k("Failed to close socket on proxy side: {}. It seems client have already closed connection.", e2.getMessage());
        }
    }

    private File g(String str) {
        e eVar = this.h;
        return new File(eVar.f2222a, eVar.f2223b.a(str));
    }

    private j h(String str) throws ProxyCacheException {
        j jVar;
        synchronized (this.f2235b) {
            jVar = this.f2237d.get(str);
            if (jVar == null) {
                jVar = new j(str, this.h);
                this.f2237d.put(str, jVar);
            }
        }
        return jVar;
    }

    private int i() {
        int i;
        synchronized (this.f2235b) {
            i = 0;
            for (j jVar : this.f2237d.values()) {
                i += jVar.b();
            }
        }
        return i;
    }

    private boolean l() {
        return this.i.e(3, 70);
    }

    private void n(Throwable th) {
        h.g("HttpProxyCacheServer error", th.getMessage());
    }

    public void o(Socket socket) {
        StringBuilder sb;
        try {
            try {
                f c2 = f.c(socket.getInputStream());
                String e2 = p.e(c2.f2229c);
                if (this.i.d(e2)) {
                    this.i.g(socket);
                } else {
                    h(e2).d(c2, socket);
                }
                q(socket);
                sb = new StringBuilder();
            } catch (Throwable th) {
                q(socket);
                h.h("Opened connections: " + i());
                throw th;
            }
        } catch (ProxyCacheException e3) {
            e = e3;
            n(new ProxyCacheException("Error processing request", e));
            q(socket);
            sb = new StringBuilder();
        } catch (SocketException unused) {
            q(socket);
            sb = new StringBuilder();
        } catch (IOException e4) {
            e = e4;
            n(new ProxyCacheException("Error processing request", e));
            q(socket);
            sb = new StringBuilder();
        }
        sb.append("Opened connections: ");
        sb.append(i());
        h.h(sb.toString());
    }

    private void q(Socket socket) {
        e(socket);
        f(socket);
        d(socket);
    }

    private void s() {
        synchronized (this.f2235b) {
            for (j jVar : this.f2237d.values()) {
                jVar.f();
            }
            this.f2237d.clear();
        }
    }

    private void t(File file) {
        try {
            this.h.f2224c.a(file);
        } catch (IOException e2) {
            h.f("Error touching file " + file, e2);
        }
    }

    public void w() {
        while (!Thread.currentThread().isInterrupted()) {
            try {
                this.f2236c.submit(new c(this.f2238e.accept()));
            } catch (IOException e2) {
                n(new ProxyCacheException("Error during waiting connection", e2));
                return;
            }
        }
    }

    public String j(String str) {
        return k(str, true);
    }

    public String k(String str, boolean z) {
        if (!z || !m(str)) {
            return l() ? c(str) : str;
        }
        File g2 = g(str);
        t(g2);
        return Uri.fromFile(g2).toString();
    }

    public boolean m(String str) {
        n.e(str, "Url can't be null!");
        return g(str).exists();
    }

    public void p(com.danikula.videocache.d dVar, String str) {
        n.a(dVar, str);
        synchronized (this.f2235b) {
            try {
                h(str).e(dVar);
            } catch (ProxyCacheException e2) {
                h.k("Error registering cache listener", e2.getMessage());
            }
        }
    }

    public void r() {
        h.h("Shutdown proxy server");
        s();
        this.h.f2225d.release();
        this.f2240g.interrupt();
        try {
            if (this.f2238e.isClosed()) {
                return;
            }
            this.f2238e.close();
        } catch (IOException e2) {
            n(new ProxyCacheException("Error shutting down proxy server", e2));
        }
    }

    public void u(com.danikula.videocache.d dVar) {
        n.d(dVar);
        synchronized (this.f2235b) {
            for (j jVar : this.f2237d.values()) {
                jVar.h(dVar);
            }
        }
    }

    public void v(com.danikula.videocache.d dVar, String str) {
        n.a(dVar, str);
        synchronized (this.f2235b) {
            try {
                h(str).h(dVar);
            } catch (ProxyCacheException e2) {
                h.k("Error registering cache listener", e2.getMessage());
            }
        }
    }

    public i(Context context) {
        this(new b(context).c());
    }

    private i(e eVar) {
        this.f2235b = new Object();
        this.f2236c = Executors.newFixedThreadPool(8);
        this.f2237d = new ConcurrentHashMap();
        this.h = (e) n.d(eVar);
        try {
            ServerSocket serverSocket = new ServerSocket(0, 8, InetAddress.getByName(f2234a));
            this.f2238e = serverSocket;
            int localPort = serverSocket.getLocalPort();
            this.f2239f = localPort;
            l.a(f2234a, localPort);
            CountDownLatch countDownLatch = new CountDownLatch(1);
            Thread thread = new Thread(new d(countDownLatch));
            this.f2240g = thread;
            thread.start();
            countDownLatch.await();
            this.i = new m(f2234a, localPort);
            h.h("Proxy cache server started. Is it alive? " + l());
        } catch (IOException | InterruptedException e2) {
            this.f2236c.shutdown();
            throw new IllegalStateException("Error starting local proxy server", e2);
        }
    }
}