package p421.p433.p434.p439.p441;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import net.lingala.zip4j.exception.ZipException;
import p138.p139.p143.p144.C2803;
import p421.p433.p434.p438.EnumC6785;
import p421.p433.p434.p442.p443.EnumC6836;
import p421.p433.p434.p446.C6857;
import p421.p433.p434.p446.C6859;

/* JADX INFO: renamed from: ޏ.ؠ.֏.ށ.ؠ.ބ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public class C6810 extends OutputStream {

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public RandomAccessFile f19700;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public long f19701;

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

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

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public long f19704;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public C6859 f19705 = new C6859();

    public C6810(File file, long j) throws ZipException {
        if (j >= 0 && j < 65536) {
            throw new ZipException("split length less than minimum allowed split length of 65536 Bytes");
        }
        this.f19700 = new RandomAccessFile(file, EnumC6836.WRITE.f19843);
        this.f19701 = j;
        this.f19702 = file;
        this.f19703 = 0;
        this.f19704 = 0L;
    }

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

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

    @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 {
        if (i2 <= 0) {
            return;
        }
        long j = this.f19701;
        if (j == -1) {
            this.f19700.write(bArr, i, i2);
            this.f19704 += (long) i2;
            return;
        }
        long j2 = this.f19704;
        if (j2 >= j) {
            m9976();
            this.f19700.write(bArr, i, i2);
            this.f19704 = i2;
            return;
        }
        long j3 = i2;
        if (j2 + j3 <= j) {
            this.f19700.write(bArr, i, i2);
            this.f19704 += j3;
            return;
        }
        boolean z = false;
        int iM10012 = this.f19705.m10012(bArr, 0);
        EnumC6785[] enumC6785ArrValues = EnumC6785.values();
        int length = enumC6785ArrValues.length;
        int i3 = 0;
        while (true) {
            if (i3 < length) {
                EnumC6785 enumC6785 = enumC6785ArrValues[i3];
                if (enumC6785 != EnumC6785.SPLIT_ZIP && enumC6785.f19631 == iM10012) {
                    z = true;
                    break;
                }
                i3++;
            } else {
                break;
            }
        }
        if (z) {
            m9976();
            this.f19700.write(bArr, i, i2);
            this.f19704 = j3;
            return;
        }
        this.f19700.write(bArr, i, (int) (this.f19701 - this.f19704));
        m9976();
        RandomAccessFile randomAccessFile = this.f19700;
        long j4 = this.f19701;
        long j5 = this.f19704;
        randomAccessFile.write(bArr, i + ((int) (j4 - j5)), (int) (j3 - (j4 - j5)));
        this.f19704 = j3 - (this.f19701 - this.f19704);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public long m9975() {
        return this.f19700.getFilePointer();
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final void m9976() throws IOException {
        String str;
        String strM10002 = C6857.m10002(this.f19702.getName());
        String absolutePath = this.f19702.getAbsolutePath();
        if (this.f19702.getParent() == null) {
            str = "";
        } else {
            str = this.f19702.getParent() + System.getProperty("file.separator");
        }
        StringBuilder sbM4889 = C2803.m4889(".z0");
        sbM4889.append(this.f19703 + 1);
        String string = sbM4889.toString();
        if (this.f19703 >= 9) {
            StringBuilder sbM48892 = C2803.m4889(".z");
            sbM48892.append(this.f19703 + 1);
            string = sbM48892.toString();
        }
        File file = new File(C2803.m4880(str, strM10002, string));
        this.f19700.close();
        if (file.exists()) {
            StringBuilder sbM48893 = C2803.m4889("split file: ");
            sbM48893.append(file.getName());
            sbM48893.append(" already exists in the current directory, cannot rename this file");
            throw new IOException(sbM48893.toString());
        }
        if (!this.f19702.renameTo(file)) {
            throw new IOException("cannot rename newly created split file");
        }
        this.f19702 = new File(absolutePath);
        this.f19700 = new RandomAccessFile(this.f19702, EnumC6836.WRITE.f19843);
        this.f19703++;
    }
}
