正在查看: Clean Center v0.5.5 应用的 Call.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Clean Center v0.5.5 应用的 Call.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.lambda.common.http;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import com.lambda.common.http.Call;
import com.lambda.common.utils.utilcode.util.ConvertUtils;
import com.lambda.common.utils.utilcode.util.ThreadUtils;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;
import javax.net.ssl.HttpsURLConnection;
import kotlin.Metadata;
import kotlin.Unit;
import kotlin.collections.MapsKt;
import kotlin.io.CloseableKt;
import kotlin.jvm.JvmStatic;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
@Metadata(d1 = {"\u0000.\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0010\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0004\u0018\u0000 \u00162\u00020\u0001:\u0002\u0015\u0016B\u000f\b\u0002\u0012\u0006\u0010\u0002\u001a\u00020\u0003¢\u0006\u0002\u0010\u0004J\u0018\u0010\u000b\u001a\u00020\f2\u0006\u0010\u0005\u001a\u00020\u00062\u0006\u0010\u0002\u001a\u00020\u0003H\u0002J\u0018\u0010\r\u001a\u00020\f2\u0006\u0010\u0005\u001a\u00020\u00062\u0006\u0010\u0002\u001a\u00020\u0003H\u0002J\u0006\u0010\u000e\u001a\u00020\fJ\u0010\u0010\u000f\u001a\u00020\u00062\u0006\u0010\u0002\u001a\u00020\u0003H\u0002J\u0014\u0010\u0010\u001a\u00020\f2\f\u0010\u0011\u001a\b\u0012\u0004\u0012\u00020\u00130\u0012J\u0006\u0010\u0014\u001a\u00020\u0013R\u001c\u0010\u0005\u001a\u0004\u0018\u00010\u0006X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0007\u0010\b\"\u0004\b\t\u0010\nR\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\u0017"}, d2 = {"Lcom/lambda/common/http/Call;", "", "request", "Lcom/lambda/common/http/Request;", "(Lcom/lambda/common/http/Request;)V", "connection", "Ljava/net/HttpURLConnection;", "getConnection", "()Ljava/net/HttpURLConnection;", "setConnection", "(Ljava/net/HttpURLConnection;)V", "addBody", "", "addHeader", "cancel", "createConnection", "enqueue", "callback", "Lcom/lambda/common/http/Callback;", "Lcom/lambda/common/http/Response;", "execute", "AsyncCall", "Companion", "lib_release"}, k = 1, mv = {1, 6, 0}, xi = 48)
public final class Call {
private static final int BUFFER_SIZE = 8192;
private static final int CONNECT_TIMEOUT = 20000;
public static final Companion INSTANCE = new Companion(null);
private static final int READ_TIMEOUT = 20000;
private HttpURLConnection connection;
private final Request request;
public Call(Request request, DefaultConstructorMarker defaultConstructorMarker) {
this(request);
}
@JvmStatic
public static final Call newCall(Request request) {
return INSTANCE.newCall(request);
}
public final HttpURLConnection getConnection() {
return this.connection;
}
public final void setConnection(HttpURLConnection httpURLConnection) {
this.connection = httpURLConnection;
}
private Call(Request request) {
this.request = request;
}
public final Response execute() {
String message;
String responseMessage;
try {
HttpURLConnection createConnection = createConnection(this.request);
this.connection = createConnection;
createConnection.connect();
Request request = this.request;
int responseCode = createConnection.getResponseCode();
String responseMessage2 = createConnection.getResponseMessage();
Intrinsics.checkNotNullExpressionValue(responseMessage2, "responseMessage");
String contentType = createConnection.getContentType();
Intrinsics.checkNotNullExpressionValue(contentType, "contentType");
Map<String, List<String>> headerFields = createConnection.getHeaderFields();
Intrinsics.checkNotNullExpressionValue(headerFields, "headerFields");
return new Response(request, responseCode, responseMessage2, contentType, headerFields, new ResponseBody(ConvertUtils.inputStream2Bytes(createConnection.getInputStream())));
} catch (Exception e) {
e.printStackTrace();
Request request2 = this.request;
HttpURLConnection httpURLConnection = this.connection;
int responseCode2 = httpURLConnection != null ? httpURLConnection.getResponseCode() : -1;
HttpURLConnection httpURLConnection2 = this.connection;
if (httpURLConnection2 == null || (responseMessage = httpURLConnection2.getResponseMessage()) == null) {
message = e.getMessage();
if (message == null) {
message = "";
}
} else {
message = responseMessage;
}
HttpURLConnection httpURLConnection3 = this.connection;
String contentType2 = httpURLConnection3 != null ? httpURLConnection3.getContentType() : null;
String str = contentType2 == null ? "" : contentType2;
HttpURLConnection httpURLConnection4 = this.connection;
Map<String, List<String>> headerFields2 = httpURLConnection4 != null ? httpURLConnection4.getHeaderFields() : null;
if (headerFields2 == null) {
headerFields2 = MapsKt.emptyMap();
}
Map<String, List<String>> map = headerFields2;
HttpURLConnection httpURLConnection5 = this.connection;
return new Response(request2, responseCode2, message, str, map, new ResponseBody(ConvertUtils.inputStream2Bytes(httpURLConnection5 != null ? httpURLConnection5.getErrorStream() : null)));
}
}
public final void enqueue(Callback<Response> callback) {
Intrinsics.checkNotNullParameter(callback, "callback");
callback.onRequest();
ThreadUtils.getCachedPool().execute(new AsyncCall(this, callback));
}
public final HttpURLConnection createConnection(Request request) throws Exception {
URLConnection openConnection = new URL(request.getUrl()).openConnection();
if (openConnection == null) {
throw new NullPointerException("null cannot be cast to non-null type java.net.HttpURLConnection");
}
HttpURLConnection httpURLConnection = (HttpURLConnection) openConnection;
if (httpURLConnection instanceof HttpsURLConnection) {
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) httpURLConnection;
httpsURLConnection.setSSLSocketFactory(SSLSocketClient.INSTANCE.getSSLSocketFactory());
httpsURLConnection.setHostnameVerifier(SSLSocketClient.INSTANCE.getHostnameVerifier());
}
if (request.getRequestMethod() == RequestMethod.POST) {
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
}
httpURLConnection.setRequestMethod(request.getRequestMethod().name());
httpURLConnection.setConnectTimeout(AccessibilityNodeInfoCompat.EXTRA_DATA_TEXT_CHARACTER_LOCATION_ARG_MAX_LENGTH);
httpURLConnection.setReadTimeout(AccessibilityNodeInfoCompat.EXTRA_DATA_TEXT_CHARACTER_LOCATION_ARG_MAX_LENGTH);
httpURLConnection.setInstanceFollowRedirects(true);
addHeader(httpURLConnection, request);
addBody(httpURLConnection, request);
return httpURLConnection;
}
private final void addHeader(HttpURLConnection connection, Request request) throws Exception {
for (Map.Entry<String, String> entry : request.getHeaders().entrySet()) {
connection.setRequestProperty(entry.getKey(), entry.getValue());
}
}
private final void addBody(HttpURLConnection connection, Request request) throws Exception {
BufferedInputStream bis;
String mediaType;
RequestBody requestBody = request.getRequestBody();
if (requestBody != null && (mediaType = requestBody.getMediaType()) != null) {
connection.setRequestProperty("content-type", mediaType);
}
RequestBody requestBody2 = request.getRequestBody();
if ((requestBody2 != null ? requestBody2.getLength() : 0L) > 0) {
RequestBody requestBody3 = request.getRequestBody();
connection.setRequestProperty("content-length", String.valueOf(requestBody3 != null ? Long.valueOf(requestBody3.getLength()) : null));
}
RequestBody requestBody4 = request.getRequestBody();
if (requestBody4 == null || (bis = requestBody4.getBis()) == null) {
return;
}
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(connection.getOutputStream());
try {
BufferedOutputStream bufferedOutputStream2 = bufferedOutputStream;
byte[] bArr = new byte[8192];
while (true) {
int read = bis.read(bArr);
if (read != -1) {
bufferedOutputStream2.write(bArr, 0, read);
} else {
bufferedOutputStream2.flush();
Unit unit = Unit.INSTANCE;
CloseableKt.closeFinally(bufferedOutputStream, (Throwable) null);
return;
}
}
} catch (Throwable th) {
try {
throw th;
} catch (Throwable th2) {
CloseableKt.closeFinally(bufferedOutputStream, th);
throw th2;
}
}
}
@Metadata(d1 = {"\u0000\u001c\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0000\b\u0082\u0004\u0018\u00002\u00020\u0001B\u0013\u0012\f\u0010\u0002\u001a\b\u0012\u0004\u0012\u00020\u00040\u0003¢\u0006\u0002\u0010\u0005J\b\u0010\u0006\u001a\u00020\u0007H\u0016R\u0014\u0010\u0002\u001a\b\u0012\u0004\u0012\u00020\u00040\u0003X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\b"}, d2 = {"Lcom/lambda/common/http/Call$AsyncCall;", "Ljava/lang/Runnable;", "callback", "Lcom/lambda/common/http/Callback;", "Lcom/lambda/common/http/Response;", "(Lcom/lambda/common/http/Call;Lcom/lambda/common/http/Callback;)V", "run", "", "lib_release"}, k = 1, mv = {1, 6, 0}, xi = 48)
final class AsyncCall implements Runnable {
private final Callback<Response> callback;
final Call this$0;
public AsyncCall(Call call, Callback<Response> callback) {
Intrinsics.checkNotNullParameter(callback, "callback");
this.this$0 = call;
this.callback = callback;
}
@Override
public void run() {
try {
Call call = this.this$0;
final HttpURLConnection createConnection = call.createConnection(call.request);
Call call2 = this.this$0;
call2.setConnection(createConnection);
createConnection.connect();
Request request = call2.request;
int responseCode = createConnection.getResponseCode();
String responseMessage = createConnection.getResponseMessage();
Intrinsics.checkNotNullExpressionValue(responseMessage, "responseMessage");
String contentType = createConnection.getContentType();
Intrinsics.checkNotNullExpressionValue(contentType, "contentType");
Map<String, List<String>> headerFields = createConnection.getHeaderFields();
Intrinsics.checkNotNullExpressionValue(headerFields, "headerFields");
final Response response = new Response(request, responseCode, responseMessage, contentType, headerFields, new ResponseBody(ConvertUtils.inputStream2Bytes(createConnection.getInputStream())));
if (response.isSuccessful()) {
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public final void run() {
Call.AsyncCall.m126run$lambda2$lambda0(Call.AsyncCall.this, response);
}
});
} else {
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public final void run() {
Call.AsyncCall.m127run$lambda2$lambda1(Call.AsyncCall.this, response, createConnection);
}
});
}
} catch (Exception e) {
e.printStackTrace();
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public final void run() {
Call.AsyncCall.m128run$lambda3(Call.AsyncCall.this, e);
}
});
}
}
public static final void m126run$lambda2$lambda0(AsyncCall asyncCall, Response response) {
Intrinsics.checkNotNullParameter(asyncCall, "this$0");
Intrinsics.checkNotNullParameter(response, "$response");
asyncCall.callback.onSuccess(response);
}
public static final void m127run$lambda2$lambda1(AsyncCall asyncCall, Response response, HttpURLConnection httpURLConnection) {
Intrinsics.checkNotNullParameter(asyncCall, "this$0");
Intrinsics.checkNotNullParameter(response, "$response");
Intrinsics.checkNotNullParameter(httpURLConnection, "$this_apply");
Callback<Response> callback = asyncCall.callback;
HttpException httpException = response.getHttpException();
if (httpException == null) {
httpException = new HttpException(httpURLConnection.getResponseCode(), httpURLConnection.getResponseMessage());
}
callback.onFailed(httpException);
}
public static final void m128run$lambda3(AsyncCall asyncCall, Exception exc) {
Intrinsics.checkNotNullParameter(asyncCall, "this$0");
Intrinsics.checkNotNullParameter(exc, "$e");
asyncCall.callback.onFailed(new HttpException(0, exc.getMessage(), 1, null));
}
}
public final void cancel() {
try {
HttpURLConnection httpURLConnection = this.connection;
if (httpURLConnection != null) {
httpURLConnection.disconnect();
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Metadata(d1 = {"\u0000 \n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\b\u0086\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002J\u0010\u0010\u0007\u001a\u00020\b2\u0006\u0010\t\u001a\u00020\nH\u0007R\u000e\u0010\u0003\u001a\u00020\u0004X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\u0005\u001a\u00020\u0004X\u0082T¢\u0006\u0002\n\u0000R\u000e\u0010\u0006\u001a\u00020\u0004X\u0082T¢\u0006\u0002\n\u0000¨\u0006\u000b"}, d2 = {"Lcom/lambda/common/http/Call$Companion;", "", "()V", "BUFFER_SIZE", "", "CONNECT_TIMEOUT", "READ_TIMEOUT", "newCall", "Lcom/lambda/common/http/Call;", "request", "Lcom/lambda/common/http/Request;", "lib_release"}, k = 1, mv = {1, 6, 0}, xi = 48)
public static final class Companion {
public Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
private Companion() {
}
@JvmStatic
public final Call newCall(Request request) {
Intrinsics.checkNotNullParameter(request, "request");
return new Call(request, null);
}
}
}