package okhttp3.internal.cache;

import c.q.c.b;
import d.f;
import d.j;
import d.y;
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 b<IOException, c.j> 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(y yVar, b<? super IOException, c.j> bVar) {
        super(yVar);
        c.q.d.j.c(yVar, "delegate");
        c.q.d.j.c(bVar, "onException");
        this.onException = bVar;
    }

    @Override // d.j, d.y, java.io.Closeable, java.lang.AutoCloseable
    public void close() {
        if (this.hasErrors) {
            return;
        }
        try {
            super.close();
        } catch (IOException e2) {
            this.hasErrors = true;
            this.onException.invoke(e2);
        }
    }

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

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