package defpackage;

import com.hierynomus.protocol.commons.buffer.Buffer$BufferException;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;

/* renamed from: ᵰᵰᵯᵾ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public abstract class AbstractC4362 {

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public int f16314;

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public byte[] f16315;

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final C3253 f16316;

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public int f16317;

    static {
        AbstractC1385.m4255(AbstractC4362.class);
    }

    public AbstractC4362() {
        this(new byte[m9336(256)], false, C3253.f12249);
    }

    public AbstractC4362(byte[] bArr, boolean z, C3253 c3253) {
        this.f16315 = bArr;
        this.f16316 = c3253;
        this.f16314 = 0;
        this.f16317 = z ? bArr.length : 0;
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public static int m9336(int i) {
        int i2 = 1;
        while (i2 < i) {
            i2 <<= 1;
            if (i2 <= 0) {
                ᵹˉᵞ.ˌᵜᵹᵩ(AbstractC3915.m8596(i, "Cannot get next power of 2; ", " is too large"));
                return 0;
            }
        }
        return i2;
    }

    public final String toString() {
        StringBuilder sb = new StringBuilder("Buffer [rpos=");
        sb.append(this.f16314);
        sb.append(", wpos=");
        sb.append(this.f16317);
        sb.append(", size=");
        return AbstractC4486.m9545(sb, this.f16315.length, "]");
    }

    /* renamed from: ˇʼʤˎ */
    public AbstractC4362 mo5106(int i, byte[] bArr) {
        int length = this.f16315.length;
        int i2 = this.f16317;
        if (length - i2 < i) {
            byte[] bArr2 = new byte[m9336(i2 + i)];
            byte[] bArr3 = this.f16315;
            System.arraycopy(bArr3, 0, bArr2, 0, bArr3.length);
            this.f16315 = bArr2;
        }
        System.arraycopy(bArr, 0, this.f16315, this.f16317, i);
        this.f16317 += i;
        return this;
    }

    /* renamed from: ˌᵜᵹᵩ, reason: contains not printable characters */
    public final String m9337(int i, Charset charset) throws Buffer$BufferException {
        String strName = charset.name();
        strName.getClass();
        switch (strName) {
            case "UTF-16":
                switch (this.f16316.f12252) {
                    case 0:
                        return C3253.m7612(this, i, AbstractC5005.f18586);
                    default:
                        return C3253.m7612(this, i, AbstractC5005.f18584);
                }
            case "UTF-8":
                byte[] bArr = new byte[i];
                m9346(i, bArr);
                return new String(bArr, charset);
            case "UTF-16BE":
                return C3253.m7612(this, i, AbstractC5005.f18586);
            case "UTF-16LE":
                return C3253.m7612(this, i, AbstractC5005.f18584);
            default:
                throw new UnsupportedCharsetException(charset.name());
        }
    }

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public final void m9338(int i) {
        this.f16316.m7613(this, i);
    }

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public final void m9339(String str, Charset charset) {
        String strName = charset.name();
        strName.getClass();
        switch (strName) {
            case "UTF-16":
                this.f16316.m7616(this, str);
                return;
            case "UTF-8":
                byte[] bytes = str.getBytes(charset);
                mo5106(bytes.length, bytes);
                return;
            case "UTF-16BE":
                C3253.f12251.m7616(this, str);
                return;
            case "UTF-16LE":
                C3253.f12249.m7616(this, str);
                return;
            default:
                throw new UnsupportedCharsetException(charset.name());
        }
    }

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public final byte m9340() throws Buffer$BufferException {
        if (m9341() < 1) {
            throw new Buffer$BufferException("Underflow");
        }
        byte[] bArr = this.f16315;
        int i = this.f16314;
        this.f16314 = i + 1;
        return bArr[i];
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final int m9341() {
        return this.f16317 - this.f16314;
    }

    /* renamed from: ᵪʩ, reason: contains not printable characters */
    public final int m9342() {
        return (int) this.f16316.m7615(this);
    }

    /* renamed from: ᵯٴᵦ, reason: contains not printable characters */
    public final void m9343() {
        this.f16316.m7618(this);
    }

    /* renamed from: ᵳٴᵶ, reason: contains not printable characters */
    public final void m9344(int i) throws Buffer$BufferException {
        if (m9341() < i) {
            throw new Buffer$BufferException("Underflow");
        }
        this.f16314 += i;
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final byte[] m9345() {
        int iM9341 = m9341();
        if (iM9341 <= 0) {
            return new byte[0];
        }
        byte[] bArr = new byte[iM9341];
        System.arraycopy(this.f16315, this.f16314, bArr, 0, iM9341);
        return bArr;
    }

    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public final void m9346(int i, byte[] bArr) throws Buffer$BufferException {
        if (m9341() < i) {
            throw new Buffer$BufferException("Underflow");
        }
        System.arraycopy(this.f16315, this.f16314, bArr, 0, i);
        this.f16314 += i;
    }

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public final byte[] m9347(int i) throws Buffer$BufferException {
        byte[] bArr = new byte[i];
        m9346(i, bArr);
        return bArr;
    }

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public final void m9348(long j) {
        switch (this.f16316.f12252) {
            case 0:
                if (j >= 0 && j <= 4294967295L) {
                    mo5106(4, new byte[]{(byte) (j >> 24), (byte) (j >> 16), (byte) (j >> 8), (byte) j});
                    break;
                } else {
                    ᵹˉᵞ.ˌᵜᵹᵩ(AbstractC4737.m10015(j, "Invalid uint32 value: "));
                    break;
                }
                break;
            default:
                if (j >= 0 && j <= 4294967295L) {
                    mo5106(4, new byte[]{(byte) j, (byte) (j >> 8), (byte) (j >> 16), (byte) (j >> 24)});
                    break;
                } else {
                    ᵹˉᵞ.ˌᵜᵹᵩ(AbstractC4737.m10015(j, "Invalid uint32 value: "));
                    break;
                }
                break;
        }
    }

    /* renamed from: ᵻᵢﹳᵰ */
    public AbstractC4362 mo5107(byte b) {
        int length = this.f16315.length;
        int i = this.f16317;
        if (length - i < 1) {
            byte[] bArr = new byte[m9336(i + 1)];
            byte[] bArr2 = this.f16315;
            System.arraycopy(bArr2, 0, bArr, 0, bArr2.length);
            this.f16315 = bArr;
        }
        byte[] bArr3 = this.f16315;
        int i2 = this.f16317;
        this.f16317 = i2 + 1;
        bArr3[i2] = b;
        return this;
    }
}
