224 lines
7.3 KiB
Java
224 lines
7.3 KiB
Java
package o;
|
|
|
|
import android.net.Uri;
|
|
import android.text.TextUtils;
|
|
import android.util.Log;
|
|
import com.bumptech.glide.load.HttpException;
|
|
import com.google.common.net.HttpHeaders;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.MalformedURLException;
|
|
import java.net.URISyntaxException;
|
|
import java.net.URL;
|
|
import java.util.Map;
|
|
import o.InterfaceC12232euN;
|
|
|
|
/* renamed from: o.ajK, reason: case insensitive filesystem */
|
|
/* loaded from: classes.dex */
|
|
public final class C2685ajK implements InterfaceC12232euN<InputStream> {
|
|
private static HBt c = new IeS();
|
|
private volatile boolean a;
|
|
private final HBt b;
|
|
private InputStream d;
|
|
private final IwF e;
|
|
private final int h;
|
|
private HttpURLConnection i;
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: o.ajK$HBt */
|
|
/* loaded from: classes.dex */
|
|
public interface HBt {
|
|
HttpURLConnection e(URL url) throws IOException;
|
|
}
|
|
|
|
public C2685ajK(IwF iwF, int i) {
|
|
this(iwF, i, c);
|
|
}
|
|
|
|
private C2685ajK(IwF iwF, int i, HBt hBt) {
|
|
this.e = iwF;
|
|
this.h = i;
|
|
this.b = hBt;
|
|
}
|
|
|
|
@Override // o.InterfaceC12232euN
|
|
public final void c(EnumC3495ayd enumC3495ayd, InterfaceC12232euN.IeS<? super InputStream> ieS) {
|
|
long e = PYC.e();
|
|
try {
|
|
try {
|
|
IwF iwF = this.e;
|
|
if (iwF.c == null) {
|
|
if (TextUtils.isEmpty(iwF.d)) {
|
|
String str = iwF.a;
|
|
if (TextUtils.isEmpty(str)) {
|
|
URL url = iwF.j;
|
|
if (url != null) {
|
|
URL url2 = url;
|
|
str = url.toString();
|
|
} else {
|
|
throw new NullPointerException("Argument must not be null");
|
|
}
|
|
}
|
|
iwF.d = Uri.encode(str, "@#&=*+-_.,:!?()/~'%;$");
|
|
}
|
|
iwF.c = new URL(iwF.d);
|
|
}
|
|
ieS.a((InterfaceC12232euN.IeS<? super InputStream>) c(iwF.c, 0, null, this.e.b.a()));
|
|
if (!Log.isLoggable("HttpUrlFetcher", 2)) {
|
|
return;
|
|
}
|
|
} catch (IOException e2) {
|
|
ieS.a((Exception) e2);
|
|
if (!Log.isLoggable("HttpUrlFetcher", 2)) {
|
|
return;
|
|
}
|
|
}
|
|
PYC.e(e);
|
|
} catch (Throwable th) {
|
|
if (Log.isLoggable("HttpUrlFetcher", 2)) {
|
|
PYC.e(e);
|
|
}
|
|
throw th;
|
|
}
|
|
}
|
|
|
|
private InputStream c(URL url, int i, URL url2, Map<String, String> map) throws HttpException {
|
|
while (i < 5) {
|
|
if (url2 != null) {
|
|
try {
|
|
if (url.toURI().equals(url2.toURI())) {
|
|
throw new HttpException("In re-direct loop", -1);
|
|
break;
|
|
}
|
|
} catch (URISyntaxException unused) {
|
|
}
|
|
}
|
|
HttpURLConnection c2 = c(url, map);
|
|
this.i = c2;
|
|
try {
|
|
c2.connect();
|
|
this.d = this.i.getInputStream();
|
|
if (this.a) {
|
|
return null;
|
|
}
|
|
int a = a(this.i);
|
|
int i2 = a / 100;
|
|
if (i2 == 2) {
|
|
return b(this.i);
|
|
}
|
|
if (i2 != 3) {
|
|
if (a == -1) {
|
|
throw new HttpException(a);
|
|
}
|
|
try {
|
|
throw new HttpException(this.i.getResponseMessage(), a);
|
|
} catch (IOException e) {
|
|
throw new HttpException("Failed to get a response message", a, e);
|
|
}
|
|
}
|
|
String headerField = this.i.getHeaderField(HttpHeaders.LOCATION);
|
|
if (TextUtils.isEmpty(headerField)) {
|
|
throw new HttpException("Received empty or null redirect url", a);
|
|
}
|
|
try {
|
|
URL url3 = new URL(url, headerField);
|
|
e();
|
|
i++;
|
|
url2 = url;
|
|
url = url3;
|
|
} catch (MalformedURLException e2) {
|
|
throw new HttpException("Bad redirect url: ".concat(String.valueOf(headerField)), a, e2);
|
|
}
|
|
} catch (IOException e3) {
|
|
throw new HttpException("Failed to connect or obtain data", a(this.i), e3);
|
|
}
|
|
}
|
|
throw new HttpException("Too many (> 5) redirects!", -1);
|
|
}
|
|
|
|
private static int a(HttpURLConnection httpURLConnection) {
|
|
try {
|
|
return httpURLConnection.getResponseCode();
|
|
} catch (IOException unused) {
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
private HttpURLConnection c(URL url, Map<String, String> map) throws HttpException {
|
|
try {
|
|
HttpURLConnection e = this.b.e(url);
|
|
for (Map.Entry<String, String> entry : map.entrySet()) {
|
|
e.addRequestProperty(entry.getKey(), entry.getValue());
|
|
}
|
|
e.setConnectTimeout(this.h);
|
|
e.setReadTimeout(this.h);
|
|
e.setUseCaches(false);
|
|
e.setDoInput(true);
|
|
e.setInstanceFollowRedirects(false);
|
|
return e;
|
|
} catch (IOException e2) {
|
|
throw new HttpException("URL.openConnection threw", 0, e2);
|
|
}
|
|
}
|
|
|
|
private InputStream b(HttpURLConnection httpURLConnection) throws HttpException {
|
|
try {
|
|
if (TextUtils.isEmpty(httpURLConnection.getContentEncoding())) {
|
|
this.d = new FTt(httpURLConnection.getInputStream(), httpURLConnection.getContentLength());
|
|
} else {
|
|
if (Log.isLoggable("HttpUrlFetcher", 3)) {
|
|
httpURLConnection.getContentEncoding();
|
|
}
|
|
this.d = httpURLConnection.getInputStream();
|
|
}
|
|
return this.d;
|
|
} catch (IOException e) {
|
|
throw new HttpException("Failed to obtain InputStream", a(httpURLConnection), e);
|
|
}
|
|
}
|
|
|
|
@Override // o.InterfaceC12232euN
|
|
public final void e() {
|
|
InputStream inputStream = this.d;
|
|
if (inputStream != null) {
|
|
try {
|
|
inputStream.close();
|
|
} catch (IOException unused) {
|
|
}
|
|
}
|
|
HttpURLConnection httpURLConnection = this.i;
|
|
if (httpURLConnection != null) {
|
|
httpURLConnection.disconnect();
|
|
}
|
|
this.i = null;
|
|
}
|
|
|
|
@Override // o.InterfaceC12232euN
|
|
public final Class<InputStream> c() {
|
|
return InputStream.class;
|
|
}
|
|
|
|
@Override // o.InterfaceC12232euN
|
|
public final pNW d() {
|
|
return pNW.REMOTE;
|
|
}
|
|
|
|
/* renamed from: o.ajK$IeS */
|
|
/* loaded from: classes.dex */
|
|
static class IeS implements HBt {
|
|
IeS() {
|
|
}
|
|
|
|
@Override // o.C2685ajK.HBt
|
|
public final HttpURLConnection e(URL url) throws IOException {
|
|
return (HttpURLConnection) url.openConnection();
|
|
}
|
|
}
|
|
|
|
@Override // o.InterfaceC12232euN
|
|
public final void a() {
|
|
this.a = true;
|
|
}
|
|
}
|