package okhttp3.internal.cache;

import g.a0;
import g.h0.b.l;
import j.d;
import j.j;
import j.z;
import java.io.EOFException;
import java.io.IOException;

/* JADX INFO: compiled from: FaultHidingSink.kt */
/* JADX INFO: loaded from: classes.dex */
public class FaultHidingSink extends j {
    private boolean hasErrors;
    private final l<IOException, a0> 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(z zVar, l<? super IOException, a0> lVar) {
        super(zVar);
        g.h0.c.l.f(zVar, "delegate");
        g.h0.c.l.f(lVar, "onException");
        this.onException = lVar;
    }

    @Override // j.j, j.z, 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 // j.j, j.z, 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<IOException, a0> getOnException() {
        return this.onException;
    }

    @Override // j.j, j.z
    public void write(d dVar, long j2) throws EOFException {
        g.h0.c.l.f(dVar, "source");
        if (this.hasErrors) {
            dVar.K(j2);
            return;
        }
        try {
            super.write(dVar, j2);
        } catch (IOException e2) {
            this.hasErrors = true;
            this.onException.invoke(e2);
        }
    }
}
