package ඓ.ⁱ.K.㸾;

import com.appsflyer.share.Constants;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Locale;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import ඓ.ⁱ.K.ʬ.AbstractC1231;
import ඓ.ⁱ.K.ʬ.AbstractC1242;
import ඓ.ⁱ.K.ʬ.C1243;
import ඓ.ⁱ.K.ʬ.C1248;
import ඓ.ⁱ.K.ඓ.C1250;
import ඓ.ⁱ.K.ඓ.C1252;
import ඓ.K.K.K.C1293;
import ῲ.ᨨ.㳳.C1841;

/* renamed from: ඓ.ⁱ.K.㸾.㿎  reason: contains not printable characters */
/* compiled from: ResumeUploader */
public final class RunnableC1283 implements Runnable {

    /* renamed from: ʬ  reason: contains not printable characters */
    public final String f5004;

    /* renamed from: Ԕ  reason: contains not printable characters */
    public File f5005;

    /* renamed from: ؿ  reason: contains not printable characters */
    public C1276 f5006;

    /* renamed from: ඓ  reason: contains not printable characters */
    public final C1269 f5007;

    /* renamed from: ᕣ  reason: contains not printable characters */
    public final long f5008;

    /* renamed from: ᨨ  reason: contains not printable characters */
    public final String[] f5009;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final long f5010;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public final C1272 f5011;

    /* renamed from: 㑃  reason: contains not printable characters */
    public final String f5012;

    /* renamed from: 㗗  reason: contains not printable characters */
    public long f5013;

    /* renamed from: 㳳  reason: contains not printable characters */
    public final C1250 f5014;

    /* renamed from: 㴹  reason: contains not printable characters */
    public final C1243 f5015;

    /* renamed from: 㸾  reason: contains not printable characters */
    public final AbstractC1278 f5016;

    /* renamed from: 㿎  reason: contains not printable characters */
    public final byte[] f5017;

    /* renamed from: 䁗  reason: contains not printable characters */
    public RandomAccessFile f5018 = null;

    /* renamed from: ඓ.ⁱ.K.㸾.㿎$ʬ  reason: contains not printable characters */
    /* compiled from: ResumeUploader */
    public class C1284 implements AbstractC1231 {

        /* renamed from: K  reason: contains not printable characters */
        public final /* synthetic */ long f5020;

        public C1284(long j) {
            this.f5020 = j;
        }

        @Override // ඓ.ⁱ.K.ʬ.AbstractC1231
        public void onProgress(long j, long j2) {
            double d = ((double) (this.f5020 + j)) / ((double) j2);
            if (d > 0.95d) {
                d = 0.95d;
            }
            RunnableC1283 r5 = RunnableC1283.this;
            ((C1266) r5.f5007.f4964).m3375(r5.f5004, d);
        }
    }

    /* renamed from: ඓ.ⁱ.K.㸾.㿎$ῲ  reason: contains not printable characters */
    /* compiled from: ResumeUploader */
    public class C1285 implements AbstractC1242 {

        /* renamed from: ʬ  reason: contains not printable characters */
        public final /* synthetic */ long f5021;

        /* renamed from: ῲ  reason: contains not printable characters */
        public final /* synthetic */ String f5022;

        /* renamed from: K  reason: contains not printable characters */
        public final /* synthetic */ int f5023;

        public C1285(int i, String str, long j) {
            this.f5023 = i;
            this.f5022 = str;
            this.f5021 = j;
        }

        @Override // ඓ.ⁱ.K.ʬ.AbstractC1242
        /* renamed from: K  reason: contains not printable characters */
        public void m3393(C1248 r5, JSONObject jSONObject) {
            String r0;
            if (r5.m3323() && !C1841.m4747()) {
                ((C1267) RunnableC1283.this.f5007.f4965).m3376();
                if (!C1841.m4747()) {
                    RunnableC1283 r02 = RunnableC1283.this;
                    r02.f5016.m3385(r02.f5004, r5, jSONObject);
                    return;
                }
            }
            if (r5.m3322()) {
                RunnableC1283 r03 = RunnableC1283.this;
                AbstractC1274 r1 = r03.f5011.f4974;
                if (r1 != null) {
                    r1.m3380(r03.f5012);
                }
                RunnableC1283 r04 = RunnableC1283.this;
                ((C1266) r04.f5007.f4964).m3375(r04.f5004, 1.0d);
                RunnableC1283 r05 = RunnableC1283.this;
                r05.f5016.m3385(r05.f5004, r5, jSONObject);
                return;
            }
            if (r5.m3325()) {
                int i = this.f5023;
                RunnableC1283 r12 = RunnableC1283.this;
                C1272 r2 = r12.f5011;
                if (i < r2.f4978 + 1 && (r0 = r2.f4971.m3364(r12.f5006.f4990, r2.f4975, this.f5022)) != null) {
                    RunnableC1283.this.m3391(this.f5021, this.f5023 + 1, r0);
                    return;
                }
            }
            RunnableC1283 r06 = RunnableC1283.this;
            r06.f5016.m3385(r06.f5004, r5, jSONObject);
        }
    }

    /* renamed from: ඓ.ⁱ.K.㸾.㿎$K  reason: contains not printable characters */
    /* compiled from: ResumeUploader */
    public class C1286 implements AbstractC1278 {

        /* renamed from: K  reason: contains not printable characters */
        public final /* synthetic */ AbstractC1278 f5026;

        public C1286(AbstractC1278 r2) {
            this.f5026 = r2;
        }

        @Override // ඓ.ⁱ.K.㸾.AbstractC1278
        /* renamed from: K  reason: contains not printable characters */
        public void m3394(String str, C1248 r3, JSONObject jSONObject) {
            RandomAccessFile randomAccessFile = RunnableC1283.this.f5018;
            if (randomAccessFile != null) {
                try {
                    randomAccessFile.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            this.f5026.m3385(str, r3, jSONObject);
        }
    }

    /* renamed from: ඓ.ⁱ.K.㸾.㿎$㸾  reason: contains not printable characters */
    /* compiled from: ResumeUploader */
    public class C1287 implements AbstractC1242 {

        /* renamed from: ʬ  reason: contains not printable characters */
        public final /* synthetic */ long f5027;

        /* renamed from: ῲ  reason: contains not printable characters */
        public final /* synthetic */ int f5029;

        /* renamed from: K  reason: contains not printable characters */
        public final /* synthetic */ String f5030;

        /* renamed from: 㸾  reason: contains not printable characters */
        public final /* synthetic */ int f5031;

        public C1287(String str, int i, long j, int i2) {
            this.f5030 = str;
            this.f5029 = i;
            this.f5027 = j;
            this.f5031 = i2;
        }

        @Override // ඓ.ⁱ.K.ʬ.AbstractC1242
        /* renamed from: K  reason: contains not printable characters */
        public void m3395(C1248 r12, JSONObject jSONObject) {
            long j;
            boolean z;
            if (r12.m3323() && !C1841.m4747()) {
                ((C1267) RunnableC1283.this.f5007.f4965).m3376();
                if (!C1841.m4747()) {
                    RunnableC1283 r0 = RunnableC1283.this;
                    r0.f5016.m3385(r0.f5004, r12, jSONObject);
                    return;
                }
            }
            int i = 0;
            if (r12.f4904 == -2) {
                RunnableC1283 r02 = RunnableC1283.this;
                r02.f5016.m3385(r02.f5004, r12, jSONObject);
            } else if (!RunnableC1283.m3390(r12, jSONObject)) {
                RunnableC1283 r03 = RunnableC1283.this;
                C1272 r7 = r03.f5011;
                String r04 = r7.f4971.m3364(r03.f5006.f4990, r7.f4975, this.f5030);
                if (r12.f4904 == 701) {
                    int i2 = this.f5029;
                    RunnableC1283 r8 = RunnableC1283.this;
                    if (i2 < r8.f5011.f4978) {
                        r8.m3391((this.f5027 / 4194304) * 4194304, i2 + 1, this.f5030);
                        return;
                    }
                }
                if (r04 != null) {
                    int i3 = r12.f4904;
                    if (i3 < 500 && i3 >= 200 && !r12.m3324()) {
                        try {
                            jSONObject.getString("ctx");
                            jSONObject.getLong("crc32");
                            z = true;
                        } catch (Exception unused) {
                            z = false;
                        }
                        if (!z) {
                            i = 1;
                        }
                    }
                    if (i != 0 || r12.m3325()) {
                        int i4 = this.f5029;
                        RunnableC1283 r2 = RunnableC1283.this;
                        if (i4 < r2.f5011.f4978) {
                            r2.m3391(this.f5027, i4 + 1, r04);
                            return;
                        }
                    }
                }
                RunnableC1283 r05 = RunnableC1283.this;
                r05.f5016.m3385(r05.f5004, r12, jSONObject);
            } else {
                String str = null;
                if (jSONObject == null) {
                    int i5 = this.f5029;
                    RunnableC1283 r72 = RunnableC1283.this;
                    C1272 r82 = r72.f5011;
                    if (i5 < r82.f4978) {
                        RunnableC1283.this.m3391(this.f5027, this.f5029 + 1, r82.f4971.m3364(r72.f5006.f4990, r82.f4975, this.f5030));
                        return;
                    }
                }
                try {
                    str = jSONObject.getString("ctx");
                    j = jSONObject.getLong("crc32");
                } catch (Exception e) {
                    e.printStackTrace();
                    j = 0;
                }
                if (str == null || j != RunnableC1283.this.f5013) {
                    int i6 = this.f5029;
                    RunnableC1283 r06 = RunnableC1283.this;
                    C1272 r1 = r06.f5011;
                    if (i6 < r1.f4978) {
                        RunnableC1283.this.m3391(this.f5027, this.f5029 + 1, r1.f4971.m3364(r06.f5006.f4990, r1.f4975, this.f5030));
                        return;
                    }
                }
                RunnableC1283 r13 = RunnableC1283.this;
                String[] strArr = r13.f5009;
                long j2 = this.f5027;
                strArr[(int) (j2 / 4194304)] = str;
                long j3 = j2 + ((long) this.f5031);
                if (!(r13.f5011.f4974 == null || j3 == 0)) {
                    Locale locale = Locale.ENGLISH;
                    Object[] objArr = new Object[4];
                    objArr[0] = Long.valueOf(r13.f5010);
                    objArr[1] = Long.valueOf(j3);
                    objArr[2] = Long.valueOf(r13.f5008);
                    String[] strArr2 = r13.f5009;
                    int length = strArr2.length;
                    StringBuilder sb = new StringBuilder((strArr2[0].length() + 3) * length);
                    while (i < length) {
                        if (i > 0) {
                            sb.append(',');
                        }
                        sb.append('\"');
                        sb.append(strArr2[i]);
                        sb.append('\"');
                        i++;
                    }
                    objArr[3] = sb.toString();
                    r13.f5011.f4974.m3381(r13.f5012, String.format(locale, "{\"size\":%d,\"offset\":%d, \"modify_time\":%d, \"contexts\":[%s]}", objArr).getBytes());
                }
                RunnableC1283.this.m3391(this.f5027 + ((long) this.f5031), this.f5029, this.f5030);
            }
        }
    }

    public RunnableC1283(C1243 r7, C1272 r8, File file, String str, C1276 r11, AbstractC1278 r12, C1269 r13, String str2) {
        C1269 r72;
        this.f5015 = r7;
        this.f5011 = r8;
        this.f5005 = file;
        this.f5012 = str2;
        this.f5010 = file.length();
        this.f5004 = str;
        C1250 r73 = new C1250();
        StringBuilder r10 = C1293.m3416("UpToken ");
        r10.append(r11.f4990);
        r73.f4922.put("Authorization", r10.toString());
        this.f5014 = r73;
        this.f5016 = new C1286(r12);
        if (r13 != null) {
            r72 = r13;
        } else {
            r72 = new C1269(null, null, false, null, null);
        }
        this.f5007 = r72;
        this.f5017 = new byte[r8.f4977];
        this.f5009 = new String[((int) (((this.f5010 + 4194304) - 1) / 4194304))];
        this.f5008 = file.lastModified();
        this.f5006 = r11;
    }

    /* renamed from: K  reason: contains not printable characters */
    public static /* synthetic */ boolean m3390(C1248 r2, JSONObject jSONObject) {
        return r2.f4904 == 200 && r2.f4899 == null && (r2.m3324() || m3389(jSONObject));
    }

    public void run() {
        byte[] r0;
        AbstractC1274 r02 = this.f5011.f4974;
        long j = 0;
        if (!(r02 == null || (r0 = r02.m3379(this.f5012)) == null)) {
            try {
                JSONObject jSONObject = new JSONObject(new String(r0));
                long optLong = jSONObject.optLong("offset", 0);
                long optLong2 = jSONObject.optLong("modify_time", 0);
                long optLong3 = jSONObject.optLong("size", 0);
                JSONArray optJSONArray = jSONObject.optJSONArray("contexts");
                if (!(optLong == 0 || optLong2 != this.f5008 || optLong3 != this.f5010 || optJSONArray == null || optJSONArray.length() == 0)) {
                    for (int i = 0; i < optJSONArray.length(); i++) {
                        this.f5009[i] = optJSONArray.optString(i);
                    }
                    j = optLong;
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        try {
            this.f5018 = new RandomAccessFile(this.f5005, "r");
            C1272 r4 = this.f5011;
            m3391(j, 0, r4.f4971.m3364(this.f5006.f4990, r4.f4975, (String) null));
        } catch (FileNotFoundException e2) {
            e2.printStackTrace();
            this.f5016.m3385(this.f5004, C1248.m3319(e2, this.f5006), null);
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public static boolean m3389(JSONObject jSONObject) {
        try {
            jSONObject.getString("ctx");
            jSONObject.getLong("crc32");
            return true;
        } catch (Exception unused) {
            return false;
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m3392(String str, byte[] bArr, int i, int i2, AbstractC1231 r18, AbstractC1242 r19, AbstractC1271 r20) {
        this.f5015.m3315(str, bArr, i, i2, this.f5014, this.f5006, this.f5010, r18, r19, r20);
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m3391(long j, int i, String str) {
        ((C1277) this.f5007.f4968).m3384();
        long j2 = this.f5010;
        if (j == j2) {
            C1285 r7 = new C1285(i, str, j);
            C1269 r0 = this.f5007;
            AbstractC1271 r10 = r0.f4968;
            String format = String.format(Locale.ENGLISH, "/mimeType/%s/fname/%s", C1252.m3333(r0.f4966), C1252.m3333(this.f5005.getName()));
            String str2 = this.f5004;
            String str3 = "";
            String format2 = str2 != null ? String.format("/key/%s", C1252.m3333(str2)) : str3;
            if (this.f5007.f4967.size() != 0) {
                String[] strArr = new String[this.f5007.f4967.size()];
                int i2 = 0;
                for (Map.Entry<String, String> entry : this.f5007.f4967.entrySet()) {
                    strArr[i2] = String.format(Locale.ENGLISH, "%s/%s", entry.getKey(), C1252.m3333(entry.getValue()));
                    i2++;
                }
                StringBuilder r4 = C1293.m3416(Constants.URL_PATH_DELIMITER);
                r4.append(C1252.m3344(strArr, Constants.URL_PATH_DELIMITER));
                str3 = r4.toString();
            }
            String format3 = String.format(Locale.ENGLISH, "/mkfile/%d%s%s%s", Long.valueOf(this.f5010), format, format2, str3);
            byte[] bytes = C1252.m3344(this.f5009, ",").getBytes();
            m3392(String.format("%s%s", str, format3), bytes, 0, bytes.length, null, r7, r10);
            return;
        }
        long j3 = j2 - j;
        long j4 = (long) this.f5011.f4977;
        if (j3 >= j4) {
            j3 = j4;
        }
        int i3 = (int) j3;
        C1284 r02 = new C1284(j);
        C1287 r16 = new C1287(str, i, j, i3);
        long j5 = 4194304;
        long j6 = j % 4194304;
        if (j6 == 0) {
            long j7 = this.f5010 - j;
            if (j7 < 4194304) {
                j5 = j7;
            }
            AbstractC1271 r6 = this.f5007.f4968;
            String format4 = String.format(Locale.ENGLISH, "/mkblk/%d", Integer.valueOf((int) j5));
            try {
                this.f5018.seek(j);
                this.f5018.read(this.f5017, 0, i3);
                this.f5013 = C1252.m3336(this.f5017, 0, i3);
                m3392(String.format("%s%s", str, format4), this.f5017, 0, i3, r02, r16, r6);
            } catch (IOException e) {
                this.f5016.m3385(this.f5004, C1248.m3319(e, this.f5006), null);
            }
        } else {
            String str4 = this.f5009[(int) (j / 4194304)];
            AbstractC1271 r62 = this.f5007.f4968;
            String format5 = String.format(Locale.ENGLISH, "/bput/%s/%d", str4, Integer.valueOf((int) j6));
            try {
                this.f5018.seek(j);
                this.f5018.read(this.f5017, 0, i3);
                this.f5013 = C1252.m3336(this.f5017, 0, i3);
                m3392(String.format("%s%s", str, format5), this.f5017, 0, i3, r02, r16, r62);
            } catch (IOException e2) {
                this.f5016.m3385(this.f5004, C1248.m3319(e2, this.f5006), null);
            }
        }
    }
}
