package defpackage;

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

/* JADX INFO: renamed from: ˁˈᵸ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public abstract class AbstractC0692 {

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final C0094 f3140;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public int f3141;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public byte[] f3142;

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public int f3143;

    static {
        AbstractC2626.m6386(AbstractC0692.class);
    }

    public AbstractC0692() {
        this(new byte[m2467(256)], false, C0094.f1323);
    }

    public AbstractC0692(byte[] bArr, boolean z, C0094 c0094) {
        this.f3142 = bArr;
        this.f3140 = c0094;
        this.f3141 = 0;
        this.f3143 = z ? bArr.length : 0;
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public static int m2467(int i) {
        int i2 = 1;
        while (i2 < i) {
            i2 <<= 1;
            if (i2 <= 0) {
                ᵕᵩʽᵲ.ᵮᵣᵗˈ(AbstractC0793.m2876(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.f3141);
        sb.append(", wpos=");
        sb.append(this.f3143);
        sb.append(", size=");
        return AbstractC3589.m8110(sb, this.f3142.length, "]");
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final byte[] m2468() {
        int iM2476 = m2476();
        if (iM2476 <= 0) {
            return new byte[0];
        }
        byte[] bArr = new byte[iM2476];
        System.arraycopy(this.f3142, this.f3141, bArr, 0, iM2476);
        return bArr;
    }

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public final void m2469(long j) {
        switch (this.f3140.f1325) {
            case 0:
                if (j >= 0 && j <= 4294967295L) {
                    mo2472(4, new byte[]{(byte) (j >> 24), (byte) (j >> 16), (byte) (j >> 8), (byte) j});
                } else {
                    ᵕᵩʽᵲ.ᵮᵣᵗˈ(AbstractC0659.m2417(j, "Invalid uint32 value: "));
                }
                break;
            default:
                if (j >= 0 && j <= 4294967295L) {
                    mo2472(4, new byte[]{(byte) j, (byte) (j >> 8), (byte) (j >> 16), (byte) (j >> 24)});
                } else {
                    ᵕᵩʽᵲ.ᵮᵣᵗˈ(AbstractC0659.m2417(j, "Invalid uint32 value: "));
                }
                break;
        }
    }

    /* JADX INFO: renamed from: ˋˈ, reason: contains not printable characters */
    public final int m2470() {
        return (int) this.f3140.m1157(this);
    }

    /* JADX INFO: renamed from: ᵝᵶ, reason: contains not printable characters */
    public final void m2471() {
        this.f3140.m1155(this);
    }

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public AbstractC0692 mo2472(int i, byte[] bArr) {
        int length = this.f3142.length;
        int i2 = this.f3143;
        if (length - i2 < i) {
            byte[] bArr2 = new byte[m2467(i2 + i)];
            byte[] bArr3 = this.f3142;
            System.arraycopy(bArr3, 0, bArr2, 0, bArr3.length);
            this.f3142 = bArr2;
        }
        System.arraycopy(bArr, 0, this.f3142, this.f3143, i);
        this.f3143 += i;
        return this;
    }

    /* JADX INFO: renamed from: ᵪᵹᵥᵻ, reason: contains not printable characters */
    public final void m2473(int i) throws Buffer$BufferException {
        if (m2476() < i) {
            throw new Buffer$BufferException("Underflow");
        }
        this.f3141 += i;
    }

    /* JADX INFO: renamed from: ᵮᵣᵗˈ, reason: contains not printable characters */
    public final String m2474(int i, Charset charset) throws Buffer$BufferException {
        String strName = charset.name();
        strName.getClass();
        switch (strName) {
            case "UTF-16":
                switch (this.f3140.f1325) {
                    case 0:
                        return C0094.m1154(this, i, AbstractC4722.f17964);
                    default:
                        return C0094.m1154(this, i, AbstractC4722.f17965);
                }
            case "UTF-8":
                byte[] bArr = new byte[i];
                m2475(i, bArr);
                return new String(bArr, charset);
            case "UTF-16BE":
                return C0094.m1154(this, i, AbstractC4722.f17964);
            case "UTF-16LE":
                return C0094.m1154(this, i, AbstractC4722.f17965);
            default:
                throw new UnsupportedCharsetException(charset.name());
        }
    }

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public final void m2475(int i, byte[] bArr) throws Buffer$BufferException {
        if (m2476() < i) {
            throw new Buffer$BufferException("Underflow");
        }
        System.arraycopy(this.f3142, this.f3141, bArr, 0, i);
        this.f3141 += i;
    }

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final int m2476() {
        return this.f3143 - this.f3141;
    }

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public final void m2477(int i) {
        this.f3140.m1159(this, i);
    }

    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public final byte[] m2478(int i) throws Buffer$BufferException {
        byte[] bArr = new byte[i];
        m2475(i, bArr);
        return bArr;
    }

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public AbstractC0692 mo2479(byte b) {
        int length = this.f3142.length;
        int i = this.f3143;
        if (length - i < 1) {
            byte[] bArr = new byte[m2467(i + 1)];
            byte[] bArr2 = this.f3142;
            System.arraycopy(bArr2, 0, bArr, 0, bArr2.length);
            this.f3142 = bArr;
        }
        byte[] bArr3 = this.f3142;
        int i2 = this.f3143;
        this.f3143 = i2 + 1;
        bArr3[i2] = b;
        return this;
    }

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public final byte m2480() throws Buffer$BufferException {
        if (m2476() < 1) {
            throw new Buffer$BufferException("Underflow");
        }
        byte[] bArr = this.f3142;
        int i = this.f3141;
        this.f3141 = i + 1;
        return bArr[i];
    }

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public final void m2481(String str, Charset charset) {
        String strName = charset.name();
        strName.getClass();
        switch (strName) {
            case "UTF-16":
                this.f3140.m1161(this, str);
                return;
            case "UTF-8":
                byte[] bytes = str.getBytes(charset);
                mo2472(bytes.length, bytes);
                return;
            case "UTF-16BE":
                C0094.f1324.m1161(this, str);
                return;
            case "UTF-16LE":
                C0094.f1323.m1161(this, str);
                return;
            default:
                throw new UnsupportedCharsetException(charset.name());
        }
    }
}
