package com.baidu.cloud.videocache; import java.io.OutputStream; 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.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /* loaded from: classes.dex */ class q { private static final Logger d = LoggerFactory.getLogger("Pinger"); private final ExecutorService a = Executors.newSingleThreadExecutor(); private final String b; private final int c; q(String str, int i) { t.a(str); this.b = str; this.c = i; } private List a() { try { return ProxySelector.getDefault().select(new URI(c())); } catch (URISyntaxException e) { throw new IllegalStateException(e); } } /* JADX INFO: Access modifiers changed from: private */ public boolean b() { n nVar = new n(c()); try { byte[] bytes = "ping ok".getBytes(); nVar.a(0L); byte[] bArr = new byte[bytes.length]; nVar.read(bArr); boolean equals = Arrays.equals(bytes, bArr); d.info("Ping response: `" + new String(bArr) + "`, pinged? " + equals); return equals; } catch (x e) { d.error("Error reading ping response", e); return false; } finally { nVar.close(); } } private String c() { return String.format(Locale.US, "http://%s:%d/%s", this.b, Integer.valueOf(this.c), "ping"); } void a(Socket socket) { OutputStream outputStream = socket.getOutputStream(); outputStream.write("HTTP/1.1 200 OK\n\n".getBytes()); outputStream.write("ping ok".getBytes()); } boolean a(int i, int i2) { t.a(i >= 1); t.a(i2 > 0); int i3 = i2; int i4 = 0; while (i4 < i) { try { } catch (InterruptedException e) { e = e; d.error("Error pinging server due to unexpected error", e); } catch (ExecutionException e2) { e = e2; d.error("Error pinging server due to unexpected error", e); } catch (TimeoutException unused) { d.warn("Error pinging server (attempt: " + i4 + ", timeout: " + i3 + "). "); } if (((Boolean) this.a.submit(new s(this)).get(i3, TimeUnit.MILLISECONDS)).booleanValue()) { return true; } i4++; i3 *= 2; } String format = String.format(Locale.US, "Error pinging server (attempts: %d, max timeout: %d). If you see this message, please, report athttps://github.com/danikula/AndroidVideoCache/issues/134. Default proxies are: %s", Integer.valueOf(i4), Integer.valueOf(i3 / 2), a()); d.error(format, new x(format)); return false; } boolean a(String str) { return "ping".equals(str); } }