package ᨨ;

import android.support.v4.media.session.PlaybackStateCompat;
import java.io.IOException;
import java.nio.ByteBuffer;
import okio.ByteString;
import ඓ.K.K.K.C1293;

/* renamed from: ᨨ.ᓣ  reason: contains not printable characters */
/* compiled from: RealBufferedSink */
public final class C1479 implements AbstractC1483 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public final AbstractC1473 f5506;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final C1492 f5507 = new C1492();

    /* renamed from: 㸾  reason: contains not printable characters */
    public boolean f5508;

    public C1479(AbstractC1473 r2) {
        if (r2 != null) {
            this.f5506 = r2;
            return;
        }
        throw new NullPointerException("sink == null");
    }

    @Override // ᨨ.AbstractC1473, java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.Channel
    public void close() throws IOException {
        Throwable th;
        if (!this.f5508) {
            try {
                if (this.f5507.f5529 > 0) {
                    this.f5506.m3692(this.f5507, this.f5507.f5529);
                }
                th = null;
            } catch (Throwable th2) {
                th = th2;
            }
            try {
                this.f5506.close();
            } catch (Throwable th3) {
                if (th == null) {
                    th = th3;
                }
            }
            this.f5508 = true;
            if (th != null) {
                C1491.m3765(th);
                throw null;
            }
        }
    }

    @Override // ᨨ.AbstractC1473, ᨨ.AbstractC1483, java.io.Flushable
    public void flush() throws IOException {
        if (!this.f5508) {
            C1492 r0 = this.f5507;
            long j = r0.f5529;
            if (j > 0) {
                this.f5506.m3692(r0, j);
            }
            this.f5506.flush();
            return;
        }
        throw new IllegalStateException("closed");
    }

    public boolean isOpen() {
        return !this.f5508;
    }

    @Override // ᨨ.AbstractC1473
    public C1477 timeout() {
        return this.f5506.timeout();
    }

    public String toString() {
        StringBuilder r0 = C1293.m3416("buffer(");
        r0.append(this.f5506);
        r0.append(")");
        return r0.toString();
    }

    @Override // ᨨ.AbstractC1483
    public AbstractC1483 write(byte[] bArr) throws IOException {
        if (!this.f5508) {
            this.f5507.write(bArr);
            m3711();
            return this;
        }
        throw new IllegalStateException("closed");
    }

    @Override // ᨨ.AbstractC1483
    public AbstractC1483 writeByte(int i) throws IOException {
        if (!this.f5508) {
            this.f5507.writeByte(i);
            return m3711();
        }
        throw new IllegalStateException("closed");
    }

    @Override // ᨨ.AbstractC1483
    public AbstractC1483 writeInt(int i) throws IOException {
        if (!this.f5508) {
            this.f5507.writeInt(i);
            return m3711();
        }
        throw new IllegalStateException("closed");
    }

    @Override // ᨨ.AbstractC1483
    public AbstractC1483 writeShort(int i) throws IOException {
        if (!this.f5508) {
            this.f5507.writeShort(i);
            m3711();
            return this;
        }
        throw new IllegalStateException("closed");
    }

    @Override // ᨨ.AbstractC1483
    /* renamed from: ඓ  reason: contains not printable characters */
    public AbstractC1483 m3710(long j) throws IOException {
        if (!this.f5508) {
            this.f5507.m3771(j);
            m3711();
            return this;
        }
        throw new IllegalStateException("closed");
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public AbstractC1483 m3711() throws IOException {
        if (!this.f5508) {
            long r0 = this.f5507.m3801();
            if (r0 > 0) {
                this.f5506.m3692(this.f5507, r0);
            }
            return this;
        }
        throw new IllegalStateException("closed");
    }

    @Override // ᨨ.AbstractC1483
    /* renamed from: K  reason: contains not printable characters */
    public C1492 m3716() {
        return this.f5507;
    }

    @Override // ᨨ.AbstractC1473
    /* renamed from: K  reason: contains not printable characters */
    public void m3717(C1492 r2, long j) throws IOException {
        if (!this.f5508) {
            this.f5507.m3797(r2, j);
            m3711();
            return;
        }
        throw new IllegalStateException("closed");
    }

    @Override // ᨨ.AbstractC1483
    public AbstractC1483 write(byte[] bArr, int i, int i2) throws IOException {
        if (!this.f5508) {
            this.f5507.write(bArr, i, i2);
            m3711();
            return this;
        }
        throw new IllegalStateException("closed");
    }

    @Override // ᨨ.AbstractC1483
    /* renamed from: K  reason: contains not printable characters */
    public AbstractC1483 m3715(ByteString byteString) throws IOException {
        if (!this.f5508) {
            this.f5507.m3795(byteString);
            m3711();
            return this;
        }
        throw new IllegalStateException("closed");
    }

    @Override // java.nio.channels.WritableByteChannel
    public int write(ByteBuffer byteBuffer) throws IOException {
        if (!this.f5508) {
            int write = this.f5507.write(byteBuffer);
            m3711();
            return write;
        }
        throw new IllegalStateException("closed");
    }

    @Override // ᨨ.AbstractC1483
    /* renamed from: K  reason: contains not printable characters */
    public AbstractC1483 m3714(String str) throws IOException {
        if (!this.f5508) {
            this.f5507.m3792(str);
            return m3711();
        }
        throw new IllegalStateException("closed");
    }

    @Override // ᨨ.AbstractC1483
    /* renamed from: K  reason: contains not printable characters */
    public long m3712(AbstractC1494 r8) throws IOException {
        if (r8 != null) {
            long j = 0;
            while (true) {
                long read = r8.read(this.f5507, PlaybackStateCompat.ACTION_PLAY_FROM_URI);
                if (read == -1) {
                    return j;
                }
                j += read;
                m3711();
            }
        } else {
            throw new IllegalArgumentException("source == null");
        }
    }

    @Override // ᨨ.AbstractC1483
    /* renamed from: K  reason: contains not printable characters */
    public AbstractC1483 m3713(long j) throws IOException {
        if (!this.f5508) {
            this.f5507.m3791(j);
            return m3711();
        }
        throw new IllegalStateException("closed");
    }
}
