what-the-bank/sources/retrofit2/OkHttpCall.java

350 lines
11 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package retrofit2;
import java.io.IOException;
import java.util.Objects;
import o.AbstractC15154gii;
import o.C15111ghZ;
import o.C15139giB;
import o.C15160gio;
import o.InterfaceC15149gid;
import okhttp3.Call;
import okhttp3.MediaType;
import okhttp3.Request;
import okhttp3.ResponseBody;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public final class OkHttpCall<T> implements Call<T> {
private final Object[] args;
private final Call.Factory callFactory;
private volatile boolean canceled;
private Throwable creationFailure;
private boolean executed;
private okhttp3.Call rawCall;
private final RequestFactory requestFactory;
private final Converter<ResponseBody, T> responseConverter;
/* JADX INFO: Access modifiers changed from: package-private */
public OkHttpCall(RequestFactory requestFactory, Object[] objArr, Call.Factory factory, Converter<ResponseBody, T> converter) {
this.requestFactory = requestFactory;
this.args = objArr;
this.callFactory = factory;
this.responseConverter = converter;
}
@Override // retrofit2.Call
public final OkHttpCall<T> clone() {
return new OkHttpCall<>(this.requestFactory, this.args, this.callFactory, this.responseConverter);
}
@Override // retrofit2.Call
public final Request request() {
Request request;
synchronized (this) {
try {
request = getRawCall().request();
} catch (IOException e) {
throw new RuntimeException("Unable to create request.", e);
}
}
return request;
}
@Override // retrofit2.Call
public final C15139giB timeout() {
C15139giB timeout;
synchronized (this) {
try {
timeout = getRawCall().timeout();
} catch (IOException e) {
throw new RuntimeException("Unable to create call.", e);
}
}
return timeout;
}
private okhttp3.Call getRawCall() throws IOException {
okhttp3.Call call = this.rawCall;
if (call != null) {
return call;
}
Throwable th = this.creationFailure;
if (th != null) {
if (th instanceof IOException) {
throw ((IOException) th);
}
if (th instanceof RuntimeException) {
throw ((RuntimeException) th);
}
throw ((Error) th);
}
try {
okhttp3.Call createRawCall = createRawCall();
this.rawCall = createRawCall;
return createRawCall;
} catch (IOException | Error | RuntimeException e) {
Utils.throwIfFatal(e);
this.creationFailure = e;
throw e;
}
}
@Override // retrofit2.Call
public final void enqueue(Callback<T> callback) {
okhttp3.Call call;
Throwable th;
Objects.requireNonNull(callback, "callback == null");
synchronized (this) {
if (this.executed) {
throw new IllegalStateException("Already executed.");
}
this.executed = true;
call = this.rawCall;
th = this.creationFailure;
if (call == null && th == null) {
try {
okhttp3.Call createRawCall = createRawCall();
this.rawCall = createRawCall;
call = createRawCall;
} catch (Throwable th2) {
th = th2;
Utils.throwIfFatal(th);
this.creationFailure = th;
}
}
}
if (th != null) {
callback.onFailure(this, th);
return;
}
if (this.canceled) {
call.cancel();
}
call.enqueue(new okhttp3.Callback(this, callback) { // from class: retrofit2.OkHttpCall.1
final OkHttpCall this$0;
final Callback val$callback;
{
this.this$0 = this;
this.val$callback = callback;
}
@Override // okhttp3.Callback
public void onResponse(okhttp3.Call call2, okhttp3.Response response) {
try {
try {
this.val$callback.onResponse(this.this$0, this.this$0.parseResponse(response));
} catch (Throwable th3) {
Utils.throwIfFatal(th3);
}
} catch (Throwable th4) {
Utils.throwIfFatal(th4);
callFailure(th4);
}
}
@Override // okhttp3.Callback
public void onFailure(okhttp3.Call call2, IOException iOException) {
callFailure(iOException);
}
private void callFailure(Throwable th3) {
try {
this.val$callback.onFailure(this.this$0, th3);
} catch (Throwable th4) {
Utils.throwIfFatal(th4);
}
}
});
}
@Override // retrofit2.Call
public final boolean isExecuted() {
boolean z;
synchronized (this) {
z = this.executed;
}
return z;
}
@Override // retrofit2.Call
public final Response<T> execute() throws IOException {
okhttp3.Call rawCall;
synchronized (this) {
if (this.executed) {
throw new IllegalStateException("Already executed.");
}
this.executed = true;
rawCall = getRawCall();
}
if (this.canceled) {
rawCall.cancel();
}
return parseResponse(rawCall.execute());
}
private okhttp3.Call createRawCall() throws IOException {
okhttp3.Call newCall = this.callFactory.newCall(this.requestFactory.create(this.args));
if (newCall != null) {
return newCall;
}
throw new NullPointerException("Call.Factory returned null.");
}
final Response<T> parseResponse(okhttp3.Response response) throws IOException {
ResponseBody body = response.body();
okhttp3.Response build = response.newBuilder().body(new NoContentResponseBody(body.contentType(), body.contentLength())).build();
int code = build.code();
if (code < 200 || code >= 300) {
try {
return Response.error(Utils.buffer(body), build);
} finally {
body.close();
}
}
if (code == 204 || code == 205) {
body.close();
return Response.success((Object) null, build);
}
ExceptionCatchingResponseBody exceptionCatchingResponseBody = new ExceptionCatchingResponseBody(body);
try {
return Response.success(this.responseConverter.convert(exceptionCatchingResponseBody), build);
} catch (RuntimeException e) {
exceptionCatchingResponseBody.throwIfCaught();
throw e;
}
}
@Override // retrofit2.Call
public final void cancel() {
okhttp3.Call call;
this.canceled = true;
synchronized (this) {
call = this.rawCall;
}
if (call != null) {
call.cancel();
}
}
/* JADX WARN: Code restructure failed: missing block: B:10:0x000f, code lost:
if (r0.isCanceled() != false) goto L12;
*/
@Override // retrofit2.Call
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public final boolean isCanceled() {
/*
r2 = this;
boolean r0 = r2.canceled
r1 = 1
if (r0 == 0) goto L6
return r1
L6:
monitor-enter(r2)
okhttp3.Call r0 = r2.rawCall // Catch: java.lang.Throwable -> L15
if (r0 == 0) goto L12
boolean r0 = r0.isCanceled() // Catch: java.lang.Throwable -> L15
if (r0 == 0) goto L12
goto L13
L12:
r1 = 0
L13:
monitor-exit(r2)
return r1
L15:
r0 = move-exception
monitor-exit(r2)
throw r0
*/
throw new UnsupportedOperationException("Method not decompiled: retrofit2.OkHttpCall.isCanceled():boolean");
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public static final class NoContentResponseBody extends ResponseBody {
private final long contentLength;
private final MediaType contentType;
/* JADX INFO: Access modifiers changed from: package-private */
public NoContentResponseBody(MediaType mediaType, long j) {
this.contentType = mediaType;
this.contentLength = j;
}
@Override // okhttp3.ResponseBody
public final InterfaceC15149gid source() {
throw new IllegalStateException("Cannot read raw response body of a converted body.");
}
@Override // okhttp3.ResponseBody
public final MediaType contentType() {
return this.contentType;
}
@Override // okhttp3.ResponseBody
public final long contentLength() {
return this.contentLength;
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public static final class ExceptionCatchingResponseBody extends ResponseBody {
private final ResponseBody delegate;
private final InterfaceC15149gid delegateSource;
IOException thrownException;
ExceptionCatchingResponseBody(ResponseBody responseBody) {
this.delegate = responseBody;
this.delegateSource = C15160gio.c(new AbstractC15154gii(this, responseBody.source()) { // from class: retrofit2.OkHttpCall.ExceptionCatchingResponseBody.1
final ExceptionCatchingResponseBody this$0;
{
this.this$0 = this;
}
@Override // o.AbstractC15154gii, o.giD
public long read(C15111ghZ c15111ghZ, long j) throws IOException {
try {
return super.read(c15111ghZ, j);
} catch (IOException e) {
this.this$0.thrownException = e;
throw e;
}
}
});
}
@Override // okhttp3.ResponseBody
public final MediaType contentType() {
return this.delegate.contentType();
}
@Override // okhttp3.ResponseBody
public final long contentLength() {
return this.delegate.contentLength();
}
@Override // okhttp3.ResponseBody, java.io.Closeable, java.lang.AutoCloseable
public final void close() {
this.delegate.close();
}
final void throwIfCaught() throws IOException {
IOException iOException = this.thrownException;
if (iOException != null) {
throw iOException;
}
}
@Override // okhttp3.ResponseBody
public final InterfaceC15149gid source() {
return this.delegateSource;
}
}
}