package com.huawei.updatesdk.a.a.b; import android.content.Context; import com.huawei.secure.android.common.ssl.SecureSSLSocketFactory; import com.huawei.updatesdk.a.a.d.d; import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.Closeable; import java.io.DataOutputStream; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; import java.util.zip.GZIPOutputStream; import javax.net.ssl.HttpsURLConnection; import org.apache.http.conn.ssl.SSLSocketFactory; public class b { private HttpURLConnection a = null; public static class a { private String a; private int b; public int a() { return this.b; } public String b() { return this.a; } } public static HttpsURLConnection a(String str, Context context) { HttpsURLConnection httpsURLConnection = (HttpsURLConnection) new URL(str).openConnection(); httpsURLConnection.setSSLSocketFactory(SecureSSLSocketFactory.getInstance(context)); httpsURLConnection.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); return httpsURLConnection; } /* JADX WARNING: Removed duplicated region for block: B:21:0x0032 */ /* JADX WARNING: Removed duplicated region for block: B:27:0x0041 A[SYNTHETIC, Splitter:B:27:0x0041] */ private byte[] a(byte[] bArr) { Throwable th; ByteArrayOutputStream byteArrayOutputStream; IOException e; DataOutputStream dataOutputStream = null; try { byteArrayOutputStream = new ByteArrayOutputStream(); try { DataOutputStream dataOutputStream2 = new DataOutputStream(new GZIPOutputStream(byteArrayOutputStream, bArr.length)); try { dataOutputStream2.write(bArr, 0, bArr.length); dataOutputStream2.flush(); try { dataOutputStream2.close(); } catch (IOException e2) { com.huawei.updatesdk.a.a.c.a.a.a.a("HttpsUtil", "gzip error!", e2); } } catch (IOException e3) { e = e3; dataOutputStream = dataOutputStream2; try { com.huawei.updatesdk.a.a.c.a.a.a.a("HttpsUtil", "gzip error!", e); if (dataOutputStream != null) { } return byteArrayOutputStream.toByteArray(); } catch (Throwable th2) { th = th2; if (dataOutputStream != null) { try { dataOutputStream.close(); } catch (IOException e4) { com.huawei.updatesdk.a.a.c.a.a.a.a("HttpsUtil", "gzip error!", e4); } } throw th; } } catch (Throwable th3) { th = th3; dataOutputStream = dataOutputStream2; if (dataOutputStream != null) { } throw th; } } catch (IOException e5) { e = e5; com.huawei.updatesdk.a.a.c.a.a.a.a("HttpsUtil", "gzip error!", e); if (dataOutputStream != null) { } return byteArrayOutputStream.toByteArray(); } } catch (IOException e6) { e = e6; byteArrayOutputStream = null; com.huawei.updatesdk.a.a.c.a.a.a.a("HttpsUtil", "gzip error!", e); if (dataOutputStream != null) { dataOutputStream.close(); } return byteArrayOutputStream.toByteArray(); } return byteArrayOutputStream.toByteArray(); } /* JADX WARNING: Removed duplicated region for block: B:24:0x00cd */ public a a(String str, String str2, String str3, String str4, Context context) { Throwable th; DataOutputStream dataOutputStream; HttpURLConnection httpURLConnection; a aVar = new a(); try { HttpsURLConnection a2 = a(str, context); this.a = a2; a2.setDoInput(true); this.a.setDoOutput(true); this.a.setUseCaches(false); this.a.setConnectTimeout(5000); this.a.setReadTimeout(10000); this.a.setRequestMethod("POST"); this.a.setRequestProperty("Content-Type", "application/x-gzip"); this.a.setRequestProperty("Content-Encoding", "gzip"); this.a.setRequestProperty("Connection", "Keep-Alive"); this.a.setRequestProperty("User-Agent", str4); dataOutputStream = new DataOutputStream(this.a.getOutputStream()); try { dataOutputStream.write(a(str2.getBytes(str3))); dataOutputStream.flush(); int responseCode = this.a.getResponseCode(); aVar.b = responseCode; BufferedInputStream bufferedInputStream = responseCode == 200 ? new BufferedInputStream(this.a.getInputStream()) : new BufferedInputStream(this.a.getErrorStream()); com.huawei.updatesdk.a.a.d.b bVar = new com.huawei.updatesdk.a.a.d.b(); byte[] a3 = a.b().a(); while (true) { int read = bufferedInputStream.read(a3); if (read == -1) { break; } bVar.a(a3, read); } a.b().a(a3); aVar.a = bVar.a(); HttpURLConnection httpURLConnection2 = this.a; if (httpURLConnection2 != null) { httpURLConnection2.disconnect(); } d.a(dataOutputStream); d.a(bufferedInputStream); return aVar; } catch (Throwable th2) { th = th2; httpURLConnection = this.a; if (httpURLConnection != null) { httpURLConnection.disconnect(); } d.a(dataOutputStream); d.a((Closeable) null); throw th; } } catch (Throwable th3) { th = th3; dataOutputStream = null; httpURLConnection = this.a; if (httpURLConnection != null) { } d.a(dataOutputStream); d.a((Closeable) null); throw th; } } public void a() { HttpURLConnection httpURLConnection = this.a; if (httpURLConnection != null) { httpURLConnection.disconnect(); } } }