流利说-英语 v8.47.26版本的 MD5 值为:0079dce5ff96e6cdbc95c261b3f51387

以下内容为反编译后的 f.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.Iterator;
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 f {
    private static final org.slf4j.b HQ = org.slf4j.c.wJ("HttpProxyCacheServer");
    private final Object HR;
    private final ExecutorService HS;
    private final Map<String, g> HT;
    private final ServerSocket HU;
    private final Thread HV;
    private final com.danikula.videocache.c HW;
    private final i HX;
    private final int port;

    private f(com.danikula.videocache.c cVar) {
        this.HR = new Object();
        this.HS = Executors.newFixedThreadPool(8);
        this.HT = new ConcurrentHashMap();
        this.HW = (com.danikula.videocache.c) j.checkNotNull(cVar);
        try {
            this.HU = new ServerSocket(0, 8, InetAddress.getByName("127.0.0.1"));
            this.port = this.HU.getLocalPort();
            CountDownLatch countDownLatch = new CountDownLatch(1);
            this.HV = new Thread(new c(countDownLatch));
            this.HV.start();
            countDownLatch.await();
            this.HX = new i("127.0.0.1", this.port);
            HQ.info("Proxy cache server started. Is it alive? " + isAlive());
        } catch (IOException | InterruptedException e) {
            this.HS.shutdown();
            throw new IllegalStateException("Error starting local proxy server", e);
        }
    }

    public String aV(String str) {
        return c(str, true);
    }

    public String c(String str, boolean z) {
        if (!z || !aW(str)) {
            return isAlive() ? aX(str) : str;
        }
        File aY = aY(str);
        p(aY);
        return Uri.fromFile(aY).toString();
    }

    public boolean aW(String str) {
        j.checkNotNull(str, "Url can't be null!");
        return aY(str).exists();
    }

    private boolean isAlive() {
        return this.HX.s(3, 70);
    }

    private String aX(String str) {
        return String.format(Locale.US, "http://%s:%d/%s", "127.0.0.1", Integer.valueOf(this.port), l.encode(str));
    }

    private File aY(String str) {
        return new File(this.HW.HG, this.HW.HH.bd(str));
    }

    private void p(File file) {
        try {
            this.HW.HI.touch(file);
        } catch (IOException e) {
            HQ.error("Error touching file " + file, (Throwable) e);
        }
    }

    public void ki() {
        while (!Thread.currentThread().isInterrupted()) {
            try {
                Socket accept = this.HU.accept();
                HQ.debug("Accept new socket " + accept);
                this.HS.submit(new b(accept));
            } catch (IOException e) {
                onError(new ProxyCacheException("Error during waiting connection", e));
                return;
            }
        }
    }

    public void b(Socket socket) {
        org.slf4j.b bVar;
        StringBuilder sb;
        try {
            try {
                d j = d.j(socket.getInputStream());
                HQ.debug("Request to cache proxy:" + j);
                String decode = l.decode(j.uri);
                if (this.HX.ba(decode)) {
                    this.HX.g(socket);
                } else {
                    aZ(decode).a(j, socket);
                }
                c(socket);
                bVar = HQ;
                sb = new StringBuilder();
            } catch (ProxyCacheException e) {
                e = e;
                onError(new ProxyCacheException("Error processing request", e));
                c(socket);
                bVar = HQ;
                sb = new StringBuilder();
            } catch (SocketException unused) {
                HQ.debug("Closing socket… Socket is closed by client.");
                c(socket);
                bVar = HQ;
                sb = new StringBuilder();
            } catch (IOException e2) {
                e = e2;
                onError(new ProxyCacheException("Error processing request", e));
                c(socket);
                bVar = HQ;
                sb = new StringBuilder();
            }
            sb.append("Opened connections: ");
            sb.append(kj());
            bVar.debug(sb.toString());
        } catch (Throwable th) {
            c(socket);
            HQ.debug("Opened connections: " + kj());
            throw th;
        }
    }

    private g aZ(String str) throws ProxyCacheException {
        g gVar;
        synchronized (this.HR) {
            gVar = this.HT.get(str);
            if (gVar == null) {
                gVar = new g(str, this.HW);
                this.HT.put(str, gVar);
            }
        }
        return gVar;
    }

    private int kj() {
        int i;
        synchronized (this.HR) {
            i = 0;
            Iterator<g> it = this.HT.values().iterator();
            while (it.hasNext()) {
                i += it.next().kj();
            }
        }
        return i;
    }

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

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

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

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

    private void onError(Throwable th) {
        HQ.error("HttpProxyCacheServer error", th);
    }

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

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

        @Override
        public void run() {
            this.HZ.countDown();
            f.this.ki();
        }
    }

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

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

        @Override
        public void run() {
            f.this.b(this.socket);
        }
    }

    public static final class a {
        private File HG;
        private com.danikula.videocache.b.c HJ;
        private com.danikula.videocache.a.a HI = new com.danikula.videocache.a.g(536870912);
        private com.danikula.videocache.a.c HH = new com.danikula.videocache.a.f();

        public a(Context context) {
            this.HJ = com.danikula.videocache.b.d.aw(context);
            this.HG = o.au(context);
        }

        public a q(File file) {
            this.HG = (File) j.checkNotNull(file);
            return this;
        }

        public a u(long j) {
            this.HI = new com.danikula.videocache.a.g(j);
            return this;
        }

        public f kk() {
            return new f(kl());
        }

        private com.danikula.videocache.c kl() {
            return new com.danikula.videocache.c(this.HG, this.HH, this.HI, this.HJ);
        }
    }
}