package defpackage;

import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;

/* renamed from: ˏᵖ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C1860 extends OutputStream {

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public static final byte[] f7546 = new byte[0];

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public int f7547;

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public int f7548;

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public final ArrayList f7549 = new ArrayList();

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public byte[] f7550;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public int f7551;

    public C1860() {
        synchronized (this) {
            m5257(1024);
        }
    }

    @Override // java.io.OutputStream, java.io.Closeable, java.lang.AutoCloseable
    public final void close() {
    }

    public final String toString() {
        return new String(m5256(), Charset.defaultCharset());
    }

    @Override // java.io.OutputStream
    public final synchronized void write(int i) {
        try {
            int i2 = this.f7548;
            int i3 = i2 - this.f7551;
            if (i3 == this.f7550.length) {
                m5257(i2 + 1);
                i3 = 0;
            }
            this.f7550[i3] = (byte) i;
            this.f7548++;
        } catch (Throwable th) {
            throw th;
        }
    }

    @Override // java.io.OutputStream
    public final void write(byte[] bArr, int i, int i2) {
        int i3;
        if (i < 0 || i > bArr.length || i2 < 0 || (i3 = i + i2) > bArr.length || i3 < 0) {
            C0190.m1431();
            return;
        }
        if (i2 == 0) {
            return;
        }
        synchronized (this) {
            try {
                int i4 = this.f7548;
                int i5 = i4 + i2;
                int i6 = i4 - this.f7551;
                while (i2 > 0) {
                    int iMin = Math.min(i2, this.f7550.length - i6);
                    System.arraycopy(bArr, i3 - i2, this.f7550, i6, iMin);
                    i2 -= iMin;
                    if (i2 > 0) {
                        m5257(i5);
                        i6 = 0;
                    }
                }
                this.f7548 = i5;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final synchronized byte[] m5256() {
        int i = this.f7548;
        if (i == 0) {
            return f7546;
        }
        byte[] bArr = new byte[i];
        ArrayList arrayList = this.f7549;
        int size = arrayList.size();
        int i2 = 0;
        int i3 = 0;
        while (i3 < size) {
            Object obj = arrayList.get(i3);
            i3++;
            byte[] bArr2 = (byte[]) obj;
            int iMin = Math.min(bArr2.length, i);
            System.arraycopy(bArr2, 0, bArr, i2, iMin);
            i2 += iMin;
            i -= iMin;
            if (i == 0) {
                break;
            }
        }
        return bArr;
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final void m5257(int i) {
        int i2 = this.f7547;
        ArrayList arrayList = this.f7549;
        if (i2 < arrayList.size() - 1) {
            this.f7551 += this.f7550.length;
            int i3 = this.f7547 + 1;
            this.f7547 = i3;
            this.f7550 = (byte[]) arrayList.get(i3);
            return;
        }
        byte[] bArr = this.f7550;
        if (bArr == null) {
            this.f7551 = 0;
        } else {
            i = Math.max(bArr.length << 1, i - this.f7551);
            this.f7551 += this.f7550.length;
        }
        this.f7547++;
        byte[] bArr2 = new byte[i];
        this.f7550 = bArr2;
        arrayList.add(bArr2);
    }
}
