package defpackage;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import net.lingala.zip4j.exception.ZipException;

/* renamed from: ᵮᵢˉᵥ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C4218 extends OutputStream implements InterfaceC1721 {

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public final C1601 f15806;

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public final long f15807;

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

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public RandomAccessFile f15809;

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public int f15810;

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

    public C4218(File file) {
        this(file, -1L);
    }

    public C4218(File file, long j) throws ZipException {
        this.f15806 = new C1601(3);
        if (j >= 0 && j < 65536) {
            C0190.m1425("split length less than minimum allowed split length of 65536 Bytes");
            throw null;
        }
        this.f15809 = new RandomAccessFile(file, "rw");
        this.f15807 = j;
        this.f15811 = file;
        this.f15810 = 0;
        this.f15808 = 0L;
    }

    @Override // java.io.OutputStream, java.io.Closeable, java.lang.AutoCloseable
    public final void close() throws IOException {
        this.f15809.close();
    }

    @Override // java.io.OutputStream
    public final void write(int i) throws IOException {
        write(new byte[]{(byte) i}, 0, 1);
    }

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

    @Override // java.io.OutputStream
    public final void write(byte[] bArr, int i, int i2) throws IOException {
        if (i2 <= 0) {
            return;
        }
        long j = this.f15807;
        if (j == -1) {
            this.f15809.write(bArr, i, i2);
            this.f15808 += i2;
            return;
        }
        long j2 = this.f15808;
        if (j2 >= j) {
            m9170();
            this.f15809.write(bArr, i, i2);
            this.f15808 = i2;
            return;
        }
        long j3 = i2;
        if (j2 + j3 <= j) {
            this.f15809.write(bArr, i, i2);
            this.f15808 += j3;
            return;
        }
        this.f15806.getClass();
        int iM4580 = C1601.m4580(0, bArr);
        for (int i3 : AbstractC1327.m4098(12)) {
            if (i3 != 8 && AbstractC3915.m8578(i3) == iM4580) {
                m9170();
                this.f15809.write(bArr, i, i2);
                this.f15808 = j3;
                return;
            }
        }
        this.f15809.write(bArr, i, (int) (j - this.f15808));
        m9170();
        RandomAccessFile randomAccessFile = this.f15809;
        long j4 = j - this.f15808;
        randomAccessFile.write(bArr, i + ((int) j4), (int) (j3 - j4));
        this.f15808 = j3 - (j - this.f15808);
    }

    /* renamed from: ˌʾˀ, reason: contains not printable characters */
    public final void m9170() throws IOException {
        String str;
        String strM9804 = AbstractC4618.m9804(this.f15811.getName());
        String absolutePath = this.f15811.getAbsolutePath();
        if (this.f15811.getParent() == null) {
            str = "";
        } else {
            str = this.f15811.getParent() + System.getProperty("file.separator");
        }
        String str2 = ".z0" + (this.f15810 + 1);
        if (this.f15810 >= 9) {
            str2 = ".z" + (this.f15810 + 1);
        }
        File file = new File(AbstractC1327.m4106(str, strM9804, str2));
        this.f15809.close();
        if (file.exists()) {
            throw new IOException("split file: " + file.getName() + " already exists in the current directory, cannot rename this file");
        }
        if (!this.f15811.renameTo(file)) {
            C0910.m3045("cannot rename newly created split file");
            return;
        }
        this.f15811 = new File(absolutePath);
        this.f15809 = new RandomAccessFile(this.f15811, "rw");
        this.f15810++;
    }

    @Override // defpackage.InterfaceC1721
    /* renamed from: ˏᵙ */
    public final long mo4919() {
        return this.f15809.getFilePointer();
    }

    @Override // defpackage.InterfaceC1721
    /* renamed from: ᵥᵯˎ */
    public final int mo4920() {
        return this.f15810;
    }
}
