328 lines
14 KiB
Java
328 lines
14 KiB
Java
package o;
|
|
|
|
import com.google.common.net.HttpHeaders;
|
|
import com.google.firebase.crashlytics.internal.common.AbstractSpiCall;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.lang.reflect.Type;
|
|
import java.net.URLConnection;
|
|
import java.util.Collection;
|
|
import java.util.Collections;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import okhttp3.Call;
|
|
import okhttp3.FormBody;
|
|
import okhttp3.Headers;
|
|
import okhttp3.MediaType;
|
|
import okhttp3.MultipartBody;
|
|
import okhttp3.OkHttpClient;
|
|
import okhttp3.Request;
|
|
import okhttp3.RequestBody;
|
|
import okhttp3.Response;
|
|
import okhttp3.internal.http.HttpMethod;
|
|
import org.threeten.bp.OffsetDateTime;
|
|
|
|
/* renamed from: o.fQg, reason: case insensitive filesystem */
|
|
/* loaded from: classes5.dex */
|
|
public final class C13093fQg {
|
|
private Map<String, Object> f;
|
|
public String e = "https://api.beid.io:80";
|
|
private boolean a = false;
|
|
public Map<String, String> d = new HashMap();
|
|
private String c = null;
|
|
public OkHttpClient b = new OkHttpClient();
|
|
private boolean j = true;
|
|
private C13100fQn g = new C13100fQn();
|
|
|
|
public C13093fQg() {
|
|
this.d.put("User-Agent", "Swagger-Codegen/1.0.0/java");
|
|
HashMap hashMap = new HashMap();
|
|
this.f = hashMap;
|
|
this.f = Collections.unmodifiableMap(hashMap);
|
|
}
|
|
|
|
/* JADX WARN: Removed duplicated region for block: B:12:0x0032 */
|
|
/* JADX WARN: Removed duplicated region for block: B:17:0x0033 A[Catch: IOException -> 0x008e, TRY_LEAVE, TryCatch #0 {IOException -> 0x008e, blocks: (B:2:0x0000, B:5:0x000b, B:7:0x0011, B:9:0x0021, B:13:0x0073, B:17:0x0033, B:20:0x003e, B:21:0x0069, B:26:0x004e), top: B:1:0x0000 }] */
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct add '--show-bad-code' argument
|
|
*/
|
|
private java.io.File d(okhttp3.Response r8) throws io.beid.beidk.a.b {
|
|
/*
|
|
r7 = this;
|
|
java.lang.String r0 = "Content-Disposition"
|
|
java.lang.String r0 = r8.header(r0) // Catch: java.io.IOException -> L8e
|
|
r1 = 0
|
|
java.lang.String r2 = ""
|
|
if (r0 == 0) goto L2d
|
|
boolean r3 = r2.equals(r0) // Catch: java.io.IOException -> L8e
|
|
if (r3 != 0) goto L2d
|
|
java.lang.String r3 = "filename=['\"]?([^'\"\\s]+)['\"]?"
|
|
java.util.regex.Pattern r3 = java.util.regex.Pattern.compile(r3) // Catch: java.io.IOException -> L8e
|
|
java.util.regex.Matcher r0 = r3.matcher(r0) // Catch: java.io.IOException -> L8e
|
|
boolean r3 = r0.find() // Catch: java.io.IOException -> L8e
|
|
if (r3 == 0) goto L2d
|
|
r3 = 1
|
|
java.lang.String r0 = r0.group(r3) // Catch: java.io.IOException -> L8e
|
|
java.lang.String r3 = ".*[/\\\\]"
|
|
java.lang.String r0 = r0.replaceAll(r3, r2) // Catch: java.io.IOException -> L8e
|
|
goto L2e
|
|
L2d:
|
|
r0 = r1
|
|
L2e:
|
|
java.lang.String r3 = "download-"
|
|
if (r0 != 0) goto L33
|
|
goto L73
|
|
L33:
|
|
java.lang.String r2 = "."
|
|
int r2 = r0.lastIndexOf(r2) // Catch: java.io.IOException -> L8e
|
|
r4 = -1
|
|
java.lang.String r5 = "-"
|
|
if (r2 != r4) goto L4e
|
|
java.lang.StringBuilder r2 = new java.lang.StringBuilder // Catch: java.io.IOException -> L8e
|
|
r2.<init>() // Catch: java.io.IOException -> L8e
|
|
r2.append(r0) // Catch: java.io.IOException -> L8e
|
|
r2.append(r5) // Catch: java.io.IOException -> L8e
|
|
java.lang.String r0 = r2.toString() // Catch: java.io.IOException -> L8e
|
|
goto L69
|
|
L4e:
|
|
java.lang.StringBuilder r1 = new java.lang.StringBuilder // Catch: java.io.IOException -> L8e
|
|
r1.<init>() // Catch: java.io.IOException -> L8e
|
|
r4 = 0
|
|
java.lang.String r4 = r0.substring(r4, r2) // Catch: java.io.IOException -> L8e
|
|
r1.append(r4) // Catch: java.io.IOException -> L8e
|
|
r1.append(r5) // Catch: java.io.IOException -> L8e
|
|
java.lang.String r1 = r1.toString() // Catch: java.io.IOException -> L8e
|
|
java.lang.String r0 = r0.substring(r2) // Catch: java.io.IOException -> L8e
|
|
r6 = r1
|
|
r1 = r0
|
|
r0 = r6
|
|
L69:
|
|
int r2 = r0.length() // Catch: java.io.IOException -> L8e
|
|
r4 = 3
|
|
if (r2 >= r4) goto L71
|
|
goto L72
|
|
L71:
|
|
r3 = r0
|
|
L72:
|
|
r2 = r1
|
|
L73:
|
|
java.io.File r0 = java.io.File.createTempFile(r3, r2) // Catch: java.io.IOException -> L8e
|
|
o.giw r1 = o.C15160gio.e(r0) // Catch: java.io.IOException -> L8e
|
|
o.gic r1 = o.C15160gio.c(r1) // Catch: java.io.IOException -> L8e
|
|
okhttp3.ResponseBody r8 = r8.body() // Catch: java.io.IOException -> L8e
|
|
o.gid r8 = r8.source() // Catch: java.io.IOException -> L8e
|
|
r1.c(r8) // Catch: java.io.IOException -> L8e
|
|
r1.close() // Catch: java.io.IOException -> L8e
|
|
return r0
|
|
L8e:
|
|
r8 = move-exception
|
|
io.beid.beidk.a.b r0 = new io.beid.beidk.a.b
|
|
r0.<init>(r8)
|
|
throw r0
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: o.C13093fQg.d(okhttp3.Response):java.io.File");
|
|
}
|
|
|
|
private String a(Object obj) {
|
|
if (obj == null) {
|
|
return "";
|
|
}
|
|
if ((obj instanceof Date) || (obj instanceof OffsetDateTime) || (obj instanceof C15520gsp)) {
|
|
String json = this.g.b.toJson(obj);
|
|
return json.substring(1, json.length() - 1);
|
|
}
|
|
if (!(obj instanceof Collection)) {
|
|
return String.valueOf(obj);
|
|
}
|
|
StringBuilder sb = new StringBuilder();
|
|
for (Object obj2 : (Collection) obj) {
|
|
if (sb.length() > 0) {
|
|
sb.append(",");
|
|
}
|
|
sb.append(String.valueOf(obj2));
|
|
}
|
|
return sb.toString();
|
|
}
|
|
|
|
public final Call b(String str, String str2, List<C13102fQp> list, List<C13102fQp> list2, Object obj, Map<String, String> map, Map<String, Object> map2, String[] strArr) throws io.beid.beidk.a.b {
|
|
int length = strArr.length;
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append(this.e);
|
|
sb.append(str);
|
|
if (!list.isEmpty()) {
|
|
str.contains("?");
|
|
Iterator<C13102fQp> it = list.iterator();
|
|
while (it.hasNext()) {
|
|
String str3 = it.next().a;
|
|
}
|
|
}
|
|
if (!list2.isEmpty()) {
|
|
sb.toString().contains("?");
|
|
Iterator<C13102fQp> it2 = list2.iterator();
|
|
while (it2.hasNext()) {
|
|
String str4 = it2.next().a;
|
|
}
|
|
}
|
|
Request.Builder url = new Request.Builder().url(sb.toString());
|
|
for (Map.Entry<String, String> entry : map.entrySet()) {
|
|
url.header(entry.getKey(), a(entry.getValue()));
|
|
}
|
|
for (Map.Entry<String, String> entry2 : this.d.entrySet()) {
|
|
if (!map.containsKey(entry2.getKey())) {
|
|
url.header(entry2.getKey(), a(entry2.getValue()));
|
|
}
|
|
}
|
|
String str5 = map.get(HttpHeaders.CONTENT_TYPE);
|
|
if (str5 == null) {
|
|
str5 = AbstractSpiCall.ACCEPT_JSON_VALUE;
|
|
}
|
|
RequestBody requestBody = null;
|
|
requestBody = null;
|
|
if (HttpMethod.permitsRequestBody(str2)) {
|
|
if ("application/x-www-form-urlencoded".equals(str5)) {
|
|
FormBody.Builder builder = new FormBody.Builder();
|
|
for (Map.Entry<String, Object> entry3 : map2.entrySet()) {
|
|
builder.add(entry3.getKey(), a(entry3.getValue()));
|
|
}
|
|
requestBody = builder.build();
|
|
} else if ("multipart/form-data".equals(str5)) {
|
|
MultipartBody.Builder builder2 = new MultipartBody.Builder();
|
|
builder2.setType(MultipartBody.FORM);
|
|
for (Map.Entry<String, Object> entry4 : map2.entrySet()) {
|
|
if (entry4.getValue() instanceof File) {
|
|
File file = (File) entry4.getValue();
|
|
StringBuilder sb2 = new StringBuilder("form-data; name=\"");
|
|
sb2.append(entry4.getKey());
|
|
sb2.append("\"; filename=\"");
|
|
sb2.append(file.getName());
|
|
sb2.append("\"");
|
|
Headers of = Headers.of(HttpHeaders.CONTENT_DISPOSITION, sb2.toString());
|
|
String guessContentTypeFromName = URLConnection.guessContentTypeFromName(file.getName());
|
|
if (guessContentTypeFromName == null) {
|
|
guessContentTypeFromName = "application/octet-stream";
|
|
}
|
|
builder2.addPart(of, RequestBody.create(MediaType.parse(guessContentTypeFromName), file));
|
|
} else {
|
|
StringBuilder sb3 = new StringBuilder("form-data; name=\"");
|
|
sb3.append(entry4.getKey());
|
|
sb3.append("\"");
|
|
builder2.addPart(Headers.of(HttpHeaders.CONTENT_DISPOSITION, sb3.toString()), RequestBody.create((MediaType) null, a(entry4.getValue())));
|
|
}
|
|
}
|
|
requestBody = builder2.build();
|
|
} else if (obj == null) {
|
|
if (!"DELETE".equals(str2)) {
|
|
requestBody = RequestBody.create(MediaType.parse(str5), "");
|
|
}
|
|
} else if (obj instanceof byte[]) {
|
|
requestBody = RequestBody.create(MediaType.parse(str5), (byte[]) obj);
|
|
} else if (obj instanceof File) {
|
|
requestBody = RequestBody.create(MediaType.parse(str5), (File) obj);
|
|
} else {
|
|
if (!e(str5)) {
|
|
StringBuilder sb4 = new StringBuilder("Content type \"");
|
|
sb4.append(str5);
|
|
sb4.append("\" is not supported");
|
|
throw new io.beid.beidk.a.b(sb4.toString());
|
|
}
|
|
requestBody = RequestBody.create(MediaType.parse(str5), obj != null ? this.g.b.toJson(obj) : null);
|
|
}
|
|
}
|
|
return this.b.newCall(url.method(str2, requestBody).build());
|
|
}
|
|
|
|
private static boolean e(String str) {
|
|
return str != null && (str.matches("(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$") || str.equals("*/*"));
|
|
}
|
|
|
|
public static String b(String[] strArr) {
|
|
if (strArr.length == 0 || strArr[0].equals("*/*")) {
|
|
return AbstractSpiCall.ACCEPT_JSON_VALUE;
|
|
}
|
|
for (String str : strArr) {
|
|
if (e(str)) {
|
|
return str;
|
|
}
|
|
}
|
|
return strArr[0];
|
|
}
|
|
|
|
private <T> T a(Response response, Type type) throws io.beid.beidk.a.b {
|
|
String str = null;
|
|
if (!response.isSuccessful()) {
|
|
if (response.body() != null) {
|
|
try {
|
|
str = response.body().string();
|
|
} catch (IOException e) {
|
|
throw new io.beid.beidk.a.b(response.message(), e, response.code(), response.headers().toMultimap());
|
|
}
|
|
}
|
|
throw new io.beid.beidk.a.b(response.message(), response.code(), response.headers().toMultimap(), str);
|
|
}
|
|
if (type != null && response.code() != 204) {
|
|
return (T) b(response, type);
|
|
}
|
|
if (response.body() != null) {
|
|
try {
|
|
response.body().close();
|
|
} catch (Exception e2) {
|
|
throw new io.beid.beidk.a.b(response.message(), e2, response.code(), response.headers().toMultimap());
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
private <T> T b(Response response, Type type) throws io.beid.beidk.a.b {
|
|
if (response == null || type == null) {
|
|
return null;
|
|
}
|
|
if ("byte[]".equals(type.toString())) {
|
|
try {
|
|
return (T) response.body().bytes();
|
|
} catch (IOException e) {
|
|
throw new io.beid.beidk.a.b(e);
|
|
}
|
|
}
|
|
if (type.equals(File.class)) {
|
|
return (T) d(response);
|
|
}
|
|
try {
|
|
Object obj = response.body() != null ? (T) response.body().string() : (T) null;
|
|
if (obj == null || "".equals(obj)) {
|
|
return null;
|
|
}
|
|
String str = response.headers().get(HttpHeaders.CONTENT_TYPE);
|
|
if (str == null) {
|
|
str = AbstractSpiCall.ACCEPT_JSON_VALUE;
|
|
}
|
|
if (e(str)) {
|
|
return (T) this.g.b((String) obj, type);
|
|
}
|
|
if (type.equals(String.class)) {
|
|
return (T) obj;
|
|
}
|
|
StringBuilder sb = new StringBuilder("Content type \"");
|
|
sb.append(str);
|
|
sb.append("\" is not supported for type: ");
|
|
sb.append(type);
|
|
throw new io.beid.beidk.a.b(sb.toString(), response.code(), response.headers().toMultimap(), (String) obj);
|
|
} catch (IOException e2) {
|
|
throw new io.beid.beidk.a.b(e2);
|
|
}
|
|
}
|
|
|
|
public final <T> C13091fQe<T> d(Call call, Type type) throws io.beid.beidk.a.b {
|
|
try {
|
|
Response execute = call.execute();
|
|
return new C13091fQe<>(execute.code(), execute.headers().toMultimap(), a(execute, type));
|
|
} catch (IOException e) {
|
|
throw new io.beid.beidk.a.b(e);
|
|
}
|
|
}
|
|
}
|