package okio.internal;

/* JADX INFO: compiled from: r8-map-id-ae6aab8d9a1033945587ffdd1bc6222159522c1d66e66a2c4cecb065134dd0a6 */
/* JADX INFO: loaded from: E:\ios\vf_dex\classes3.dex */
@kotlin.Metadata(d1 = {"\u0000*\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0000\n\u0002\u0010\u000b\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0002\b\f\b\u0000\u0018\u00002\u00020\u0001B\u001f\u0012\u0006\u0010\u0003\u001a\u00020\u0002\u0012\u0006\u0010\u0005\u001a\u00020\u0004\u0012\u0006\u0010\u0007\u001a\u00020\u0006¢\u0006\u0004\b\b\u0010\tJ\u001b\u0010\r\u001a\u00020\f*\u00020\n2\u0006\u0010\u000b\u001a\u00020\u0004H\u0002¢\u0006\u0004\b\r\u0010\u000eJ\u001f\u0010\u0011\u001a\u00020\u00042\u0006\u0010\u000f\u001a\u00020\n2\u0006\u0010\u0010\u001a\u00020\u0004H\u0016¢\u0006\u0004\b\u0011\u0010\u0012R\u0014\u0010\u0005\u001a\u00020\u00048\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\r\u0010\u0013R\u0014\u0010\u0007\u001a\u00020\u00068\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\u0014\u0010\u0015R\u0016\u0010\u0017\u001a\u00020\u00048\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b\u0016\u0010\u0013¨\u0006\u0018"}, d2 = {"Lokio/internal/FixedLengthSource;", "Lokio/ForwardingSource;", "Lokio/Source;", "delegate", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "size", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "truncate", "<init>", "(Lokio/Source;JZ)V", "Lokio/Buffer;", "newSize", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "a", "(Lokio/Buffer;J)V", "sink", "byteCount", "read", "(Lokio/Buffer;J)J", "J", "b", "Z", "c", "bytesReceived", "okio"}, k = 1, mv = {1, 9, 0}, xi = 48)
public final class FixedLengthSource extends okio.ForwardingSource {

    /* JADX INFO: renamed from: a, reason: from kotlin metadata */
    private final long size;

    /* JADX INFO: renamed from: b, reason: from kotlin metadata */
    private final boolean truncate;

    /* JADX INFO: renamed from: c, reason: from kotlin metadata */
    private long bytesReceived;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public FixedLengthSource(okio.Source source, long j, boolean z) {
        super(source);
        kotlin.jvm.internal.Intrinsics.l(source, "delegate");
        this.size = j;
        this.truncate = z;
    }

    private final void a(okio.Buffer buffer, long j) throws java.io.EOFException {
        okio.Buffer buffer2 = new okio.Buffer();
        buffer2.L1(buffer);
        buffer.write(buffer2, j);
        buffer2.clear();
    }

    @Override // okio.ForwardingSource, okio.Source
    public long read(okio.Buffer sink, long byteCount) throws java.io.IOException {
        kotlin.jvm.internal.Intrinsics.l(sink, "sink");
        long j = this.bytesReceived;
        long j2 = this.size;
        if (j > j2) {
            byteCount = 0;
        } else if (this.truncate) {
            long j5 = j2 - j;
            if (j5 == 0) {
                return -1L;
            }
            byteCount = java.lang.Math.min(byteCount, j5);
        }
        long j6 = super.read(sink, byteCount);
        if (j6 != -1) {
            this.bytesReceived += j6;
        }
        long j7 = this.bytesReceived;
        long j8 = this.size;
        if ((j7 >= j8 || j6 != -1) && j7 <= j8) {
            return j6;
        }
        if (j6 > 0 && j7 > j8) {
            a(sink, sink.getSize() - (this.bytesReceived - this.size));
        }
        throw new java.io.IOException("expected " + this.size + " bytes but got " + this.bytesReceived);
    }
}
