package p138.p176.p177.p242.p265.p266;

import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.Map;
import p000.p001.p002.p003.p004.C0567;

/* JADX INFO: renamed from: ދ.ހ.֏.ހ.ބ.֏.ˏ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class RunnableC4819 implements Runnable {

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final URL f14498;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final byte[] f14499;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public final InterfaceC4865 f14500;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public final String f14501;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public final Map<String, String> f14502;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public final /* synthetic */ C5039 f14503;

    public RunnableC4819(C5039 c5039, String str, URL url, byte[] bArr, Map<String, String> map, InterfaceC4865 interfaceC4865) {
        this.f14503 = c5039;
        C0567.m1926(str);
        C0567.m1910(url);
        C0567.m1910(interfaceC4865);
        this.f14498 = url;
        this.f14499 = bArr;
        this.f14500 = interfaceC4865;
        this.f14501 = str;
        this.f14502 = map;
    }

    /* JADX WARN: Removed duplicated region for block: B:47:0x00f0  */
    /* JADX WARN: Removed duplicated region for block: B:60:0x0134  */
    /* JADX WARN: Removed duplicated region for block: B:63:0x011c A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:65:0x00d8 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    @Override // java.lang.Runnable
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void run() throws Throwable {
        HttpURLConnection httpURLConnectionM8533;
        Map<String, List<String>> map;
        Map<String, List<String>> map2;
        Throwable th;
        IOException iOException;
        int i;
        int i2;
        Map<String, List<String>> headerFields;
        this.f14503.mo8006();
        OutputStream outputStream = null;
        try {
            httpURLConnectionM8533 = this.f14503.m8533(this.f14498);
        } catch (IOException e) {
            e = e;
            httpURLConnectionM8533 = null;
            map2 = null;
        } catch (Throwable th2) {
            th = th2;
            httpURLConnectionM8533 = null;
            map = null;
        }
        try {
            if (this.f14502 != null) {
                for (Map.Entry<String, String> entry : this.f14502.entrySet()) {
                    httpURLConnectionM8533.addRequestProperty(entry.getKey(), entry.getValue());
                }
            }
            if (this.f14499 != null) {
                byte[] bArrM8143 = this.f14503.m8157().m8143(this.f14499);
                this.f14503.mo8165().f14452.m8035("Uploading data. size", Integer.valueOf(bArrM8143.length));
                httpURLConnectionM8533.setDoOutput(true);
                httpURLConnectionM8533.addRequestProperty("Content-Encoding", "gzip");
                httpURLConnectionM8533.setFixedLengthStreamingMode(bArrM8143.length);
                httpURLConnectionM8533.connect();
                OutputStream outputStream2 = httpURLConnectionM8533.getOutputStream();
                try {
                    outputStream2.write(bArrM8143);
                    outputStream2.close();
                } catch (IOException e2) {
                    map2 = null;
                    iOException = e2;
                    outputStream = outputStream2;
                    i2 = 0;
                    if (outputStream != null) {
                    }
                    if (httpURLConnectionM8533 != null) {
                    }
                    C4771 c4771Mo8163 = this.f14503.mo8163();
                    RunnableC4893 runnableC4893 = new RunnableC4893(this.f14501, this.f14500, i2, iOException, null, map2, null);
                    c4771Mo8163.m8482();
                    C0567.m1910(runnableC4893);
                    c4771Mo8163.m8005(new C4894<>(c4771Mo8163, runnableC4893, "Task exception on worker thread"));
                } catch (Throwable th3) {
                    map = null;
                    th = th3;
                    outputStream = outputStream2;
                    i = 0;
                    if (outputStream != null) {
                    }
                    if (httpURLConnectionM8533 != null) {
                    }
                    C4771 c4771Mo81632 = this.f14503.mo8163();
                    RunnableC4893 runnableC48932 = new RunnableC4893(this.f14501, this.f14500, i, null, null, map, null);
                    c4771Mo81632.m8482();
                    C0567.m1910(runnableC48932);
                    c4771Mo81632.m8005(new C4894<>(c4771Mo81632, runnableC48932, "Task exception on worker thread"));
                    throw th;
                }
            }
            int responseCode = httpURLConnectionM8533.getResponseCode();
            try {
                headerFields = httpURLConnectionM8533.getHeaderFields();
            } catch (IOException e3) {
                e = e3;
                map2 = null;
                i2 = responseCode;
            } catch (Throwable th4) {
                map = null;
                th = th4;
                i = responseCode;
            }
            try {
                byte[] bArrM8532 = C5039.m8532(httpURLConnectionM8533);
                httpURLConnectionM8533.disconnect();
                C4771 c4771Mo81633 = this.f14503.mo8163();
                RunnableC4893 runnableC48933 = new RunnableC4893(this.f14501, this.f14500, responseCode, null, bArrM8532, headerFields, null);
                c4771Mo81633.m8482();
                C0567.m1910(runnableC48933);
                c4771Mo81633.m8005(new C4894<>(c4771Mo81633, runnableC48933, "Task exception on worker thread"));
            } catch (IOException e4) {
                e = e4;
                i2 = responseCode;
                map2 = headerFields;
                iOException = e;
                if (outputStream != null) {
                    try {
                        outputStream.close();
                    } catch (IOException e5) {
                        this.f14503.mo8165().f14444.m8036("Error closing HTTP compressed POST connection output stream. appId", C4794.m8038(this.f14501), e5);
                    }
                }
                if (httpURLConnectionM8533 != null) {
                    httpURLConnectionM8533.disconnect();
                }
                C4771 c4771Mo81634 = this.f14503.mo8163();
                RunnableC4893 runnableC48934 = new RunnableC4893(this.f14501, this.f14500, i2, iOException, null, map2, null);
                c4771Mo81634.m8482();
                C0567.m1910(runnableC48934);
                c4771Mo81634.m8005(new C4894<>(c4771Mo81634, runnableC48934, "Task exception on worker thread"));
            } catch (Throwable th5) {
                th = th5;
                i = responseCode;
                map = headerFields;
                if (outputStream != null) {
                    try {
                        outputStream.close();
                    } catch (IOException e6) {
                        this.f14503.mo8165().f14444.m8036("Error closing HTTP compressed POST connection output stream. appId", C4794.m8038(this.f14501), e6);
                    }
                }
                if (httpURLConnectionM8533 != null) {
                    httpURLConnectionM8533.disconnect();
                }
                C4771 c4771Mo816322 = this.f14503.mo8163();
                RunnableC4893 runnableC489322 = new RunnableC4893(this.f14501, this.f14500, i, null, null, map, null);
                c4771Mo816322.m8482();
                C0567.m1910(runnableC489322);
                c4771Mo816322.m8005(new C4894<>(c4771Mo816322, runnableC489322, "Task exception on worker thread"));
                throw th;
            }
        } catch (IOException e7) {
            e = e7;
            map2 = null;
            iOException = e;
            i2 = 0;
            if (outputStream != null) {
            }
            if (httpURLConnectionM8533 != null) {
            }
            C4771 c4771Mo816342 = this.f14503.mo8163();
            RunnableC4893 runnableC489342 = new RunnableC4893(this.f14501, this.f14500, i2, iOException, null, map2, null);
            c4771Mo816342.m8482();
            C0567.m1910(runnableC489342);
            c4771Mo816342.m8005(new C4894<>(c4771Mo816342, runnableC489342, "Task exception on worker thread"));
        } catch (Throwable th6) {
            th = th6;
            map = null;
            th = th;
            i = 0;
            if (outputStream != null) {
            }
            if (httpURLConnectionM8533 != null) {
            }
            C4771 c4771Mo8163222 = this.f14503.mo8163();
            RunnableC4893 runnableC4893222 = new RunnableC4893(this.f14501, this.f14500, i, null, null, map, null);
            c4771Mo8163222.m8482();
            C0567.m1910(runnableC4893222);
            c4771Mo8163222.m8005(new C4894<>(c4771Mo8163222, runnableC4893222, "Task exception on worker thread"));
            throw th;
        }
    }
}
