package IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5;

import IMuAHx_6.KQgRr5e_0.KQgRr5e_0.IFxWkV_5;
import IMuAHx_6.KQgRr5e_0.KQgRr5e_0.Mqv2r_3;
import IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.ProtocolException;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;
/* compiled from: DownloadUrlConnection.java */
/* loaded from: classes.dex */
public class PGPF6hQ_2 implements IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0, KQgRr5e_0.InterfaceC0002KQgRr5e_0 {
    public Mqv2r_3 KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public KQgRr5e_0 f99KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public URL f100KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public URLConnection f101KQgRr5e_0;

    /* compiled from: DownloadUrlConnection.java */
    /* loaded from: classes.dex */
    public static class KQgRr5e_0 {
        public Integer KQgRr5e_0;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public Proxy f102KQgRr5e_0;
        public Integer QxJ9d_1;
    }

    /* compiled from: DownloadUrlConnection.java */
    /* loaded from: classes.dex */
    public static class QxJ9d_1 implements KQgRr5e_0.QxJ9d_1 {
        public final KQgRr5e_0 KQgRr5e_0;

        public QxJ9d_1() {
            this(null);
        }

        @Override // IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0.QxJ9d_1
        public IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0 KQgRr5e_0(String str) throws IOException {
            return new PGPF6hQ_2(str, this.KQgRr5e_0);
        }

        public QxJ9d_1(KQgRr5e_0 kQgRr5e_0) {
            this.KQgRr5e_0 = kQgRr5e_0;
        }
    }

    public PGPF6hQ_2(String str, KQgRr5e_0 kQgRr5e_0) throws IOException {
        this(new URL(str), kQgRr5e_0);
    }

    @Override // IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0
    public void QxJ9d_1() throws IOException {
        IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.PGPF6hQ_2.KQgRr5e_0("DownloadUrlConnection", "config connection for " + this.f100KQgRr5e_0);
        KQgRr5e_0 kQgRr5e_0 = this.f99KQgRr5e_0;
        if (kQgRr5e_0 != null && kQgRr5e_0.f102KQgRr5e_0 != null) {
            this.f101KQgRr5e_0 = this.f100KQgRr5e_0.openConnection(this.f99KQgRr5e_0.f102KQgRr5e_0);
        } else {
            this.f101KQgRr5e_0 = this.f100KQgRr5e_0.openConnection();
        }
        URLConnection uRLConnection = this.f101KQgRr5e_0;
        if (uRLConnection instanceof HttpURLConnection) {
            ((HttpURLConnection) uRLConnection).setInstanceFollowRedirects(false);
        }
        KQgRr5e_0 kQgRr5e_02 = this.f99KQgRr5e_0;
        if (kQgRr5e_02 != null) {
            if (kQgRr5e_02.KQgRr5e_0 != null) {
                this.f101KQgRr5e_0.setReadTimeout(this.f99KQgRr5e_0.KQgRr5e_0.intValue());
            }
            if (this.f99KQgRr5e_0.QxJ9d_1 != null) {
                this.f101KQgRr5e_0.setConnectTimeout(this.f99KQgRr5e_0.QxJ9d_1.intValue());
            }
        }
    }

    public PGPF6hQ_2(URL url, KQgRr5e_0 kQgRr5e_0) throws IOException {
        this(url, kQgRr5e_0, new C0003PGPF6hQ_2());
    }

    @Override // IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0
    public void KQgRr5e_0(String str, String str2) {
        this.f101KQgRr5e_0.addRequestProperty(str, str2);
    }

    public PGPF6hQ_2(URL url, KQgRr5e_0 kQgRr5e_0, Mqv2r_3 mqv2r_3) throws IOException {
        this.f99KQgRr5e_0 = kQgRr5e_0;
        this.f100KQgRr5e_0 = url;
        this.KQgRr5e_0 = mqv2r_3;
        QxJ9d_1();
    }

    @Override // IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0, IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0.InterfaceC0002KQgRr5e_0
    public KQgRr5e_0.InterfaceC0002KQgRr5e_0 KQgRr5e_0() throws IOException {
        Map<String, List<String>> QxJ9d_12 = QxJ9d_1();
        this.f101KQgRr5e_0.connect();
        this.KQgRr5e_0.KQgRr5e_0(this, this, QxJ9d_12);
        return this;
    }

    @Override // IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0, IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0.InterfaceC0002KQgRr5e_0
    public int KQgRr5e_0() throws IOException {
        URLConnection uRLConnection = this.f101KQgRr5e_0;
        if (uRLConnection instanceof HttpURLConnection) {
            return ((HttpURLConnection) uRLConnection).getResponseCode();
        }
        return 0;
    }

    @Override // IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0, IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0.InterfaceC0002KQgRr5e_0
    public InputStream KQgRr5e_0() throws IOException {
        return this.f101KQgRr5e_0.getInputStream();
    }

    @Override // IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0, IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0.InterfaceC0002KQgRr5e_0
    public boolean KQgRr5e_0(String str) throws ProtocolException {
        URLConnection uRLConnection = this.f101KQgRr5e_0;
        if (uRLConnection instanceof HttpURLConnection) {
            ((HttpURLConnection) uRLConnection).setRequestMethod(str);
            return true;
        }
        return false;
    }

    /* compiled from: DownloadUrlConnection.java */
    /* renamed from: IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.PGPF6hQ_2$PGPF6hQ_2  reason: collision with other inner class name */
    /* loaded from: classes.dex */
    public static final class C0003PGPF6hQ_2 implements Mqv2r_3 {
        public String KQgRr5e_0;

        @Override // IMuAHx_6.KQgRr5e_0.KQgRr5e_0.Mqv2r_3
        public void KQgRr5e_0(IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0 kQgRr5e_0, KQgRr5e_0.InterfaceC0002KQgRr5e_0 interfaceC0002KQgRr5e_0, Map<String, List<String>> map) throws IOException {
            PGPF6hQ_2 pGPF6hQ_2 = (PGPF6hQ_2) kQgRr5e_0;
            int i = 0;
            for (int KQgRr5e_0 = interfaceC0002KQgRr5e_0.KQgRr5e_0(); IFxWkV_5.KQgRr5e_0(KQgRr5e_0); KQgRr5e_0 = pGPF6hQ_2.KQgRr5e_0()) {
                pGPF6hQ_2.KQgRr5e_0();
                i++;
                if (i <= 10) {
                    this.KQgRr5e_0 = IFxWkV_5.KQgRr5e_0(interfaceC0002KQgRr5e_0, KQgRr5e_0);
                    pGPF6hQ_2.f100KQgRr5e_0 = new URL(this.KQgRr5e_0);
                    pGPF6hQ_2.QxJ9d_1();
                    IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.PGPF6hQ_2.KQgRr5e_0(map, pGPF6hQ_2);
                    pGPF6hQ_2.f101KQgRr5e_0.connect();
                } else {
                    throw new ProtocolException("Too many redirect requests: " + i);
                }
            }
        }

        @Override // IMuAHx_6.KQgRr5e_0.KQgRr5e_0.Mqv2r_3
        public String KQgRr5e_0() {
            return this.KQgRr5e_0;
        }
    }

    @Override // IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0, IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0.InterfaceC0002KQgRr5e_0
    public Map<String, List<String>> KQgRr5e_0() {
        return this.f101KQgRr5e_0.getHeaderFields();
    }

    @Override // IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0, IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0.InterfaceC0002KQgRr5e_0
    public String KQgRr5e_0(String str) {
        return this.f101KQgRr5e_0.getHeaderField(str);
    }

    @Override // IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0
    public Map<String, List<String>> QxJ9d_1() {
        return this.f101KQgRr5e_0.getRequestProperties();
    }

    @Override // IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0, IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0.InterfaceC0002KQgRr5e_0
    public String KQgRr5e_0() {
        return this.KQgRr5e_0.KQgRr5e_0();
    }

    @Override // IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0, IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.IFxWkV_5.KQgRr5e_0.InterfaceC0002KQgRr5e_0
    public void KQgRr5e_0() {
        try {
            InputStream inputStream = this.f101KQgRr5e_0.getInputStream();
            if (inputStream != null) {
                inputStream.close();
            }
        } catch (IOException unused) {
        }
    }
}
