package okhttp3; import io.sentry.ProfilingTraceData; import io.sentry.protocol.TransactionInfo; import java.io.Closeable; import java.io.IOException; import java.net.ProtocolException; import java.util.concurrent.TimeUnit; import kotlin.Metadata; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.jvm.internal.Intrinsics; import okhttp3.internal.http1.HeadersReader; import okio.Buffer; import okio.BufferedSource; import okio.ByteString; import okio.Okio; import okio.Options; import okio.Source; import okio.Timeout; /* compiled from: MultipartReader.kt */ @Metadata(bv = {1, 0, 3}, d1 = {"\u0000P\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0003\n\u0002\u0010\u000b\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\b\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\t\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0004\u0018\u0000 \u001c2\u00020\u0001:\u0003\u001c\u001d\u001eB\u000f\b\u0016\u0012\u0006\u0010\u0002\u001a\u00020\u0003¢\u0006\u0002\u0010\u0004B\u0015\u0012\u0006\u0010\u0005\u001a\u00020\u0006\u0012\u0006\u0010\u0007\u001a\u00020\b¢\u0006\u0002\u0010\tJ\b\u0010\u0015\u001a\u00020\u0016H\u0016J\u0010\u0010\u0017\u001a\u00020\u00182\u0006\u0010\u0019\u001a\u00020\u0018H\u0002J\b\u0010\u001a\u001a\u0004\u0018\u00010\u001bR\u0013\u0010\u0007\u001a\u00020\b8\u0007¢\u0006\b\n\u0000\u001a\u0004\b\u0007\u0010\nR\u000e\u0010\u000b\u001a\u00020\fX\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\r\u001a\u00020\u000eX\u0082\u0004¢\u0006\u0002\n\u0000R\u0014\u0010\u000f\u001a\b\u0018\u00010\u0010R\u00020\u0000X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0011\u001a\u00020\u000eX\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0012\u001a\u00020\fX\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0013\u001a\u00020\u0014X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0005\u001a\u00020\u0006X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\u001f"}, d2 = {"Lokhttp3/MultipartReader;", "Ljava/io/Closeable;", io.sentry.protocol.Response.TYPE, "Lokhttp3/ResponseBody;", "(Lokhttp3/ResponseBody;)V", TransactionInfo.JsonKeys.SOURCE, "Lokio/BufferedSource;", "boundary", "", "(Lokio/BufferedSource;Ljava/lang/String;)V", "()Ljava/lang/String;", "closed", "", "crlfDashDashBoundary", "Lokio/ByteString;", "currentPart", "Lokhttp3/MultipartReader$PartSource;", "dashDashBoundary", "noMoreParts", "partCount", "", "close", "", "currentPartBytesRemaining", "", "maxResult", "nextPart", "Lokhttp3/MultipartReader$Part;", "Companion", "Part", "PartSource", "okhttp"}, k = 1, mv = {1, 4, 0}) /* loaded from: classes3.dex */ public final class MultipartReader implements Closeable { /* renamed from: Companion, reason: from kotlin metadata */ public static final Companion INSTANCE = new Companion(null); private static final Options afterBoundaryOptions = Options.INSTANCE.of(ByteString.INSTANCE.encodeUtf8("\r\n"), ByteString.INSTANCE.encodeUtf8("--"), ByteString.INSTANCE.encodeUtf8(" "), ByteString.INSTANCE.encodeUtf8("\t")); private final String boundary; private boolean closed; private final ByteString crlfDashDashBoundary; private PartSource currentPart; private final ByteString dashDashBoundary; private boolean noMoreParts; private int partCount; private final BufferedSource source; /* renamed from: boundary, reason: from getter */ public final String getBoundary() { return this.boundary; } public MultipartReader(BufferedSource source, String boundary) throws IOException { Intrinsics.checkNotNullParameter(source, "source"); Intrinsics.checkNotNullParameter(boundary, "boundary"); this.source = source; this.boundary = boundary; this.dashDashBoundary = new Buffer().writeUtf8("--").writeUtf8(boundary).readByteString(); this.crlfDashDashBoundary = new Buffer().writeUtf8("\r\n--").writeUtf8(boundary).readByteString(); } /* 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 = "response" kotlin.jvm.internal.Intrinsics.checkNotNullParameter(r3, r0) okio.BufferedSource r0 = r3.getSource() okhttp3.MediaType r3 = r3.get$contentType() if (r3 == 0) goto L1b java.lang.String r1 = "boundary" java.lang.String r3 = r3.parameter(r1) if (r3 == 0) goto L1b r2.(r0, r3) return L1b: java.net.ProtocolException r2 = new java.net.ProtocolException java.lang.String r3 = "expected the Content-Type to have a boundary parameter" r2.(r3) java.lang.Throwable r2 = (java.lang.Throwable) r2 throw r2 */ throw new UnsupportedOperationException("Method not decompiled: okhttp3.MultipartReader.(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.rangeEquals(0L, this.dashDashBoundary)) { this.source.skip(this.dashDashBoundary.size()); } else { while (true) { long currentPartBytesRemaining = currentPartBytesRemaining(8192L); if (currentPartBytesRemaining == 0) { break; } this.source.skip(currentPartBytesRemaining); } this.source.skip(this.crlfDashDashBoundary.size()); } boolean z = false; while (true) { int select = this.source.select(afterBoundaryOptions); if (select == -1) { throw new ProtocolException("unexpected characters after boundary"); } if (select == 0) { this.partCount++; Headers readHeaders = new HeadersReader(this.source).readHeaders(); PartSource partSource = new PartSource(); this.currentPart = partSource; return new Part(readHeaders, Okio.buffer(partSource)); } if (select == 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 (select == 2 || select == 3) { z = true; } } } /* compiled from: MultipartReader.kt */ @Metadata(bv = {1, 0, 3}, d1 = {"\u0000&\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\t\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\b\u0082\u0004\u0018\u00002\u00020\u0001B\u0005¢\u0006\u0002\u0010\u0002J\b\u0010\u0005\u001a\u00020\u0006H\u0016J\u0018\u0010\u0007\u001a\u00020\b2\u0006\u0010\t\u001a\u00020\n2\u0006\u0010\u000b\u001a\u00020\bH\u0016J\b\u0010\u0003\u001a\u00020\u0004H\u0016R\u000e\u0010\u0003\u001a\u00020\u0004X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\f"}, d2 = {"Lokhttp3/MultipartReader$PartSource;", "Lokio/Source;", "(Lokhttp3/MultipartReader;)V", ProfilingTraceData.TRUNCATION_REASON_TIMEOUT, "Lokio/Timeout;", "close", "", "read", "", "sink", "Lokio/Buffer;", "byteCount", "okhttp"}, k = 1, mv = {1, 4, 0}) /* loaded from: classes3.dex */ private final class PartSource implements Source { private final Timeout timeout = new Timeout(); @Override // okio.Source /* renamed from: timeout, reason: from getter */ public Timeout getTimeout() { return this.timeout; } public PartSource() { } @Override // okio.Source, java.io.Closeable, java.lang.AutoCloseable public void close() { if (Intrinsics.areEqual(MultipartReader.this.currentPart, this)) { MultipartReader.this.currentPart = null; } } @Override // okio.Source public long read(Buffer sink, long byteCount) { Intrinsics.checkNotNullParameter(sink, "sink"); if (byteCount >= 0) { if (Intrinsics.areEqual(MultipartReader.this.currentPart, this)) { Timeout timeout = MultipartReader.this.source.getTimeout(); Timeout timeout2 = this.timeout; long timeoutNanos = timeout.getTimeoutNanos(); timeout.timeout(Timeout.INSTANCE.minTimeout(timeout2.getTimeoutNanos(), timeout.getTimeoutNanos()), TimeUnit.NANOSECONDS); if (timeout.getHasDeadline()) { long deadlineNanoTime = timeout.deadlineNanoTime(); if (timeout2.getHasDeadline()) { timeout.deadlineNanoTime(Math.min(timeout.deadlineNanoTime(), timeout2.deadlineNanoTime())); } try { long currentPartBytesRemaining = MultipartReader.this.currentPartBytesRemaining(byteCount); return currentPartBytesRemaining == 0 ? -1L : MultipartReader.this.source.read(sink, currentPartBytesRemaining); } finally { timeout.timeout(timeoutNanos, TimeUnit.NANOSECONDS); if (timeout2.getHasDeadline()) { timeout.deadlineNanoTime(deadlineNanoTime); } } } if (timeout2.getHasDeadline()) { timeout.deadlineNanoTime(timeout2.deadlineNanoTime()); } try { long currentPartBytesRemaining2 = MultipartReader.this.currentPartBytesRemaining(byteCount); return currentPartBytesRemaining2 == 0 ? -1L : MultipartReader.this.source.read(sink, currentPartBytesRemaining2); } finally { timeout.timeout(timeoutNanos, TimeUnit.NANOSECONDS); if (timeout2.getHasDeadline()) { timeout.clearDeadline(); } } } throw new IllegalStateException("closed".toString()); } throw new IllegalArgumentException(("byteCount < 0: " + byteCount).toString()); } } /* JADX INFO: Access modifiers changed from: private */ public final long currentPartBytesRemaining(long maxResult) { this.source.require(this.crlfDashDashBoundary.size()); long indexOf = this.source.getBuffer().indexOf(this.crlfDashDashBoundary); if (indexOf == -1) { return Math.min(maxResult, (this.source.getBuffer().size() - this.crlfDashDashBoundary.size()) + 1); } return Math.min(maxResult, indexOf); } @Override // java.io.Closeable, java.lang.AutoCloseable public void close() throws IOException { if (this.closed) { return; } this.closed = true; this.currentPart = null; this.source.close(); } /* compiled from: MultipartReader.kt */ @Metadata(bv = {1, 0, 3}, d1 = {"\u0000\u001e\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0010\u0002\n\u0000\u0018\u00002\u00020\u0001B\u0015\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005¢\u0006\u0002\u0010\u0006J\t\u0010\t\u001a\u00020\nH\u0096\u0001R\u0013\u0010\u0004\u001a\u00020\u00058\u0007¢\u0006\b\n\u0000\u001a\u0004\b\u0004\u0010\u0007R\u0013\u0010\u0002\u001a\u00020\u00038\u0007¢\u0006\b\n\u0000\u001a\u0004\b\u0002\u0010\b¨\u0006\u000b"}, d2 = {"Lokhttp3/MultipartReader$Part;", "Ljava/io/Closeable;", "headers", "Lokhttp3/Headers;", "body", "Lokio/BufferedSource;", "(Lokhttp3/Headers;Lokio/BufferedSource;)V", "()Lokio/BufferedSource;", "()Lokhttp3/Headers;", "close", "", "okhttp"}, k = 1, mv = {1, 4, 0}) /* loaded from: classes3.dex */ public static final class Part implements Closeable { private final BufferedSource body; private final Headers headers; /* renamed from: body, reason: from getter */ public final BufferedSource getBody() { return this.body; } @Override // java.io.Closeable, java.lang.AutoCloseable public void close() { this.body.close(); } /* renamed from: headers, reason: from getter */ public final Headers getHeaders() { return this.headers; } public Part(Headers headers, BufferedSource body) { Intrinsics.checkNotNullParameter(headers, "headers"); Intrinsics.checkNotNullParameter(body, "body"); this.headers = headers; this.body = body; } } /* compiled from: MultipartReader.kt */ @Metadata(bv = {1, 0, 3}, d1 = {"\u0000\u0014\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\b\u0080\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002R\u0011\u0010\u0003\u001a\u00020\u0004¢\u0006\b\n\u0000\u001a\u0004\b\u0005\u0010\u0006¨\u0006\u0007"}, d2 = {"Lokhttp3/MultipartReader$Companion;", "", "()V", "afterBoundaryOptions", "Lokio/Options;", "getAfterBoundaryOptions", "()Lokio/Options;", "okhttp"}, k = 1, mv = {1, 4, 0}) /* loaded from: classes3.dex */ public static final class Companion { private Companion() { } public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } public final Options getAfterBoundaryOptions() { return MultipartReader.afterBoundaryOptions; } } }