package defpackage;

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

/* JADX INFO: renamed from: ᵷᵢˑᵼ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C4908 extends OutputStream implements InterfaceC4839 {

    /* JADX INFO: renamed from: ˌᴵ, reason: contains not printable characters */
    public RandomAccessFile f18681;

    /* JADX INFO: renamed from: ᵔᵖᵹᵫ, reason: contains not printable characters */
    public File f18682;

    /* JADX INFO: renamed from: ᵜᵪʾ, reason: contains not printable characters */
    public final long f18683;

    /* JADX INFO: renamed from: ᵨᵼⁱ, reason: contains not printable characters */
    public int f18684;

    /* JADX INFO: renamed from: ᵯᵷʽ, reason: contains not printable characters */
    public long f18685;

    /* JADX INFO: renamed from: ᵶˇᵱ, reason: contains not printable characters */
    public final C2994 f18686;

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

    public C4908(File file, long j) throws ZipException {
        this.f18686 = new C2994(3);
        if (j >= 0 && j < 65536) {
            C4468.m9508("split length less than minimum allowed split length of 65536 Bytes");
            throw null;
        }
        this.f18681 = new RandomAccessFile(file, "rw");
        this.f18683 = j;
        this.f18682 = file;
        this.f18684 = 0;
        this.f18685 = 0L;
    }

    @Override // java.io.OutputStream, java.io.Closeable, java.lang.AutoCloseable
    public final void close() throws IOException {
        this.f18681.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.f18683;
        if (j == -1) {
            this.f18681.write(bArr, i, i2);
            this.f18685 += (long) i2;
            return;
        }
        long j2 = this.f18685;
        if (j2 >= j) {
            m10215();
            this.f18681.write(bArr, i, i2);
            this.f18685 = i2;
            return;
        }
        long j3 = i2;
        if (j2 + j3 <= j) {
            this.f18681.write(bArr, i, i2);
            this.f18685 += j3;
            return;
        }
        this.f18686.getClass();
        int iM7072 = C2994.m7072(0, bArr);
        for (int i3 : AbstractC3653.m8225(12)) {
            if (i3 != 8 && AbstractC0793.m2872(i3) == iM7072) {
                m10215();
                this.f18681.write(bArr, i, i2);
                this.f18685 = j3;
                return;
            }
        }
        this.f18681.write(bArr, i, (int) (j - this.f18685));
        m10215();
        RandomAccessFile randomAccessFile = this.f18681;
        long j4 = j - this.f18685;
        randomAccessFile.write(bArr, i + ((int) j4), (int) (j3 - j4));
        this.f18685 = j3 - (j - this.f18685);
    }

    @Override // defpackage.InterfaceC4839
    /* JADX INFO: renamed from: ːˏᵟᵯ */
    public final long mo7054() {
        return this.f18681.getFilePointer();
    }

    /* JADX INFO: renamed from: ᵟᵹᵙ, reason: contains not printable characters */
    public final void m10215() throws IOException {
        String str;
        String str2 = ˁᵨᵦ.ᵝᵶ(this.f18682.getName());
        String absolutePath = this.f18682.getAbsolutePath();
        if (this.f18682.getParent() == null) {
            str = "";
        } else {
            str = this.f18682.getParent() + System.getProperty("file.separator");
        }
        String str3 = ".z0" + (this.f18684 + 1);
        if (this.f18684 >= 9) {
            str3 = ".z" + (this.f18684 + 1);
        }
        File file = new File(AbstractC3653.m8223(str, str2, str3));
        this.f18681.close();
        if (file.exists()) {
            throw new IOException("split file: " + file.getName() + " already exists in the current directory, cannot rename this file");
        }
        if (!this.f18682.renameTo(file)) {
            C1685.m4568("cannot rename newly created split file");
            return;
        }
        this.f18682 = new File(absolutePath);
        this.f18681 = new RandomAccessFile(this.f18682, "rw");
        this.f18684++;
    }

    @Override // defpackage.InterfaceC4839
    /* JADX INFO: renamed from: ᵲᵶᵳˈ */
    public final int mo7056() {
        return this.f18684;
    }
}
