package p138.p176.p291.p296.p297.p300;

import android.util.Log;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Locale;
import p138.p139.p143.p144.C2803;
import p138.p176.p291.p296.p297.C5608;
import p138.p176.p291.p296.p297.p299.C5627;

/* JADX INFO: renamed from: ދ.ހ.ށ.ބ.ށ.ވ.ނ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public class C5711 implements InterfaceC5700 {

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public static final Charset f16323 = Charset.forName("UTF-8");

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final File f16324;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final int f16325;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public C5705 f16326;

    /* JADX INFO: renamed from: ދ.ހ.ށ.ބ.ށ.ވ.ނ$֏, reason: contains not printable characters */
    public class C5712 {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final byte[] f16327;

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public final int f16328;

        public C5712(C5711 c5711, byte[] bArr, int i) {
            this.f16327 = bArr;
            this.f16328 = i;
        }
    }

    public C5711(File file, int i) {
        this.f16324 = file;
        this.f16325 = i;
    }

    @Override // p138.p176.p291.p296.p297.p300.InterfaceC5700
    /* JADX INFO: renamed from: ֏ */
    public void mo9072() {
        C5627.m8998(this.f16326, "There was a problem closing the Crashlytics log file.");
        this.f16326 = null;
    }

    @Override // p138.p176.p291.p296.p297.p300.InterfaceC5700
    /* JADX INFO: renamed from: ֏ */
    public void mo9073(long j, String str) {
        m9094();
        if (this.f16326 == null) {
            return;
        }
        if (str == null) {
            str = "null";
        }
        try {
            int i = this.f16325 / 4;
            if (str.length() > i) {
                str = "..." + str.substring(str.length() - i);
            }
            byte[] bytes = String.format(Locale.US, "%d %s%n", Long.valueOf(j), str.replaceAll("\r", " ").replaceAll("\n", " ")).getBytes(f16323);
            C5705 c5705 = this.f16326;
            if (c5705 == null) {
                throw null;
            }
            c5705.m9086(bytes, 0, bytes.length);
            while (!this.f16326.m9089() && this.f16326.m9092() > this.f16325) {
                this.f16326.m9091();
            }
        } catch (IOException e) {
            C5608 c5608 = C5608.f16066;
            if (c5608.m8974(6)) {
                Log.e(c5608.f16067, "There was a problem writing to the Crashlytics log.", e);
            }
        }
    }

    @Override // p138.p176.p291.p296.p297.p300.InterfaceC5700
    /* JADX INFO: renamed from: ؠ */
    public String mo9074() {
        byte[] bArrMo9075 = mo9075();
        if (bArrMo9075 != null) {
            return new String(bArrMo9075, f16323);
        }
        return null;
    }

    /* JADX WARN: Removed duplicated region for block: B:4:0x000a  */
    @Override // p138.p176.p291.p296.p297.p300.InterfaceC5700
    /* JADX INFO: renamed from: ހ */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public byte[] mo9075() {
        C5712 c5712;
        if (this.f16324.exists()) {
            m9094();
            C5705 c5705 = this.f16326;
            if (c5705 != null) {
                int[] iArr = {0};
                byte[] bArr = new byte[c5705.m9092()];
                try {
                    this.f16326.m9085(new C5710(this, bArr, iArr));
                } catch (IOException e) {
                    C5608 c5608 = C5608.f16066;
                    if (c5608.m8974(6)) {
                        Log.e(c5608.f16067, "A problem occurred while reading the Crashlytics log file.", e);
                    }
                }
                c5712 = new C5712(this, bArr, iArr[0]);
            }
        } else {
            c5712 = null;
        }
        if (c5712 == null) {
            return null;
        }
        int i = c5712.f16328;
        byte[] bArr2 = new byte[i];
        System.arraycopy(c5712.f16327, 0, bArr2, 0, i);
        return bArr2;
    }

    @Override // p138.p176.p291.p296.p297.p300.InterfaceC5700
    /* JADX INFO: renamed from: ށ */
    public void mo9076() {
        C5627.m8998(this.f16326, "There was a problem closing the Crashlytics log file.");
        this.f16326 = null;
        this.f16324.delete();
    }

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public final void m9094() {
        if (this.f16326 == null) {
            try {
                this.f16326 = new C5705(this.f16324);
            } catch (IOException e) {
                C5608 c5608 = C5608.f16066;
                StringBuilder sbM4889 = C2803.m4889("Could not open log file: ");
                sbM4889.append(this.f16324);
                c5608.m8976(sbM4889.toString(), e);
            }
        }
    }
}
