181 lines
6.3 KiB
Java
181 lines
6.3 KiB
Java
package com.google.zxing.client.android;
|
|
|
|
import com.ijm.dataencryption.de.DataDecryptTool;
|
|
import com.ubt.jimu.diy.model.DiyPreviewStep;
|
|
import java.io.IOException;
|
|
import java.io.InputStreamReader;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.URI;
|
|
import java.net.URISyntaxException;
|
|
import java.net.URL;
|
|
import java.net.URLConnection;
|
|
import java.util.Arrays;
|
|
import java.util.Collection;
|
|
import java.util.HashSet;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class HttpHelper {
|
|
private static final Collection<String> a = new HashSet(Arrays.asList("amzn.to", "bit.ly", "bitly.com", "fb.me", "goo.gl", "is.gd", "j.mp", "lnkd.in", "ow.ly", "R.BEETAGG.COM", "r.beetagg.com", "SCN.BY", "su.pr", "t.co", "tinyurl.com", "tr.im"));
|
|
|
|
/* renamed from: com.google.zxing.client.android.HttpHelper$1, reason: invalid class name */
|
|
static /* synthetic */ class AnonymousClass1 {
|
|
static final /* synthetic */ int[] a = new int[ContentType.values().length];
|
|
|
|
static {
|
|
try {
|
|
a[ContentType.HTML.ordinal()] = 1;
|
|
} catch (NoSuchFieldError unused) {
|
|
}
|
|
try {
|
|
a[ContentType.JSON.ordinal()] = 2;
|
|
} catch (NoSuchFieldError unused2) {
|
|
}
|
|
try {
|
|
a[ContentType.XML.ordinal()] = 3;
|
|
} catch (NoSuchFieldError unused3) {
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum ContentType {
|
|
HTML,
|
|
JSON,
|
|
XML,
|
|
TEXT
|
|
}
|
|
|
|
public static CharSequence a(String str, ContentType contentType) throws IOException {
|
|
return a(str, contentType, Integer.MAX_VALUE);
|
|
}
|
|
|
|
public static CharSequence a(String str, ContentType contentType, int i) throws IOException {
|
|
int i2 = AnonymousClass1.a[contentType.ordinal()];
|
|
return a(str, i2 != 1 ? i2 != 2 ? i2 != 3 ? "text/*,*/*" : "application/xml,text/*,*/*" : "application/json,text/*,*/*" : "application/xhtml+xml,text/html,text/*,*/*", i);
|
|
}
|
|
|
|
private static CharSequence a(String str, String str2, int i) throws IOException {
|
|
int i2 = 0;
|
|
while (i2 < 5) {
|
|
HttpURLConnection a2 = a(new URL(str));
|
|
a2.setInstanceFollowRedirects(true);
|
|
a2.setRequestProperty("Accept", str2);
|
|
a2.setRequestProperty("Accept-Charset", "utf-8,*");
|
|
a2.setRequestProperty("User-Agent", "ZXing (Android)");
|
|
try {
|
|
int a3 = a(a2);
|
|
if (a3 == 200) {
|
|
return a(a2, i);
|
|
}
|
|
if (a3 == 302) {
|
|
String headerField = a2.getHeaderField("Location");
|
|
if (headerField != null) {
|
|
i2++;
|
|
a2.disconnect();
|
|
str = headerField;
|
|
} else {
|
|
throw new IOException("No Location");
|
|
}
|
|
} else {
|
|
throw new IOException("Bad HTTP response: " + a3);
|
|
}
|
|
} finally {
|
|
a2.disconnect();
|
|
}
|
|
}
|
|
throw new IOException("Too many redirects");
|
|
}
|
|
|
|
private static String a(URLConnection uRLConnection) {
|
|
int indexOf;
|
|
String headerField = uRLConnection.getHeaderField("Content-Type");
|
|
return (headerField == null || (indexOf = headerField.indexOf("charset=")) < 0) ? "UTF-8" : headerField.substring(indexOf + 8);
|
|
}
|
|
|
|
private static CharSequence a(URLConnection uRLConnection, int i) throws IOException {
|
|
int read;
|
|
String a2 = a(uRLConnection);
|
|
StringBuilder sb = new StringBuilder();
|
|
InputStreamReader inputStreamReader = new InputStreamReader(uRLConnection.getInputStream(), a2);
|
|
try {
|
|
char[] cArr = new char[DataDecryptTool.DECRYPT_SP_FILE];
|
|
while (sb.length() < i && (read = inputStreamReader.read(cArr)) > 0) {
|
|
sb.append(cArr, 0, read);
|
|
}
|
|
inputStreamReader.close();
|
|
inputStreamReader.close();
|
|
return sb;
|
|
} catch (Throwable th) {
|
|
try {
|
|
throw th;
|
|
} catch (Throwable th2) {
|
|
try {
|
|
inputStreamReader.close();
|
|
} catch (Throwable th3) {
|
|
th.addSuppressed(th3);
|
|
}
|
|
throw th2;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static URI a(URI uri) throws IOException {
|
|
if (!a.contains(uri.getHost())) {
|
|
return uri;
|
|
}
|
|
HttpURLConnection a2 = a(uri.toURL());
|
|
a2.setInstanceFollowRedirects(false);
|
|
a2.setDoInput(false);
|
|
a2.setRequestMethod("HEAD");
|
|
a2.setRequestProperty("User-Agent", "ZXing (Android)");
|
|
try {
|
|
int a3 = a(a2);
|
|
if (a3 != 307) {
|
|
switch (a3) {
|
|
case 300:
|
|
case DiyPreviewStep.TYPE_PROGRAM /* 301 */:
|
|
case 302:
|
|
case 303:
|
|
break;
|
|
default:
|
|
return uri;
|
|
}
|
|
}
|
|
String headerField = a2.getHeaderField("Location");
|
|
if (headerField != null) {
|
|
try {
|
|
return new URI(headerField);
|
|
} catch (URISyntaxException unused) {
|
|
}
|
|
}
|
|
return uri;
|
|
} finally {
|
|
a2.disconnect();
|
|
}
|
|
}
|
|
|
|
private static HttpURLConnection a(URL url) throws IOException {
|
|
try {
|
|
URLConnection openConnection = url.openConnection();
|
|
if (openConnection instanceof HttpURLConnection) {
|
|
return (HttpURLConnection) openConnection;
|
|
}
|
|
throw new IOException("Expected HttpURLConnection but got " + openConnection.getClass());
|
|
} catch (NullPointerException e) {
|
|
throw new IOException(e);
|
|
}
|
|
}
|
|
|
|
private static int a(HttpURLConnection httpURLConnection) throws IOException {
|
|
try {
|
|
httpURLConnection.connect();
|
|
try {
|
|
return httpURLConnection.getResponseCode();
|
|
} catch (IllegalArgumentException | NullPointerException | StringIndexOutOfBoundsException e) {
|
|
throw new IOException(e);
|
|
}
|
|
} catch (RuntimeException e2) {
|
|
throw new IOException(e2);
|
|
}
|
|
}
|
|
}
|