翰林优商.apk(点击下载) / c.java


package com.bytedance.sdk.openadsdk.api.plugin.a;

import com.baidu.mobads.sdk.internal.ae;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.util.Arrays;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;

/* compiled from: NetApi */
public class c {

    /* access modifiers changed from: private */
    /* compiled from: NetApi */
    public static final class a {
        private static final c a = new c();
    }

    private c() {
    }

    public static c a() {
        return a.a;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:22:0x007a, code lost:
        if (r5 != null) goto L_0x007c;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:24:?, code lost:
        r5.disconnect();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:31:0x0089, code lost:
        if (r5 != null) goto L_0x007c;
     */
    /* JADX WARNING: Removed duplicated region for block: B:37:0x0091 A[SYNTHETIC, Splitter:B:37:0x0091] */
    public String a(boolean z, String str, byte[] bArr) {
        Throwable th;
        HttpsURLConnection httpsURLConnection;
        Exception e;
        HttpsURLConnection httpsURLConnection2 = null;
        try {
            URL url = new URL(str);
            HttpsURLConnection.setDefaultSSLSocketFactory(a(b()));
            httpsURLConnection = (HttpsURLConnection) url.openConnection();
            try {
                httpsURLConnection.setConnectTimeout(5000);
                httpsURLConnection.setHostnameVerifier(a.a);
                if (!z || bArr == null || bArr.length == 0) {
                    httpsURLConnection.setRequestMethod("GET");
                } else {
                    httpsURLConnection.setDoOutput(true);
                    httpsURLConnection.setFixedLengthStreamingMode(bArr.length);
                    BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(httpsURLConnection.getOutputStream());
                    bufferedOutputStream.write(bArr);
                    bufferedOutputStream.flush();
                    bufferedOutputStream.close();
                    httpsURLConnection.setRequestMethod(ae.b);
                }
                int responseCode = httpsURLConnection.getResponseCode();
                if (responseCode >= 200 && responseCode < 300) {
                    String str2 = new String(a(httpsURLConnection.getInputStream(), 1024), a(httpsURLConnection.getHeaderField("Content-Type"), "utf-8"));
                    if (httpsURLConnection != null) {
                        try {
                            httpsURLConnection.disconnect();
                        } catch (Exception unused) {
                        }
                    }
                    return str2;
                }
            } catch (Exception e2) {
                e = e2;
                try {
                    e.printStackTrace();
                } catch (Throwable th2) {
                    th = th2;
                    httpsURLConnection2 = httpsURLConnection;
                    if (httpsURLConnection2 != null) {
                    }
                    throw th;
                }
            }
        } catch (Exception e3) {
            e = e3;
            httpsURLConnection = null;
            e.printStackTrace();
        } catch (Throwable th3) {
            th = th3;
            if (httpsURLConnection2 != null) {
                try {
                    httpsURLConnection2.disconnect();
                } catch (Exception unused2) {
                }
            }
            throw th;
        }
        return null;
    }

    private static byte[] a(InputStream inputStream, int i) throws IOException {
        if (inputStream == null) {
            return null;
        }
        if (i < 1) {
            i = 1;
        }
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        byte[] bArr = new byte[i];
        while (true) {
            int read = inputStream.read(bArr);
            if (read != -1) {
                byteArrayOutputStream.write(bArr, 0, read);
            } else {
                byteArrayOutputStream.close();
                inputStream.close();
                return byteArrayOutputStream.toByteArray();
            }
        }
    }

    private static String a(String str, String str2) {
        if (str != null) {
            String[] split = str.split(";", 0);
            for (int i = 1; i < split.length; i++) {
                String[] split2 = split[i].trim().split("=", 0);
                if (split2.length == 2 && split2[0].equals("charset")) {
                    return split2[1];
                }
            }
        }
        return str2;
    }

    private SSLSocketFactory a(X509TrustManager x509TrustManager) throws IOException {
        try {
            SSLContext instance = SSLContext.getInstance("TLS");
            instance.init(null, new TrustManager[]{x509TrustManager}, null);
            return instance.getSocketFactory();
        } catch (GeneralSecurityException e) {
            throw new IOException("No System TLS", e);
        }
    }

    private X509TrustManager b() throws IOException {
        try {
            TrustManagerFactory instance = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
            KeyStore keyStore = null;
            instance.init((KeyStore) null);
            TrustManager[] trustManagers = instance.getTrustManagers();
            if (trustManagers.length == 1 && (trustManagers[0] instanceof X509TrustManager)) {
                return (X509TrustManager) trustManagers[0];
            }
            throw new IllegalStateException("Unexpected default trust managers:" + Arrays.toString(trustManagers));
        } catch (GeneralSecurityException e) {
            throw new IOException("No System TLS", e);
        }
    }
}