789娱乐城.apk(点击下载) / b.java


package com.sh.sdk.shareinstall.business.a.a.a;

import android.text.TextUtils;
import com.facebook.stetho.common.Utf8Charset;
import com.facebook.stetho.server.http.HttpHeaders;
import com.sh.sdk.shareinstall.business.c.n;
import java.io.BufferedWriter;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import java.util.UUID;
import java.util.zip.GZIPOutputStream;

/* compiled from: RealRequest */
class b {

    /* renamed from: a  reason: collision with root package name */
    private static final String f2839a = UUID.randomUUID().toString();

    b() {
    }

    /* access modifiers changed from: package-private */
    public c a(String str, Map<String, String> map) {
        Exception e;
        HttpURLConnection httpURLConnection;
        try {
            httpURLConnection = a(str, "GET");
            try {
                httpURLConnection.setDoInput(true);
                if (map != null) {
                    a(httpURLConnection, map);
                }
                httpURLConnection.connect();
                return a(httpURLConnection);
            } catch (Exception e2) {
                e = e2;
                return a(httpURLConnection, e);
            }
        } catch (Exception e3) {
            e = e3;
            httpURLConnection = null;
            return a(httpURLConnection, e);
        }
    }

    /* access modifiers changed from: package-private */
    public c a(String str, String str2, String str3, Map<String, String> map) {
        Exception e;
        HttpURLConnection httpURLConnection;
        try {
            httpURLConnection = a(str, "POST");
            try {
                httpURLConnection.setDoOutput(true);
                httpURLConnection.setDoInput(true);
                httpURLConnection.setUseCaches(false);
                if (!TextUtils.isEmpty(str3)) {
                    httpURLConnection.setRequestProperty(HttpHeaders.CONTENT_TYPE, str3);
                }
                if (!TextUtils.isEmpty(str) && str.contains("https://statlog.shareinstall.com.cn/shareinstall_logs_act/activity")) {
                    httpURLConnection.setRequestProperty("Accept-Encoding", "gzip");
                    httpURLConnection.setRequestProperty("Content-Encoding", "compress,gzip");
                }
                if (map != null) {
                    a(httpURLConnection, map);
                }
                httpURLConnection.connect();
                if (!TextUtils.isEmpty(str2)) {
                    if (TextUtils.isEmpty(str) || !str.contains("https://statlog.shareinstall.com.cn/shareinstall_logs_act/activity")) {
                        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(httpURLConnection.getOutputStream(), Utf8Charset.NAME));
                        bufferedWriter.write(str2);
                        bufferedWriter.flush();
                        bufferedWriter.close();
                    } else {
                        OutputStream outputStream = httpURLConnection.getOutputStream();
                        GZIPOutputStream gZIPOutputStream = new GZIPOutputStream(outputStream);
                        gZIPOutputStream.write(str2.getBytes(Utf8Charset.NAME));
                        gZIPOutputStream.flush();
                        outputStream.flush();
                        gZIPOutputStream.close();
                        outputStream.close();
                    }
                }
                return a(httpURLConnection);
            } catch (Exception e2) {
                e = e2;
                return a(httpURLConnection, e);
            }
        } catch (Exception e3) {
            e = e3;
            httpURLConnection = null;
            return a(httpURLConnection, e);
        }
    }

    private HttpURLConnection a(String str, String str2) {
        HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
        int i = 15000;
        httpURLConnection.setConnectTimeout("https://config.shareinstall.com.cn/signal/config".equals(str) ? 3000 : 15000);
        if ("https://config.shareinstall.com.cn/signal/config".equals(str)) {
            i = 3000;
        }
        httpURLConnection.setReadTimeout(i);
        httpURLConnection.setRequestMethod(str2);
        return httpURLConnection;
    }

    private void a(HttpURLConnection httpURLConnection, Map<String, String> map) {
        if (map != null) {
            for (String str : map.keySet()) {
                httpURLConnection.setRequestProperty(str, map.get(str));
            }
        }
    }

    private c a(HttpURLConnection httpURLConnection) {
        c cVar = new c();
        cVar.c = httpURLConnection.getResponseCode();
        cVar.d = (long) httpURLConnection.getContentLength();
        try {
            if (400 != cVar.c) {
                if (cVar.c < 500) {
                    cVar.b = httpURLConnection.getErrorStream();
                    cVar.f2840a = httpURLConnection.getInputStream();
                    return cVar;
                }
            }
            cVar.b = httpURLConnection.getErrorStream();
            return cVar;
        } catch (Exception unused) {
            cVar.b = httpURLConnection.getErrorStream();
            return cVar;
        }
    }

    private c a(HttpURLConnection httpURLConnection, Exception exc) {
        if (httpURLConnection != null) {
            httpURLConnection.disconnect();
        }
        n.a(exc.getMessage());
        c cVar = new c();
        cVar.e = exc;
        return cVar;
    }
}