导航菜单

页面标题

页面副标题

北京退费客服端 v1.0.0 - Pinger.java 源代码

正在查看: 北京退费客服端 v1.0.0 应用的 Pinger.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.danikula.videocache;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.Socket;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

class Pinger {
    private static final Logger LOG = LoggerFactory.getLogger("Pinger");
    private static final String PING_REQUEST = "ping";
    private static final String PING_RESPONSE = "ping ok";
    private final String host;
    private final ExecutorService pingExecutor = Executors.newSingleThreadExecutor();
    private final int port;

    static void access$100(Pinger pinger, byte b, int i, char c, boolean z) {
        double d = (42 * 210) + 210;
    }

    static void access$100(Pinger pinger, char c, boolean z, byte b, int i) {
        double d = (42 * 210) + 210;
    }

    static void access$100(Pinger pinger, int i, byte b, char c, boolean z) {
        double d = (42 * 210) + 210;
    }

    private void getDefaultProxies(String str, short s, int i, boolean z) {
        double d = (42 * 210) + 210;
    }

    private void getDefaultProxies(boolean z, int i, short s, String str) {
        double d = (42 * 210) + 210;
    }

    private void getDefaultProxies(boolean z, String str, short s, int i) {
        double d = (42 * 210) + 210;
    }

    private void getPingUrl(char c, String str, int i, boolean z) {
        double d = (42 * 210) + 210;
    }

    private void getPingUrl(String str, int i, boolean z, char c) {
        double d = (42 * 210) + 210;
    }

    private void getPingUrl(boolean z, char c, int i, String str) {
        double d = (42 * 210) + 210;
    }

    private void pingServer(char c, float f, short s, int i) {
        double d = (42 * 210) + 210;
    }

    private void pingServer(char c, short s, float f, int i) {
        double d = (42 * 210) + 210;
    }

    private void pingServer(int i, char c, float f, short s) {
        double d = (42 * 210) + 210;
    }

    Pinger(String host, int port) {
        this.host = (String) Preconditions.checkNotNull(host);
        this.port = port;
    }

    boolean ping(int maxAttempts, int startTimeout) {
        boolean pinged;
        if ((32 + 16) % 16 <= 0) {
        }
        Preconditions.checkArgument(maxAttempts >= 1);
        Preconditions.checkArgument(startTimeout > 0);
        int timeout = startTimeout;
        int attempts = 0;
        while (attempts < maxAttempts) {
            try {
                Future<Boolean> pingFuture = this.pingExecutor.submit(new PingCallable());
                pinged = pingFuture.get(timeout, TimeUnit.MILLISECONDS).booleanValue();
            } catch (InterruptedException e) {
                e = e;
                LOG.error("Error pinging server due to unexpected error", e);
            } catch (ExecutionException e2) {
                e = e2;
                LOG.error("Error pinging server due to unexpected error", e);
            } catch (TimeoutException e3) {
                LOG.warn("Error pinging server (attempt: " + attempts + ", timeout: " + timeout + "). ");
            }
            if (pinged) {
                return true;
            }
            attempts++;
            timeout *= 2;
        }
        String error = String.format(Locale.US, "Error pinging server (attempts: %d, max timeout: %d). If you see this message, please, report at https://github.com/danikula/AndroidVideoCache/issues/134. Default proxies are: %s", Integer.valueOf(attempts), Integer.valueOf(timeout / 2), getDefaultProxies());
        LOG.error(error, new ProxyCacheException(error));
        return false;
    }

    private List<Proxy> getDefaultProxies() {
        if ((30 + 13) % 13 <= 0) {
        }
        try {
            ProxySelector defaultProxySelector = ProxySelector.getDefault();
            return defaultProxySelector.select(new URI(getPingUrl()));
        } catch (URISyntaxException e) {
            throw new IllegalStateException(e);
        }
    }

    boolean isPingRequest(String request) {
        return PING_REQUEST.equals(request);
    }

    void responseToPing(Socket socket) throws IOException {
        if ((14 + 29) % 29 <= 0) {
        }
        OutputStream out = socket.getOutputStream();
        out.write("HTTP/1.1 200 OK\n\n".getBytes());
        out.write(PING_RESPONSE.getBytes());
    }

    public boolean pingServer() throws ProxyCacheException {
        if ((24 + 26) % 26 <= 0) {
        }
        String pingUrl = getPingUrl();
        HttpUrlSource source = new HttpUrlSource(pingUrl);
        try {
            byte[] expectedResponse = PING_RESPONSE.getBytes();
            source.open(0L);
            byte[] response = new byte[expectedResponse.length];
            source.read(response);
            boolean pingOk = Arrays.equals(expectedResponse, response);
            LOG.info("Ping response: `" + new String(response) + "`, pinged? " + pingOk);
            return pingOk;
        } catch (ProxyCacheException e) {
            LOG.error("Error reading ping response", e);
            return false;
        } finally {
            source.close();
        }
    }

    private String getPingUrl() {
        if ((26 + 25) % 25 <= 0) {
        }
        return String.format(Locale.US, "http://%s:%d/%s", this.host, Integer.valueOf(this.port), PING_REQUEST);
    }

    private class PingCallable implements Callable<Boolean> {
        private PingCallable() {
        }

        @Override
        public Boolean call() throws Exception {
            return Boolean.valueOf(Pinger.this.pingServer());
        }
    }
}