package ඓ.ῲ.K.ᕣ.㿎;

import android.text.TextUtils;
import android.util.Log;
import com.appsflyer.share.Constants;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.HttpException;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Map;
import ඓ.ῲ.K.ᓣ.C0824;
import ඓ.ῲ.K.ᓣ.C0847;
import ඓ.ῲ.K.ᕣ.㳳.C1085;
import ඓ.ῲ.K.ᕣ.㿎.AbstractC1146;
import ඓ.K.K.K.C1293;

/* renamed from: ඓ.ῲ.K.ᕣ.㿎.㳳  reason: contains not printable characters */
/* compiled from: HttpUrlFetcher */
public class C1140 implements AbstractC1146<InputStream> {

    /* renamed from: 㿎  reason: contains not printable characters */
    public static final AbstractC1141 f4618 = new C1142();

    /* renamed from: ʬ  reason: contains not printable characters */
    public final int f4619;

    /* renamed from: ඓ  reason: contains not printable characters */
    public HttpURLConnection f4620;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final C1085 f4621;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public volatile boolean f4622;

    /* renamed from: 㴹  reason: contains not printable characters */
    public InputStream f4623;

    /* renamed from: 㸾  reason: contains not printable characters */
    public final AbstractC1141 f4624;

    /* renamed from: ඓ.ῲ.K.ᕣ.㿎.㳳$ῲ  reason: contains not printable characters */
    /* compiled from: HttpUrlFetcher */
    public interface AbstractC1141 {
    }

    /* renamed from: ඓ.ῲ.K.ᕣ.㿎.㳳$K  reason: contains not printable characters */
    /* compiled from: HttpUrlFetcher */
    public static class C1142 implements AbstractC1141 {
        /* renamed from: K  reason: contains not printable characters */
        public HttpURLConnection m3057(URL url) throws IOException {
            return (HttpURLConnection) url.openConnection();
        }
    }

    public C1140(C1085 r2, int i) {
        AbstractC1141 r0 = f4618;
        this.f4621 = r2;
        this.f4619 = i;
        this.f4624 = r0;
    }

    @Override // ඓ.ῲ.K.ᕣ.㿎.AbstractC1146
    public void cancel() {
        this.f4622 = true;
    }

    @Override // ඓ.ῲ.K.ᕣ.㿎.AbstractC1146
    /* renamed from: ʬ  reason: contains not printable characters */
    public DataSource m3052() {
        return DataSource.REMOTE;
    }

    @Override // ඓ.ῲ.K.ᕣ.㿎.AbstractC1146
    /* renamed from: ῲ  reason: contains not printable characters */
    public void m3053() {
        InputStream inputStream = this.f4623;
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException unused) {
            }
        }
        HttpURLConnection httpURLConnection = this.f4620;
        if (httpURLConnection != null) {
            httpURLConnection.disconnect();
        }
        this.f4620 = null;
    }

    @Override // ඓ.ῲ.K.ᕣ.㿎.AbstractC1146
    /* renamed from: K  reason: contains not printable characters */
    public void m3056(Priority priority, AbstractC1146.AbstractC1147<? super InputStream> k) {
        StringBuilder sb;
        long r1 = C0847.m2463();
        try {
            k.m3069(m3054(this.f4621.m2939(), 0, null, this.f4621.f4544.m2994()));
            if (Log.isLoggable("HttpUrlFetcher", 2)) {
                sb = new StringBuilder();
                sb.append("Finished http url fetcher fetch in ");
                sb.append(C0847.m2462(r1));
                Log.v("HttpUrlFetcher", sb.toString());
            }
        } catch (IOException e) {
            if (Log.isLoggable("HttpUrlFetcher", 3)) {
                Log.d("HttpUrlFetcher", "Failed to load data for url", e);
            }
            k.m3068((Exception) e);
            if (Log.isLoggable("HttpUrlFetcher", 2)) {
                sb = new StringBuilder();
            }
        } catch (Throwable th) {
            if (Log.isLoggable("HttpUrlFetcher", 2)) {
                StringBuilder r9 = C1293.m3416("Finished http url fetcher fetch in ");
                r9.append(C0847.m2462(r1));
                Log.v("HttpUrlFetcher", r9.toString());
            }
            throw th;
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final InputStream m3054(URL url, int i, URL url2, Map<String, String> map) throws IOException {
        if (i < 5) {
            if (url2 != null) {
                try {
                    if (url.toURI().equals(url2.toURI())) {
                        throw new HttpException("In re-direct loop");
                    }
                } catch (URISyntaxException unused) {
                }
            }
            this.f4620 = ((C1142) this.f4624).m3057(url);
            for (Map.Entry<String, String> entry : map.entrySet()) {
                this.f4620.addRequestProperty(entry.getKey(), entry.getValue());
            }
            this.f4620.setConnectTimeout(this.f4619);
            this.f4620.setReadTimeout(this.f4619);
            boolean z = false;
            this.f4620.setUseCaches(false);
            this.f4620.setDoInput(true);
            this.f4620.setInstanceFollowRedirects(false);
            this.f4620.connect();
            this.f4623 = this.f4620.getInputStream();
            if (this.f4622) {
                return null;
            }
            int responseCode = this.f4620.getResponseCode();
            int i2 = responseCode / 100;
            if (i2 == 2) {
                HttpURLConnection httpURLConnection = this.f4620;
                if (TextUtils.isEmpty(httpURLConnection.getContentEncoding())) {
                    this.f4623 = new C0824(httpURLConnection.getInputStream(), (long) httpURLConnection.getContentLength());
                } else {
                    if (Log.isLoggable("HttpUrlFetcher", 3)) {
                        StringBuilder r8 = C1293.m3416("Got non empty content encoding: ");
                        r8.append(httpURLConnection.getContentEncoding());
                        Log.d("HttpUrlFetcher", r8.toString());
                    }
                    this.f4623 = httpURLConnection.getInputStream();
                }
                return this.f4623;
            }
            if (i2 == 3) {
                z = true;
            }
            if (z) {
                String headerField = this.f4620.getHeaderField(Constants.HTTP_REDIRECT_URL_HEADER_FIELD);
                if (!TextUtils.isEmpty(headerField)) {
                    URL url3 = new URL(url, headerField);
                    m3053();
                    return m3054(url3, i + 1, url, map);
                }
                throw new HttpException("Received empty or null redirect url");
            } else if (responseCode == -1) {
                throw new HttpException(responseCode);
            } else {
                throw new HttpException(this.f4620.getResponseMessage(), responseCode);
            }
        } else {
            throw new HttpException("Too many (> 5) redirects!");
        }
    }

    @Override // ඓ.ῲ.K.ᕣ.㿎.AbstractC1146
    /* renamed from: K  reason: contains not printable characters */
    public Class<InputStream> m3055() {
        return InputStream.class;
    }
}
