package okhttp3.internal.cache;

import androidx.media3.container.NalUnitUtil;
import defpackage.cr4;
import defpackage.e6a;
import defpackage.kp6;
import defpackage.lg0;
import defpackage.mv8;
import defpackage.ok3;
import defpackage.sq3;
import java.io.IOException;
import kotlin.Metadata;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u00004\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0002\b\t\n\u0002\u0010\u000b\n\u0002\b\u0003\b\u0010\u0018\u00002\u00020\u0001B#\u0012\u0006\u0010\u0003\u001a\u00020\u0002\u0012\u0012\u0010\u0007\u001a\u000e\u0012\u0004\u0012\u00020\u0005\u0012\u0004\u0012\u00020\u00060\u0004¢\u0006\u0004\b\b\u0010\tJ\u001f\u0010\u000e\u001a\u00020\u00062\u0006\u0010\u000b\u001a\u00020\n2\u0006\u0010\r\u001a\u00020\fH\u0016¢\u0006\u0004\b\u000e\u0010\u000fJ\u000f\u0010\u0010\u001a\u00020\u0006H\u0016¢\u0006\u0004\b\u0010\u0010\u0011J\u000f\u0010\u0012\u001a\u00020\u0006H\u0016¢\u0006\u0004\b\u0012\u0010\u0011R#\u0010\u0007\u001a\u000e\u0012\u0004\u0012\u00020\u0005\u0012\u0004\u0012\u00020\u00060\u00048\u0006¢\u0006\f\n\u0004\b\u0007\u0010\u0013\u001a\u0004\b\u0014\u0010\u0015R\u0016\u0010\u0017\u001a\u00020\u00168\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b\u0017\u0010\u0018¨\u0006\u0019"}, d2 = {"Lokhttp3/internal/cache/FaultHidingSink;", "Lok3;", "Lmv8;", "delegate", "Lkotlin/Function1;", "Ljava/io/IOException;", "Le6a;", "onException", "<init>", "(Lmv8;Lsq3;)V", "Llg0;", "source", "", "byteCount", "write", "(Llg0;J)V", "flush", "()V", "close", "Lsq3;", "getOnException", "()Lsq3;", "", "hasErrors", "Z", "okhttp"}, k = 1, mv = {1, 8, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
public class FaultHidingSink extends ok3 {
    private boolean hasErrors;

    @kp6
    private final sq3<IOException, e6a> onException;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    /* JADX WARN: Multi-variable type inference failed */
    public FaultHidingSink(@kp6 mv8 mv8Var, @kp6 sq3<? super IOException, e6a> sq3Var) {
        super(mv8Var);
        cr4.g(mv8Var, "delegate");
        cr4.g(sq3Var, "onException");
        this.onException = sq3Var;
    }

    @Override // defpackage.ok3, defpackage.mv8, java.io.Closeable, java.lang.AutoCloseable
    public void close() {
        if (this.hasErrors) {
            return;
        }
        try {
            super.close();
        } catch (IOException e) {
            this.hasErrors = true;
            this.onException.invoke(e);
        }
    }

    @Override // defpackage.ok3, defpackage.mv8, java.io.Flushable
    public void flush() {
        if (this.hasErrors) {
            return;
        }
        try {
            super.flush();
        } catch (IOException e) {
            this.hasErrors = true;
            this.onException.invoke(e);
        }
    }

    @kp6
    public final sq3<IOException, e6a> getOnException() {
        return this.onException;
    }

    @Override // defpackage.ok3, defpackage.mv8
    public void write(@kp6 lg0 source, long byteCount) {
        cr4.g(source, "source");
        if (this.hasErrors) {
            source.skip(byteCount);
            return;
        }
        try {
            super.write(source, byteCount);
        } catch (IOException e) {
            this.hasErrors = true;
            this.onException.invoke(e);
        }
    }
}
