what-the-bank/sources/okhttp3/MultipartReader.java

298 lines
11 KiB
Java

package okhttp3;
import java.io.Closeable;
import java.io.IOException;
import java.net.ProtocolException;
import java.util.concurrent.TimeUnit;
import o.C14953gcr;
import o.C14957gcv;
import o.C15111ghZ;
import o.C15139giB;
import o.C15155gij;
import o.C15160gio;
import o.C15163gir;
import o.InterfaceC15149gid;
import o.gdP;
import o.giD;
import okhttp3.internal.http1.HeadersReader;
/* loaded from: classes6.dex */
public final class MultipartReader implements Closeable {
public static final Companion Companion = new Companion(null);
private static final C15163gir afterBoundaryOptions;
private final String boundary;
private boolean closed;
private final C15155gij crlfDashDashBoundary;
private PartSource currentPart;
private final C15155gij dashDashBoundary;
private boolean noMoreParts;
private int partCount;
private final InterfaceC15149gid source;
public MultipartReader(InterfaceC15149gid interfaceC15149gid, String str) throws IOException {
C14957gcv.e(interfaceC15149gid, "");
C14957gcv.e(str, "");
this.source = interfaceC15149gid;
this.boundary = str;
C15111ghZ c15111ghZ = new C15111ghZ();
C14957gcv.e("--", "");
C15111ghZ c = c15111ghZ.c("--", 0, 2);
C14957gcv.e(str, "");
C15111ghZ c2 = c.c(str, 0, str.length());
this.dashDashBoundary = c2.c(c2.c);
C15111ghZ c15111ghZ2 = new C15111ghZ();
C14957gcv.e("\r\n--", "");
C15111ghZ c3 = c15111ghZ2.c("\r\n--", 0, 4);
C14957gcv.e(str, "");
C15111ghZ c4 = c3.c(str, 0, str.length());
this.crlfDashDashBoundary = c4.c(c4.c);
}
/* JADX WARN: Illegal instructions before constructor call */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public MultipartReader(okhttp3.ResponseBody r3) throws java.io.IOException {
/*
r2 = this;
java.lang.String r0 = ""
o.C14957gcv.e(r3, r0)
o.gid r0 = r3.source()
okhttp3.MediaType r3 = r3.contentType()
if (r3 != 0) goto L11
r3 = 0
goto L17
L11:
java.lang.String r1 = "boundary"
java.lang.String r3 = r3.parameter(r1)
L17:
if (r3 == 0) goto L1d
r2.<init>(r0, r3)
return
L1d:
java.net.ProtocolException r3 = new java.net.ProtocolException
java.lang.String r0 = "expected the Content-Type to have a boundary parameter"
r3.<init>(r0)
throw r3
*/
throw new UnsupportedOperationException("Method not decompiled: okhttp3.MultipartReader.<init>(okhttp3.ResponseBody):void");
}
public final Part nextPart() throws IOException {
if (!(!this.closed)) {
throw new IllegalStateException("closed".toString());
}
if (this.noMoreParts) {
return null;
}
if (this.partCount == 0 && this.source.e(0L, this.dashDashBoundary)) {
this.source.j(this.dashDashBoundary.a());
} else {
while (true) {
long currentPartBytesRemaining = currentPartBytesRemaining(8192L);
if (currentPartBytesRemaining == 0) {
break;
}
this.source.j(currentPartBytesRemaining);
}
this.source.j(this.crlfDashDashBoundary.a());
}
boolean z = false;
while (true) {
int c = this.source.c(afterBoundaryOptions);
if (c == -1) {
throw new ProtocolException("unexpected characters after boundary");
}
if (c == 0) {
this.partCount++;
Headers readHeaders = new HeadersReader(this.source).readHeaders();
PartSource partSource = new PartSource(this);
this.currentPart = partSource;
return new Part(readHeaders, C15160gio.c(partSource));
}
if (c == 1) {
if (z) {
throw new ProtocolException("unexpected characters after boundary");
}
if (this.partCount == 0) {
throw new ProtocolException("expected at least 1 part");
}
this.noMoreParts = true;
return null;
}
if (c == 2 || c == 3) {
z = true;
}
}
}
/* loaded from: classes6.dex */
final class PartSource implements giD {
final MultipartReader this$0;
private final C15139giB timeout;
public PartSource(MultipartReader multipartReader) {
C14957gcv.e(multipartReader, "");
this.this$0 = multipartReader;
this.timeout = new C15139giB();
}
@Override // o.giD, java.io.Closeable, java.lang.AutoCloseable
public final void close() {
if (C14957gcv.b(this.this$0.currentPart, this)) {
this.this$0.currentPart = null;
}
}
@Override // o.giD
public final long read(C15111ghZ c15111ghZ, long j) {
C14957gcv.e(c15111ghZ, "");
if (j >= 0) {
if (C14957gcv.b(this.this$0.currentPart, this)) {
C15139giB timeout = this.this$0.source.timeout();
C15139giB c15139giB = this.timeout;
MultipartReader multipartReader = this.this$0;
long timeoutNanos = timeout.timeoutNanos();
C15139giB.RVV rvv = C15139giB.Companion;
timeout.timeout(C15139giB.RVV.d(c15139giB.timeoutNanos(), timeout.timeoutNanos()), TimeUnit.NANOSECONDS);
if (timeout.hasDeadline()) {
long deadlineNanoTime = timeout.deadlineNanoTime();
if (c15139giB.hasDeadline()) {
timeout.deadlineNanoTime(Math.min(timeout.deadlineNanoTime(), c15139giB.deadlineNanoTime()));
}
try {
long currentPartBytesRemaining = multipartReader.currentPartBytesRemaining(j);
return currentPartBytesRemaining == 0 ? -1L : multipartReader.source.read(c15111ghZ, currentPartBytesRemaining);
} finally {
timeout.timeout(timeoutNanos, TimeUnit.NANOSECONDS);
if (c15139giB.hasDeadline()) {
timeout.deadlineNanoTime(deadlineNanoTime);
}
}
}
if (c15139giB.hasDeadline()) {
timeout.deadlineNanoTime(c15139giB.deadlineNanoTime());
}
try {
long currentPartBytesRemaining2 = multipartReader.currentPartBytesRemaining(j);
return currentPartBytesRemaining2 == 0 ? -1L : multipartReader.source.read(c15111ghZ, currentPartBytesRemaining2);
} finally {
timeout.timeout(timeoutNanos, TimeUnit.NANOSECONDS);
if (c15139giB.hasDeadline()) {
timeout.clearDeadline();
}
}
}
throw new IllegalStateException("closed".toString());
}
throw new IllegalArgumentException(C14957gcv.c("byteCount < 0: ", Long.valueOf(j)).toString());
}
@Override // o.giD
public final C15139giB timeout() {
return this.timeout;
}
}
@Override // java.io.Closeable, java.lang.AutoCloseable
public final void close() throws IOException {
if (this.closed) {
return;
}
this.closed = true;
this.currentPart = null;
this.source.close();
}
/* loaded from: classes6.dex */
public static final class Part implements Closeable {
private final InterfaceC15149gid body;
private final Headers headers;
public Part(Headers headers, InterfaceC15149gid interfaceC15149gid) {
C14957gcv.e(headers, "");
C14957gcv.e(interfaceC15149gid, "");
this.headers = headers;
this.body = interfaceC15149gid;
}
public final Headers headers() {
return this.headers;
}
@Override // java.io.Closeable, java.lang.AutoCloseable
public final void close() {
this.body.close();
}
public final InterfaceC15149gid body() {
return this.body;
}
}
/* loaded from: classes6.dex */
public static final class Companion {
private Companion() {
}
public final C15163gir getAfterBoundaryOptions() {
return MultipartReader.afterBoundaryOptions;
}
public /* synthetic */ Companion(C14953gcr c14953gcr) {
this();
}
}
static {
C15163gir.LWm lWm = C15163gir.c;
C15155gij.LWm lWm2 = C15155gij.c;
C14957gcv.e("\r\n", "");
C14957gcv.e("\r\n", "");
byte[] bytes = "\r\n".getBytes(gdP.a);
C14957gcv.c(bytes, "");
C15155gij c15155gij = new C15155gij(bytes);
c15155gij.d = "\r\n";
C15155gij.LWm lWm3 = C15155gij.c;
C14957gcv.e("--", "");
C14957gcv.e("--", "");
byte[] bytes2 = "--".getBytes(gdP.a);
C14957gcv.c(bytes2, "");
C15155gij c15155gij2 = new C15155gij(bytes2);
c15155gij2.d = "--";
C15155gij.LWm lWm4 = C15155gij.c;
C14957gcv.e(" ", "");
C14957gcv.e(" ", "");
byte[] bytes3 = " ".getBytes(gdP.a);
C14957gcv.c(bytes3, "");
C15155gij c15155gij3 = new C15155gij(bytes3);
c15155gij3.d = " ";
C15155gij.LWm lWm5 = C15155gij.c;
C14957gcv.e("\t", "");
C14957gcv.e("\t", "");
byte[] bytes4 = "\t".getBytes(gdP.a);
C14957gcv.c(bytes4, "");
C15155gij c15155gij4 = new C15155gij(bytes4);
c15155gij4.d = "\t";
afterBoundaryOptions = lWm.a(c15155gij, c15155gij2, c15155gij3, c15155gij4);
}
/* JADX INFO: Access modifiers changed from: private */
public final long currentPartBytesRemaining(long j) {
this.source.g(this.crlfDashDashBoundary.a());
C15111ghZ i = this.source.i();
C15155gij c15155gij = this.crlfDashDashBoundary;
C14957gcv.e(c15155gij, "");
long a = i.a(c15155gij, 0L);
if (a == -1) {
return Math.min(j, (this.source.i().c - this.crlfDashDashBoundary.a()) + 1);
}
return Math.min(j, a);
}
public final String boundary() {
return this.boundary;
}
}