package p461;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import p138.p139.p143.p144.C2803;
import p402.InterfaceC6540;
import p402.p411.p413.C6635;

/* JADX INFO: renamed from: ޑ.ގ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
@InterfaceC6540
public final class C7119 implements InterfaceC7106 {

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final C7103 f20657;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public boolean f20658;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public final InterfaceC7127 f20659;

    /* JADX INFO: renamed from: ޑ.ގ$֏, reason: contains not printable characters */
    public static final class C7120 extends OutputStream {
        public C7120() {
        }

        @Override // java.io.OutputStream, java.io.Closeable, java.lang.AutoCloseable
        public void close() throws Throwable {
            C7119.this.close();
        }

        @Override // java.io.OutputStream, java.io.Flushable
        public void flush() {
            C7119 c7119 = C7119.this;
            if (c7119.f20658) {
                return;
            }
            c7119.flush();
        }

        public String toString() {
            return C7119.this + ".outputStream()";
        }

        @Override // java.io.OutputStream
        public void write(int i) throws IOException {
            C7119 c7119 = C7119.this;
            if (c7119.f20658) {
                throw new IOException("closed");
            }
            c7119.f20657.writeByte((int) ((byte) i));
            C7119.this.m10471();
        }

        @Override // java.io.OutputStream
        public void write(byte[] bArr, int i, int i2) throws IOException {
            if (bArr == null) {
                C6635.m9824("data");
                throw null;
            }
            C7119 c7119 = C7119.this;
            if (c7119.f20658) {
                throw new IOException("closed");
            }
            c7119.f20657.write(bArr, i, i2);
            C7119.this.m10471();
        }
    }

    public C7119(InterfaceC7127 interfaceC7127) {
        if (interfaceC7127 == null) {
            C6635.m9824("sink");
            throw null;
        }
        this.f20659 = interfaceC7127;
        this.f20657 = new C7103();
    }

    @Override // p461.InterfaceC7127, java.io.Closeable, java.lang.AutoCloseable
    public void close() throws Throwable {
        if (this.f20658) {
            return;
        }
        Throwable th = null;
        try {
            if (this.f20657.f20630 > 0) {
                this.f20659.mo10205(this.f20657, this.f20657.f20630);
            }
        } catch (Throwable th2) {
            th = th2;
        }
        try {
            this.f20659.close();
        } catch (Throwable th3) {
            if (th == null) {
                th = th3;
            }
        }
        this.f20658 = true;
        if (th != null) {
            throw th;
        }
    }

    @Override // p461.InterfaceC7106, p461.InterfaceC7127, java.io.Flushable
    public void flush() {
        if (!(!this.f20658)) {
            throw new IllegalStateException("closed".toString());
        }
        C7103 c7103 = this.f20657;
        long j = c7103.f20630;
        if (j > 0) {
            this.f20659.mo10205(c7103, j);
        }
        this.f20659.flush();
    }

    @Override // p461.InterfaceC7106
    public C7103 getBuffer() {
        return this.f20657;
    }

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

    public String toString() {
        StringBuilder sbM4889 = C2803.m4889("buffer(");
        sbM4889.append(this.f20659);
        sbM4889.append(')');
        return sbM4889.toString();
    }

    @Override // java.nio.channels.WritableByteChannel
    public int write(ByteBuffer byteBuffer) {
        if (byteBuffer == null) {
            C6635.m9824("source");
            throw null;
        }
        if (!(!this.f20658)) {
            throw new IllegalStateException("closed".toString());
        }
        int iWrite = this.f20657.write(byteBuffer);
        m10471();
        return iWrite;
    }

    @Override // p461.InterfaceC7106
    public InterfaceC7106 write(byte[] bArr) {
        if (bArr == null) {
            C6635.m9824("source");
            throw null;
        }
        if (!(!this.f20658)) {
            throw new IllegalStateException("closed".toString());
        }
        this.f20657.write(bArr);
        m10471();
        return this;
    }

    @Override // p461.InterfaceC7106
    public InterfaceC7106 write(byte[] bArr, int i, int i2) {
        if (bArr == null) {
            C6635.m9824("source");
            throw null;
        }
        if (!(!this.f20658)) {
            throw new IllegalStateException("closed".toString());
        }
        this.f20657.write(bArr, i, i2);
        m10471();
        return this;
    }

    @Override // p461.InterfaceC7106
    public InterfaceC7106 writeByte(int i) {
        if (!(!this.f20658)) {
            throw new IllegalStateException("closed".toString());
        }
        this.f20657.writeByte(i);
        return m10471();
    }

    @Override // p461.InterfaceC7106
    public InterfaceC7106 writeInt(int i) {
        if (!(!this.f20658)) {
            throw new IllegalStateException("closed".toString());
        }
        this.f20657.writeInt(i);
        return m10471();
    }

    @Override // p461.InterfaceC7106
    public InterfaceC7106 writeShort(int i) {
        if (!(!this.f20658)) {
            throw new IllegalStateException("closed".toString());
        }
        this.f20657.writeShort(i);
        m10471();
        return this;
    }

    @Override // p461.InterfaceC7106
    /* JADX INFO: renamed from: ֏ */
    public long mo10410(InterfaceC7129 interfaceC7129) {
        if (interfaceC7129 == null) {
            C6635.m9824("source");
            throw null;
        }
        long j = 0;
        while (true) {
            long jMo10207 = interfaceC7129.mo10207(this.f20657, 8192);
            if (jMo10207 == -1) {
                return j;
            }
            j += jMo10207;
            m10471();
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public InterfaceC7106 m10471() {
        if (!(!this.f20658)) {
            throw new IllegalStateException("closed".toString());
        }
        long jM10419 = this.f20657.m10419();
        if (jM10419 > 0) {
            this.f20659.mo10205(this.f20657, jM10419);
        }
        return this;
    }

    @Override // p461.InterfaceC7106
    /* JADX INFO: renamed from: ֏ */
    public InterfaceC7106 mo10414(String str) {
        if (str == null) {
            C6635.m9824("string");
            throw null;
        }
        if (!(!this.f20658)) {
            throw new IllegalStateException("closed".toString());
        }
        this.f20657.mo10414(str);
        m10471();
        return this;
    }

    @Override // p461.InterfaceC7106
    /* JADX INFO: renamed from: ֏ */
    public InterfaceC7106 mo10415(String str, int i, int i2) {
        if (str == null) {
            C6635.m9824("string");
            throw null;
        }
        if (!(!this.f20658)) {
            throw new IllegalStateException("closed".toString());
        }
        this.f20657.mo10415(str, i, i2);
        m10471();
        return this;
    }

    @Override // p461.InterfaceC7127
    /* JADX INFO: renamed from: ֏ */
    public void mo10205(C7103 c7103, long j) {
        if (c7103 == null) {
            C6635.m9824("source");
            throw null;
        }
        if (!(!this.f20658)) {
            throw new IllegalStateException("closed".toString());
        }
        this.f20657.mo10205(c7103, j);
        m10471();
    }

    @Override // p461.InterfaceC7106
    /* JADX INFO: renamed from: ؠ */
    public InterfaceC7106 mo10421(long j) {
        if (!(!this.f20658)) {
            throw new IllegalStateException("closed".toString());
        }
        this.f20657.mo10421(j);
        return m10471();
    }

    @Override // p461.InterfaceC7106
    /* JADX INFO: renamed from: ؠ */
    public InterfaceC7106 mo10422(C7108 c7108) {
        if (c7108 == null) {
            C6635.m9824("byteString");
            throw null;
        }
        if (!(!this.f20658)) {
            throw new IllegalStateException("closed".toString());
        }
        this.f20657.mo10422(c7108);
        m10471();
        return this;
    }

    @Override // p461.InterfaceC7127
    /* JADX INFO: renamed from: ށ */
    public C7130 mo10278() {
        return this.f20659.mo10278();
    }

    @Override // p461.InterfaceC7106
    /* JADX INFO: renamed from: ޅ */
    public InterfaceC7106 mo10432(long j) {
        if (!(!this.f20658)) {
            throw new IllegalStateException("closed".toString());
        }
        this.f20657.mo10432(j);
        m10471();
        return this;
    }

    @Override // p461.InterfaceC7106
    /* JADX INFO: renamed from: ގ */
    public OutputStream mo10439() {
        return new C7120();
    }
}
