package p138.p176.p291.p296.p297.p305;

import java.io.ByteArrayInputStream;
import java.io.Flushable;
import java.io.IOException;
import java.io.OutputStream;

/* JADX INFO: renamed from: ދ.ހ.ށ.ބ.ށ.ތ.ހ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C5833 implements Flushable {

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final byte[] f16536;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final int f16537;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public int f16538 = 0;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public final OutputStream f16539;

    /* JADX INFO: renamed from: ދ.ހ.ށ.ބ.ށ.ތ.ހ$֏, reason: contains not printable characters */
    public static class C5834 extends IOException {
        public C5834() {
            super("CodedOutputStream was writing to a flat byte array and ran out of space.");
        }
    }

    public C5833(OutputStream outputStream, byte[] bArr) {
        this.f16539 = outputStream;
        this.f16536 = bArr;
        this.f16537 = bArr.length;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static C5833 m9149(OutputStream outputStream) {
        return new C5833(outputStream, new byte[4096]);
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public static int m9150(int i, long j) {
        return m9154(i) + (((-128) & j) == 0 ? 1 : ((-16384) & j) == 0 ? 2 : ((-2097152) & j) == 0 ? 3 : ((-268435456) & j) == 0 ? 4 : ((-34359738368L) & j) == 0 ? 5 : ((-4398046511104L) & j) == 0 ? 6 : ((-562949953421312L) & j) == 0 ? 7 : ((-72057594037927936L) & j) == 0 ? 8 : (j & Long.MIN_VALUE) == 0 ? 9 : 10);
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public static int m9151(int i, C5830 c5830) {
        return m9154(i) + m9153(c5830.f16530.length) + c5830.f16530.length;
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public static int m9152(int i, boolean z) {
        return m9154(i) + 1;
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public static int m9153(int i) {
        if ((i & (-128)) == 0) {
            return 1;
        }
        if ((i & (-16384)) == 0) {
            return 2;
        }
        if (((-2097152) & i) == 0) {
            return 3;
        }
        return (i & (-268435456)) == 0 ? 4 : 5;
    }

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public static int m9154(int i) {
        return m9153((i << 3) | 0);
    }

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public static int m9155(int i, int i2) {
        return m9154(i) + (i2 >= 0 ? m9153(i2) : 10);
    }

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public static int m9156(int i, int i2) {
        return m9154(i) + m9153(i2);
    }

    @Override // java.io.Flushable
    public void flush() throws IOException {
        if (this.f16539 != null) {
            m9157();
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m9157() throws IOException {
        OutputStream outputStream = this.f16539;
        if (outputStream == null) {
            throw new C5834();
        }
        outputStream.write(this.f16536, 0, this.f16538);
        this.f16538 = 0;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public void m9158(int i) throws IOException {
        byte b = (byte) i;
        if (this.f16538 == this.f16537) {
            m9157();
        }
        byte[] bArr = this.f16536;
        int i2 = this.f16538;
        this.f16538 = i2 + 1;
        bArr[i2] = b;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public void m9159(int i, int i2) throws IOException {
        m9164((i << 3) | 0);
        if (i2 >= 0) {
            m9164(i2);
        } else {
            m9163(i2);
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public void m9160(int i, long j) throws IOException {
        m9164((i << 3) | 0);
        m9163(j);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public void m9161(int i, C5830 c5830) throws IOException {
        m9164((i << 3) | 2);
        m9164(c5830.f16530.length);
        byte[] bArr = c5830.f16530;
        int length = bArr.length;
        int i2 = this.f16537;
        int i3 = this.f16538;
        int i4 = i2 - i3;
        if (i4 >= length) {
            System.arraycopy(bArr, 0, this.f16536, i3, length);
            this.f16538 += length;
            return;
        }
        System.arraycopy(bArr, 0, this.f16536, i3, i4);
        int i5 = i4 + 0;
        int i6 = length - i4;
        this.f16538 = this.f16537;
        m9157();
        if (i6 <= this.f16537) {
            System.arraycopy(c5830.f16530, i5, this.f16536, 0, i6);
            this.f16538 = i6;
            return;
        }
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(c5830.f16530);
        long j = i5;
        if (j != byteArrayInputStream.skip(j)) {
            throw new IllegalStateException("Skip failed.");
        }
        while (i6 > 0) {
            int iMin = Math.min(i6, this.f16537);
            int i7 = byteArrayInputStream.read(this.f16536, 0, iMin);
            if (i7 != iMin) {
                throw new IllegalStateException("Read failed.");
            }
            this.f16539.write(this.f16536, 0, i7);
            i6 -= i7;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public void m9162(int i, boolean z) throws IOException {
        m9164((i << 3) | 0);
        m9158(z ? 1 : 0);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public void m9163(long j) throws IOException {
        while (((-128) & j) != 0) {
            m9158((((int) j) & 127) | 128);
            j >>>= 7;
        }
        m9158((int) j);
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public void m9164(int i) throws IOException {
        while ((i & (-128)) != 0) {
            m9158((i & 127) | 128);
            i >>>= 7;
        }
        m9158(i);
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public void m9165(int i, int i2) throws IOException {
        m9164((i << 3) | i2);
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public void m9166(int i, int i2) throws IOException {
        m9164((i << 3) | 0);
        m9164(i2);
    }
}
