中建乐购 v3.2.3版本的 MD5 值为:3856d0da11f056931d64951d23a4b3b8

以下内容为反编译后的 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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class i {
    private static final Logger f6069a = LoggerFactory.getLogger("HttpProxyCacheServer");
    private static final String f6070b = "127.0.0.1";
    private final Object f6071c;
    private final ExecutorService f6072d;
    private final Map<String, j> f6073e;
    private final ServerSocket f6074f;
    private final int f6075g;
    private final Thread f6076h;
    private final f f6077i;
    private final m f6078j;

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

    private i(f fVar) {
        this.f6071c = new Object();
        this.f6072d = Executors.newFixedThreadPool(8);
        this.f6073e = new ConcurrentHashMap();
        this.f6077i = (f) n.a(fVar);
        try {
            this.f6074f = new ServerSocket(0, 8, InetAddress.getByName(f6070b));
            this.f6075g = this.f6074f.getLocalPort();
            l.a(f6070b, this.f6075g);
            CountDownLatch countDownLatch = new CountDownLatch(1);
            this.f6076h = new Thread(new c(countDownLatch));
            this.f6076h.start();
            countDownLatch.await();
            this.f6078j = new m(f6070b, this.f6075g);
            Logger logger = f6069a;
            logger.info("Proxy cache server started. Is it alive? " + b());
        } catch (IOException | InterruptedException e2) {
            this.f6072d.shutdown();
            throw new IllegalStateException("Error starting local proxy server", e2);
        }
    }

    public String a(String str) {
        return a(str, true);
    }

    public String a(String str, boolean z2) {
        if (!z2 || !b(str)) {
            return b() ? c(str) : str;
        }
        File d2 = d(str);
        a(d2);
        return Uri.fromFile(d2).toString();
    }

    public void a(e eVar, String str) {
        n.a(eVar, str);
        synchronized (this.f6071c) {
            try {
                e(str).a(eVar);
            } catch (ProxyCacheException e2) {
                f6069a.warn("Error registering cache listener", (Throwable) e2);
            }
        }
    }

    public void b(e eVar, String str) {
        n.a(eVar, str);
        synchronized (this.f6071c) {
            try {
                e(str).b(eVar);
            } catch (ProxyCacheException e2) {
                f6069a.warn("Error registering cache listener", (Throwable) e2);
            }
        }
    }

    public void a(e eVar) {
        n.a(eVar);
        synchronized (this.f6071c) {
            for (j jVar : this.f6073e.values()) {
                jVar.b(eVar);
            }
        }
    }

    public boolean b(String str) {
        n.a(str, "Url can't be null!");
        return d(str).exists();
    }

    public void a() {
        f6069a.info("Shutdown proxy server");
        c();
        this.f6077i.f6059d.a();
        this.f6076h.interrupt();
        try {
            if (this.f6074f.isClosed()) {
                return;
            }
            this.f6074f.close();
        } catch (IOException e2) {
            a(new ProxyCacheException("Error shutting down proxy server", e2));
        }
    }

    private boolean b() {
        return this.f6078j.a(3, 70);
    }

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

    private File d(String str) {
        return new File(this.f6077i.f6056a, this.f6077i.f6057b.a(str));
    }

    private void a(File file) {
        try {
            this.f6077i.f6058c.a(file);
        } catch (IOException e2) {
            Logger logger = f6069a;
            logger.error("Error touching file " + file, (Throwable) e2);
        }
    }

    private void c() {
        synchronized (this.f6071c) {
            for (j jVar : this.f6073e.values()) {
                jVar.a();
            }
            this.f6073e.clear();
        }
    }

    public void d() {
        while (!Thread.currentThread().isInterrupted()) {
            try {
                Socket accept = this.f6074f.accept();
                Logger logger = f6069a;
                logger.debug("Accept new socket " + accept);
                this.f6072d.submit(new b(accept));
            } catch (IOException e2) {
                a(new ProxyCacheException("Error during waiting connection", e2));
                return;
            }
        }
    }

    public void a(Socket socket) {
        Logger logger;
        StringBuilder sb;
        try {
            try {
                try {
                    g a2 = g.a(socket.getInputStream());
                    Logger logger2 = f6069a;
                    logger2.debug("Request to cache proxy:" + a2);
                    String c2 = p.c(a2.f6062a);
                    if (this.f6078j.a(c2)) {
                        this.f6078j.a(socket);
                    } else {
                        e(c2).a(a2, socket);
                    }
                    b(socket);
                    logger = f6069a;
                    sb = new StringBuilder();
                } catch (SocketException unused) {
                    f6069a.debug("Closing socket… Socket is closed by client.");
                    b(socket);
                    logger = f6069a;
                    sb = new StringBuilder();
                }
            } catch (ProxyCacheException | IOException e2) {
                a(new ProxyCacheException("Error processing request", e2));
                b(socket);
                logger = f6069a;
                sb = new StringBuilder();
            }
            sb.append("Opened connections: ");
            sb.append(e());
            logger.debug(sb.toString());
        } catch (Throwable th) {
            b(socket);
            Logger logger3 = f6069a;
            logger3.debug("Opened connections: " + e());
            throw th;
        }
    }

    private j e(String str) throws ProxyCacheException {
        j jVar;
        synchronized (this.f6071c) {
            jVar = this.f6073e.get(str);
            if (jVar == null) {
                jVar = new j(str, this.f6077i);
                this.f6073e.put(str, jVar);
            }
        }
        return jVar;
    }

    private int e() {
        int i2;
        synchronized (this.f6071c) {
            i2 = 0;
            for (j jVar : this.f6073e.values()) {
                i2 += jVar.b();
            }
        }
        return i2;
    }

    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) {
            f6069a.debug("Releasing input stream… Socket is closed by client.");
        } catch (IOException e2) {
            a(new ProxyCacheException("Error closing socket input stream", e2));
        }
    }

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

    private void e(Socket socket) {
        try {
            if (socket.isClosed()) {
                return;
            }
            socket.close();
        } catch (IOException e2) {
            a(new ProxyCacheException("Error closing socket", e2));
        }
    }

    private void a(Throwable th) {
        f6069a.error("HttpProxyCacheServer error", th);
    }

    private final class c implements Runnable {
        private final CountDownLatch f6087b;

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

        @Override
        public void run() {
            this.f6087b.countDown();
            i.this.d();
        }
    }

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

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

        @Override
        public void run() {
            i.this.a(this.f6085b);
        }
    }

    public static final class a {
        private static final long f6079a = 536870912;
        private File f6080b;
        private di.c f6083e;
        private dh.a f6082d = new dh.h(536870912);
        private dh.c f6081c = new dh.f();

        public a(Context context) {
            this.f6083e = di.d.a(context);
            this.f6080b = t.a(context);
        }

        public a a(File file) {
            this.f6080b = (File) n.a(file);
            return this;
        }

        public a a(dh.c cVar) {
            this.f6081c = (dh.c) n.a(cVar);
            return this;
        }

        public a a(long j2) {
            this.f6082d = new dh.h(j2);
            return this;
        }

        public a a(int i2) {
            this.f6082d = new dh.g(i2);
            return this;
        }

        public a a(dh.a aVar) {
            this.f6082d = (dh.a) n.a(aVar);
            return this;
        }

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

        public f b() {
            return new f(this.f6080b, this.f6081c, this.f6082d, this.f6083e);
        }
    }
}