package ඓ.ῲ.K.ᕣ.㿎;

import com.facebook.internal.NativeProtocol;
import java.io.IOException;
import java.io.OutputStream;
import ඓ.ῲ.K.ᕣ.ᨨ.ゎ.AbstractC0967;
import ඓ.ῲ.K.ᕣ.ᨨ.ゎ.C0964;

/* renamed from: ඓ.ῲ.K.ᕣ.㿎.ʬ  reason: contains not printable characters */
/* compiled from: BufferedOutputStream */
public final class C1122 extends OutputStream {

    /* renamed from: ʬ  reason: contains not printable characters */
    public byte[] f4587;

    /* renamed from: ඓ  reason: contains not printable characters */
    public int f4588;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final OutputStream f4589;

    /* renamed from: 㸾  reason: contains not printable characters */
    public AbstractC0967 f4590;

    public C1122(OutputStream outputStream, AbstractC0967 r3) {
        this.f4589 = outputStream;
        this.f4590 = r3;
        this.f4587 = (byte[]) ((C0964) r3).m2735(NativeProtocol.MESSAGE_GET_ACCESS_TOKEN_REQUEST, byte[].class);
    }

    /* JADX INFO: finally extract failed */
    @Override // java.io.OutputStream, java.io.Closeable, java.lang.AutoCloseable
    public void close() throws IOException {
        try {
            flush();
            this.f4589.close();
            byte[] bArr = this.f4587;
            if (bArr != null) {
                ((C0964) this.f4590).m2743(bArr);
                this.f4587 = null;
            }
        } catch (Throwable th) {
            this.f4589.close();
            throw th;
        }
    }

    @Override // java.io.OutputStream, java.io.Flushable
    public void flush() throws IOException {
        int i = this.f4588;
        if (i > 0) {
            this.f4589.write(this.f4587, 0, i);
            this.f4588 = 0;
        }
        this.f4589.flush();
    }

    @Override // java.io.OutputStream
    public void write(int i) throws IOException {
        byte[] bArr = this.f4587;
        int i2 = this.f4588;
        this.f4588 = i2 + 1;
        bArr[i2] = (byte) i;
        m3006();
    }

    /* renamed from: ᨨ  reason: contains not printable characters */
    public final void m3006() throws IOException {
        int i = this.f4588;
        byte[] bArr = this.f4587;
        if (i == bArr.length && i > 0) {
            this.f4589.write(bArr, 0, i);
            this.f4588 = 0;
        }
    }

    @Override // java.io.OutputStream
    public void write(byte[] bArr) throws IOException {
        write(bArr, 0, bArr.length);
    }

    @Override // java.io.OutputStream
    public void write(byte[] bArr, int i, int i2) throws IOException {
        int i3 = 0;
        do {
            int i4 = i2 - i3;
            int i5 = i + i3;
            if (this.f4588 != 0 || i4 < this.f4587.length) {
                int min = Math.min(i4, this.f4587.length - this.f4588);
                System.arraycopy(bArr, i5, this.f4587, this.f4588, min);
                this.f4588 += min;
                i3 += min;
                m3006();
            } else {
                this.f4589.write(bArr, i5, i4);
                return;
            }
        } while (i3 < i2);
    }
}
