package o; import com.android.volley.AuthFailureError; import com.google.common.net.HttpHeaders; import io.grpc.internal.GrpcUtil; import java.io.DataOutputStream; import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import javax.net.ssl.SSLSocketFactory; /* renamed from: o.aCc, reason: case insensitive filesystem */ /* loaded from: classes.dex */ public final class C1376aCc extends WBD { private final LWm b; private final SSLSocketFactory e; /* renamed from: o.aCc$LWm */ /* loaded from: classes.dex */ public interface LWm { } public C1376aCc() { this((byte) 0); } private C1376aCc(byte b) { this((char) 0); } private C1376aCc(char c) { this.b = null; this.e = null; } @Override // o.WBD public final noY d(HJP hjp, Map map) throws IOException, AuthFailureError { String url = hjp.getUrl(); HashMap hashMap = new HashMap(); hashMap.putAll(map); hashMap.putAll(hjp.getHeaders()); URL url2 = new URL(url); HttpURLConnection httpURLConnection = (HttpURLConnection) url2.openConnection(); httpURLConnection.setInstanceFollowRedirects(HttpURLConnection.getFollowRedirects()); int timeoutMs = hjp.getTimeoutMs(); httpURLConnection.setConnectTimeout(timeoutMs); httpURLConnection.setReadTimeout(timeoutMs); boolean z = false; httpURLConnection.setUseCaches(false); httpURLConnection.setDoInput(true); "https".equals(url2.getProtocol()); try { for (String str : hashMap.keySet()) { httpURLConnection.setRequestProperty(str, (String) hashMap.get(str)); } switch (hjp.getMethod()) { case -1: byte[] postBody = hjp.getPostBody(); if (postBody != null) { httpURLConnection.setRequestMethod(GrpcUtil.HTTP_METHOD); c(httpURLConnection, hjp, postBody); break; } break; case 0: httpURLConnection.setRequestMethod("GET"); break; case 1: httpURLConnection.setRequestMethod(GrpcUtil.HTTP_METHOD); byte[] body = hjp.getBody(); if (body != null) { c(httpURLConnection, hjp, body); break; } break; case 2: httpURLConnection.setRequestMethod("PUT"); byte[] body2 = hjp.getBody(); if (body2 != null) { c(httpURLConnection, hjp, body2); break; } break; case 3: httpURLConnection.setRequestMethod("DELETE"); break; case 4: httpURLConnection.setRequestMethod("HEAD"); break; case 5: httpURLConnection.setRequestMethod("OPTIONS"); break; case 6: httpURLConnection.setRequestMethod("TRACE"); break; case 7: httpURLConnection.setRequestMethod("PATCH"); byte[] body3 = hjp.getBody(); if (body3 != null) { c(httpURLConnection, hjp, body3); break; } break; default: throw new IllegalStateException("Unknown method type."); } int responseCode = httpURLConnection.getResponseCode(); if (responseCode == -1) { throw new IOException("Could not retrieve response code from HttpUrlConnection."); } if (hjp.getMethod() == 4 || ((100 <= responseCode && responseCode < 200) || responseCode == 204 || responseCode == 304)) { noY noy = new noY(responseCode, c(httpURLConnection.getHeaderFields())); httpURLConnection.disconnect(); return noy; } try { return new noY(responseCode, c(httpURLConnection.getHeaderFields()), httpURLConnection.getContentLength(), new RVV(httpURLConnection)); } catch (Throwable th) { th = th; z = true; if (!z) { httpURLConnection.disconnect(); } throw th; } } catch (Throwable th2) { th = th2; } } private static List c(Map> map) { ArrayList arrayList = new ArrayList(map.size()); for (Map.Entry> entry : map.entrySet()) { if (entry.getKey() != null) { Iterator it = entry.getValue().iterator(); while (it.hasNext()) { arrayList.add(new ucE(entry.getKey(), it.next())); } } } return arrayList; } /* renamed from: o.aCc$RVV */ /* loaded from: classes.dex */ static class RVV extends FilterInputStream { private final HttpURLConnection b; @Override // java.io.FilterInputStream, java.io.InputStream, java.io.Closeable, java.lang.AutoCloseable public final void close() throws IOException { super.close(); this.b.disconnect(); } RVV(HttpURLConnection httpURLConnection) { super(C1376aCc.d(httpURLConnection)); this.b = httpURLConnection; } } static InputStream d(HttpURLConnection httpURLConnection) { try { return httpURLConnection.getInputStream(); } catch (IOException unused) { return httpURLConnection.getErrorStream(); } } private static void c(HttpURLConnection httpURLConnection, HJP hjp, byte[] bArr) throws IOException { httpURLConnection.setDoOutput(true); if (!httpURLConnection.getRequestProperties().containsKey(HttpHeaders.CONTENT_TYPE)) { httpURLConnection.setRequestProperty(HttpHeaders.CONTENT_TYPE, hjp.getBodyContentType()); } int length = bArr.length; DataOutputStream dataOutputStream = new DataOutputStream(httpURLConnection.getOutputStream()); dataOutputStream.write(bArr); dataOutputStream.close(); } }