discord-jadx/app/src/main/java/com/discord/restapi/utils/CountingRequestBody.java

116 lines
4.2 KiB
Java

package com.discord.restapi.utils;
import c.d.b.a.a;
import c0.g0.c;
import c0.z.d.m;
import f0.e;
import f0.i;
import f0.q;
import f0.v;
import java.io.IOException;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.DefaultConstructorMarker;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okio.BufferedSink;
import okio.ByteString;
import rx.Observable;
import rx.subjects.BehaviorSubject;
/* compiled from: CountingRequestBody.kt */
public final class CountingRequestBody extends RequestBody {
private final BehaviorSubject<Long> bytesWrittenSubject;
private final RequestBody delegate;
private final long estimatedContentLength;
private final int ignoreWriteToCount;
private int numWriteToCalls;
/* compiled from: CountingRequestBody.kt */
public static final class CountingSink extends i {
private long bytesWritten;
private final Function1<Long, Unit> listener;
/* JADX DEBUG: Multi-variable search result rejected for r3v0, resolved type: kotlin.jvm.functions.Function1<? super java.lang.Long, kotlin.Unit> */
/* JADX WARN: Multi-variable type inference failed */
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public CountingSink(v vVar, Function1<? super Long, Unit> function1) {
super(vVar);
m.checkNotNullParameter(vVar, "delegate");
m.checkNotNullParameter(function1, "listener");
this.listener = function1;
}
@Override // f0.i, f0.v
public void write(e eVar, long j) throws IOException {
m.checkNotNullParameter(eVar, "source");
super.write(eVar, j);
long j2 = this.bytesWritten + j;
this.bytesWritten = j2;
this.listener.invoke(Long.valueOf(j2));
}
}
public CountingRequestBody(RequestBody requestBody, int i) {
m.checkNotNullParameter(requestBody, "delegate");
this.delegate = requestBody;
this.ignoreWriteToCount = i;
this.bytesWrittenSubject = BehaviorSubject.l0(0L);
this.estimatedContentLength = requestBody.contentLength();
}
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
public /* synthetic */ CountingRequestBody(RequestBody requestBody, int i, int i2, DefaultConstructorMarker defaultConstructorMarker) {
this(requestBody, (i2 & 2) != 0 ? 0 : i);
}
public static final /* synthetic */ void access$updateProgress(CountingRequestBody countingRequestBody, long j) {
countingRequestBody.updateProgress(j);
}
private final void updateProgress(long j) {
if (this.numWriteToCalls > this.ignoreWriteToCount) {
this.bytesWrittenSubject.onNext(Long.valueOf(j));
}
}
@Override // okhttp3.RequestBody
public long contentLength() throws IOException {
return -1;
}
@Override // okhttp3.RequestBody
public MediaType contentType() {
return this.delegate.contentType();
}
public final Observable<Long> getBytesWrittenObservable() {
Observable<Long> K = this.bytesWrittenSubject.q().K();
m.checkNotNullExpressionValue(K, "bytesWrittenSubject.dist…().onBackpressureLatest()");
return K;
}
public final long getEstimatedContentLength() {
return this.estimatedContentLength;
}
@Override // okhttp3.RequestBody
public void writeTo(BufferedSink bufferedSink) throws IOException {
m.checkNotNullParameter(bufferedSink, "sink");
int i = this.numWriteToCalls;
this.numWriteToCalls = i + 1;
if (i < this.ignoreWriteToCount) {
ByteString.a aVar = ByteString.j;
StringBuilder M = a.M('<');
M.append(this.delegate);
M.append('>');
bufferedSink.d0(aVar.b(M.toString(), c.a));
return;
}
CountingSink countingSink = new CountingSink(bufferedSink, new CountingRequestBody$writeTo$countingSink$1(this));
m.checkParameterIsNotNull(countingSink, "$this$buffer");
q qVar = new q(countingSink);
this.delegate.writeTo(qVar);
qVar.flush();
}
}