package Nm6q_10;

import java.nio.ByteBuffer;
/* compiled from: RealBufferedSink.kt */
/* loaded from: classes.dex */
public final class NQvZgp_17 implements IFxWkV_5 {
    public final H5YG8fq_22 KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final X6FRs_4 f342KQgRr5e_0;
    public boolean QxJ9d_1;

    public NQvZgp_17(H5YG8fq_22 h5YG8fq_22) {
        FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.QxJ9d_1(h5YG8fq_22, "sink");
        this.KQgRr5e_0 = h5YG8fq_22;
        this.f342KQgRr5e_0 = new X6FRs_4();
    }

    @Override // Nm6q_10.H5YG8fq_22
    public void KQgRr5e_0(X6FRs_4 x6FRs_4, long j) {
        FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.QxJ9d_1(x6FRs_4, "source");
        if (!this.QxJ9d_1) {
            this.f342KQgRr5e_0.KQgRr5e_0(x6FRs_4, j);
            KQgRr5e_0();
            return;
        }
        throw new IllegalStateException("closed".toString());
    }

    @Override // Nm6q_10.IFxWkV_5
    public IFxWkV_5 PGPF6hQ_2(int i) {
        if (!this.QxJ9d_1) {
            this.f342KQgRr5e_0.QxJ9d_1(i);
            return KQgRr5e_0();
        }
        throw new IllegalStateException("closed".toString());
    }

    @Override // Nm6q_10.IFxWkV_5
    public X6FRs_4 QxJ9d_1() {
        return this.f342KQgRr5e_0;
    }

    @Override // Nm6q_10.H5YG8fq_22, java.io.Closeable, java.lang.AutoCloseable
    public void close() {
        if (this.QxJ9d_1) {
            return;
        }
        Throwable th = null;
        try {
            if (this.f342KQgRr5e_0.PGPF6hQ_2() > 0) {
                this.KQgRr5e_0.KQgRr5e_0(this.f342KQgRr5e_0, this.f342KQgRr5e_0.PGPF6hQ_2());
            }
        } catch (Throwable th2) {
            th = th2;
        }
        try {
            this.KQgRr5e_0.close();
        } catch (Throwable th3) {
            if (th == null) {
                th = th3;
            }
        }
        this.QxJ9d_1 = true;
        if (th != null) {
            throw th;
        }
    }

    @Override // Nm6q_10.IFxWkV_5, Nm6q_10.H5YG8fq_22, java.io.Flushable
    public void flush() {
        if (!this.QxJ9d_1) {
            if (this.f342KQgRr5e_0.PGPF6hQ_2() > 0) {
                H5YG8fq_22 h5YG8fq_22 = this.KQgRr5e_0;
                X6FRs_4 x6FRs_4 = this.f342KQgRr5e_0;
                h5YG8fq_22.KQgRr5e_0(x6FRs_4, x6FRs_4.PGPF6hQ_2());
            }
            this.KQgRr5e_0.flush();
            return;
        }
        throw new IllegalStateException("closed".toString());
    }

    @Override // java.nio.channels.Channel
    public boolean isOpen() {
        return !this.QxJ9d_1;
    }

    public String toString() {
        return "buffer(" + this.KQgRr5e_0 + ')';
    }

    @Override // java.nio.channels.WritableByteChannel
    public int write(ByteBuffer byteBuffer) {
        FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.QxJ9d_1(byteBuffer, "source");
        if (!this.QxJ9d_1) {
            int write = this.f342KQgRr5e_0.write(byteBuffer);
            KQgRr5e_0();
            return write;
        }
        throw new IllegalStateException("closed".toString());
    }

    @Override // Nm6q_10.IFxWkV_5
    public IFxWkV_5 QxJ9d_1(int i) {
        if (!this.QxJ9d_1) {
            this.f342KQgRr5e_0.KQgRr5e_0(i);
            return KQgRr5e_0();
        }
        throw new IllegalStateException("closed".toString());
    }

    @Override // Nm6q_10.IFxWkV_5
    public IFxWkV_5 KQgRr5e_0(String str) {
        FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.QxJ9d_1(str, "string");
        if (!this.QxJ9d_1) {
            this.f342KQgRr5e_0.KQgRr5e_0(str);
            KQgRr5e_0();
            return this;
        }
        throw new IllegalStateException("closed".toString());
    }

    @Override // Nm6q_10.IFxWkV_5
    public IFxWkV_5 KQgRr5e_0(byte[] bArr) {
        FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.QxJ9d_1(bArr, "source");
        if (!this.QxJ9d_1) {
            this.f342KQgRr5e_0.KQgRr5e_0(bArr);
            KQgRr5e_0();
            return this;
        }
        throw new IllegalStateException("closed".toString());
    }

    @Override // Nm6q_10.IFxWkV_5
    public IFxWkV_5 KQgRr5e_0(byte[] bArr, int i, int i2) {
        FSaI4_7.Xgtqvk_8.QxJ9d_1.IFxWkV_5.QxJ9d_1(bArr, "source");
        if (!this.QxJ9d_1) {
            this.f342KQgRr5e_0.KQgRr5e_0(bArr, i, i2);
            KQgRr5e_0();
            return this;
        }
        throw new IllegalStateException("closed".toString());
    }

    @Override // Nm6q_10.IFxWkV_5
    public IFxWkV_5 KQgRr5e_0(int i) {
        if (!this.QxJ9d_1) {
            this.f342KQgRr5e_0.PGPF6hQ_2(i);
            KQgRr5e_0();
            return this;
        }
        throw new IllegalStateException("closed".toString());
    }

    @Override // Nm6q_10.IFxWkV_5
    public IFxWkV_5 KQgRr5e_0(long j) {
        if (!this.QxJ9d_1) {
            this.f342KQgRr5e_0.KQgRr5e_0(j);
            return KQgRr5e_0();
        }
        throw new IllegalStateException("closed".toString());
    }

    @Override // Nm6q_10.IFxWkV_5, Nm6q_10.H5YG8fq_22
    public IFxWkV_5 KQgRr5e_0() {
        if (!this.QxJ9d_1) {
            long QxJ9d_1 = this.f342KQgRr5e_0.QxJ9d_1();
            if (QxJ9d_1 > 0) {
                this.KQgRr5e_0.KQgRr5e_0(this.f342KQgRr5e_0, QxJ9d_1);
            }
            return this;
        }
        throw new IllegalStateException("closed".toString());
    }

    @Override // Nm6q_10.IFxWkV_5, Nm6q_10.H5YG8fq_22
    public KVtv3R_25 KQgRr5e_0() {
        return this.KQgRr5e_0.KQgRr5e_0();
    }
}
