package p138.p145.p146.p151.p152;

import java.io.IOException;
import java.io.OutputStream;
import p138.p145.p146.p151.p154.p155.InterfaceC2940;

/* JADX INFO: renamed from: ދ.ؠ.֏.ތ.މ.ހ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C2855 extends OutputStream {

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

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public byte[] f8824;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public InterfaceC2940 f8825;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public int f8826;

    public C2855(OutputStream outputStream, InterfaceC2940 interfaceC2940) {
        this.f8823 = outputStream;
        this.f8825 = interfaceC2940;
        this.f8824 = (byte[]) interfaceC2940.mo5081(65536, byte[].class);
    }

    @Override // java.io.OutputStream, java.io.Closeable, java.lang.AutoCloseable
    public void close() throws IOException {
        try {
            flush();
            this.f8823.close();
            byte[] bArr = this.f8824;
            if (bArr != null) {
                this.f8825.mo5080(bArr);
                this.f8824 = null;
            }
        } catch (Throwable th) {
            this.f8823.close();
            throw th;
        }
    }

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

    @Override // java.io.OutputStream
    public void write(int i) throws IOException {
        byte[] bArr = this.f8824;
        int i2 = this.f8826;
        int i3 = i2 + 1;
        this.f8826 = i3;
        bArr[i2] = (byte) i;
        if (i3 != bArr.length || i3 <= 0) {
            return;
        }
        this.f8823.write(bArr, 0, i3);
        this.f8826 = 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.f8826 == 0 && i4 >= this.f8824.length) {
                this.f8823.write(bArr, i5, i4);
                return;
            }
            int iMin = Math.min(i4, this.f8824.length - this.f8826);
            System.arraycopy(bArr, i5, this.f8824, this.f8826, iMin);
            int i6 = this.f8826 + iMin;
            this.f8826 = i6;
            i3 += iMin;
            byte[] bArr2 = this.f8824;
            if (i6 == bArr2.length && i6 > 0) {
                this.f8823.write(bArr2, 0, i6);
                this.f8826 = 0;
            }
        } while (i3 < i2);
    }
}
