package com.ironsource;

import android.net.Uri;
import android.util.Pair;
import com.google.common.net.HttpHeaders;
import com.mbridge.msdk.playercommon.exoplayer2.DefaultLoadControl;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.ProtocolException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
/* loaded from: classes4.dex */
public class sf {

    /* renamed from: a  reason: collision with root package name */
    private static final String f3062a = "POST";
    private static final String b = "GET";
    private static final String c = "ISHttpService";

    /* loaded from: classes4.dex */
    public static class a {
        private static final int h = 15000;
        private static final int i = 15000;
        private static final String j = "UTF-8";

        /* renamed from: a  reason: collision with root package name */
        final String f3063a;
        final String b;
        final String c;
        final int d;
        final int e;
        final String f;
        ArrayList<Pair<String, String>> g;

        /* JADX INFO: Access modifiers changed from: package-private */
        /* renamed from: com.ironsource.sf$a$a  reason: collision with other inner class name */
        /* loaded from: classes4.dex */
        public static class C0267a {
            String b;
            String d;

            /* renamed from: a  reason: collision with root package name */
            List<Pair<String, String>> f3064a = new ArrayList();
            String c = "POST";
            int e = DefaultLoadControl.DEFAULT_MIN_BUFFER_MS;
            int f = DefaultLoadControl.DEFAULT_MIN_BUFFER_MS;
            String g = "UTF-8";

            C0267a() {
            }

            C0267a a(int i) {
                this.e = i;
                return this;
            }

            C0267a a(Pair<String, String> pair) {
                this.f3064a.add(pair);
                return this;
            }

            C0267a a(String str) {
                this.d = str;
                return this;
            }

            C0267a a(List<Pair<String, String>> list) {
                this.f3064a.addAll(list);
                return this;
            }

            a a() {
                return new a(this);
            }

            C0267a b(int i) {
                this.f = i;
                return this;
            }

            C0267a b(String str) {
                this.g = str;
                return this;
            }

            C0267a c(String str) {
                this.b = str;
                return this;
            }

            C0267a d(String str) {
                this.c = str;
                return this;
            }
        }

        public a(C0267a c0267a) {
            this.f3063a = c0267a.b;
            this.b = c0267a.c;
            this.c = c0267a.d;
            this.g = new ArrayList<>(c0267a.f3064a);
            this.d = c0267a.e;
            this.e = c0267a.f;
            this.f = c0267a.g;
        }

        boolean a() {
            return "POST".equals(this.b);
        }
    }

    public static ap a(String str, String str2, List<Pair<String, String>> list) throws Exception {
        Uri build = Uri.parse(str).buildUpon().encodedQuery(str2).build();
        a.C0267a c0267a = new a.C0267a();
        c0267a.c(build.toString()).a(str2).d("GET").a(list);
        return b(c0267a.a());
    }

    private static HttpURLConnection a(a aVar) throws IOException {
        HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(aVar.f3063a).openConnection();
        httpURLConnection.setConnectTimeout(aVar.d);
        httpURLConnection.setReadTimeout(aVar.e);
        httpURLConnection.setRequestMethod(aVar.b);
        return httpURLConnection;
    }

    private static void a(HttpURLConnection httpURLConnection, a aVar) throws Exception {
        if (aVar.a()) {
            byte[] bytes = aVar.c.getBytes(aVar.f);
            httpURLConnection.setRequestProperty(HttpHeaders.CONTENT_LENGTH, Integer.toString(bytes.length));
            a(httpURLConnection, bytes);
        }
    }

    private static void a(HttpURLConnection httpURLConnection, List<Pair<String, String>> list) throws ProtocolException {
        for (Pair<String, String> pair : list) {
            httpURLConnection.setRequestProperty((String) pair.first, (String) pair.second);
        }
    }

    private static void a(HttpURLConnection httpURLConnection, byte[] bArr) throws Exception {
        httpURLConnection.setDoOutput(true);
        DataOutputStream dataOutputStream = new DataOutputStream(httpURLConnection.getOutputStream());
        try {
            dataOutputStream.write(bArr);
            dataOutputStream.flush();
        } finally {
            dataOutputStream.close();
        }
    }

    private static boolean a(String str, String str2) {
        return (str == null || str.isEmpty() || str2 == null || str2.isEmpty()) ? false : true;
    }

    /* JADX WARN: Code restructure failed: missing block: B:31:0x0068, code lost:
        r6 = r3.getResponseCode();
        r2.f2200a = r6;
     */
    /* JADX WARN: Code restructure failed: missing block: B:32:0x0070, code lost:
        if (r6 < 400) goto L37;
     */
    /* JADX WARN: Code restructure failed: missing block: B:33:0x0072, code lost:
        android.util.Log.d(com.ironsource.sf.c, "Failed post to " + r9.f3063a + " StatusCode: " + r2.f2200a);
     */
    /* JADX WARN: Code restructure failed: missing block: B:34:0x0090, code lost:
        if (r4 == null) goto L36;
     */
    /* JADX WARN: Code restructure failed: missing block: B:35:0x0092, code lost:
        r8 = r4;
        r4 = r3;
        r3 = r8;
     */
    /* JADX WARN: Code restructure failed: missing block: B:36:0x0095, code lost:
        r3.close();
     */
    /* JADX WARN: Code restructure failed: missing block: B:37:0x0099, code lost:
        r4 = r3;
     */
    /* JADX WARN: Code restructure failed: missing block: B:38:0x009a, code lost:
        r4.disconnect();
     */
    /* JADX WARN: Code restructure failed: missing block: B:39:0x009d, code lost:
        return r2;
     */
    /* JADX WARN: Code restructure failed: missing block: B:9:0x0032, code lost:
        if (r3 != null) goto L15;
     */
    /* JADX WARN: Not initialized variable reg: 4, insn: 0x00a0: MOVE  (r8 I:??[OBJECT, ARRAY]) = (r4 I:??[OBJECT, ARRAY]), block:B:42:0x00a0 */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public static com.ironsource.ap b(com.ironsource.sf.a r9) throws java.lang.Exception {
        /*
            Method dump skipped, instructions count: 221
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ironsource.sf.b(com.ironsource.sf$a):com.ironsource.ap");
    }

    public static ap b(String str, String str2, List<Pair<String, String>> list) throws Exception {
        a.C0267a c0267a = new a.C0267a();
        c0267a.c(str).a(str2).d("POST").a(list);
        return b(c0267a.a());
    }
}
