package okhttp3.internal.cache;

import java.io.EOFException;
import java.io.IOException;
import okio.C;
import okio.C0688f;
import okio.k;
import y1.l;

/* JADX INFO: loaded from: classes2.dex */
public class FaultHidingSink extends k {
    private boolean hasErrors;
    private final l onException;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public FaultHidingSink(C delegate, l onException) {
        super(delegate);
        kotlin.jvm.internal.l.e(delegate, "delegate");
        kotlin.jvm.internal.l.e(onException, "onException");
        this.onException = onException;
    }

    @Override // okio.k, okio.C, java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.Channel
    public void close() {
        if (this.hasErrors) {
            return;
        }
        try {
            super.close();
        } catch (IOException e2) {
            this.hasErrors = true;
            this.onException.invoke(e2);
        }
    }

    @Override // okio.k, okio.C, java.io.Flushable
    public void flush() {
        if (this.hasErrors) {
            return;
        }
        try {
            super.flush();
        } catch (IOException e2) {
            this.hasErrors = true;
            this.onException.invoke(e2);
        }
    }

    public final l getOnException() {
        return this.onException;
    }

    @Override // okio.k, okio.C
    public void write(C0688f source, long j2) throws EOFException {
        kotlin.jvm.internal.l.e(source, "source");
        if (this.hasErrors) {
            source.skip(j2);
            return;
        }
        try {
            super.write(source, j2);
        } catch (IOException e2) {
            this.hasErrors = true;
            this.onException.invoke(e2);
        }
    }
}
