package com.bumptech.glide.load.engine;

import android.util.Log;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import p138.p139.p143.p144.C2803;
import p138.p145.p146.p151.EnumC2840;
import p138.p145.p146.p151.InterfaceC2844;

/* JADX INFO: loaded from: classes.dex */
public final class GlideException extends Exception {

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public static final StackTraceElement[] f1518 = new StackTraceElement[0];

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final List<Throwable> f1519;

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

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

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public Class<?> f1522;

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

    /* JADX INFO: renamed from: com.bumptech.glide.load.engine.GlideException$֏, reason: contains not printable characters */
    public static final class C0264 implements Appendable {

        /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
        public final Appendable f1524;

        /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
        public boolean f1525 = true;

        public C0264(Appendable appendable) {
            this.f1524 = appendable;
        }

        @Override // java.lang.Appendable
        public Appendable append(char c) throws IOException {
            if (this.f1525) {
                this.f1525 = false;
                this.f1524.append("  ");
            }
            this.f1525 = c == '\n';
            this.f1524.append(c);
            return this;
        }

        @Override // java.lang.Appendable
        public Appendable append(CharSequence charSequence) throws IOException {
            if (charSequence == null) {
                charSequence = "";
            }
            append(charSequence, 0, charSequence.length());
            return this;
        }

        @Override // java.lang.Appendable
        public Appendable append(CharSequence charSequence, int i, int i2) throws IOException {
            if (charSequence == null) {
                charSequence = "";
            }
            boolean z = false;
            if (this.f1525) {
                this.f1525 = false;
                this.f1524.append("  ");
            }
            if (charSequence.length() > 0 && charSequence.charAt(i2 - 1) == '\n') {
                z = true;
            }
            this.f1525 = z;
            this.f1524.append(charSequence, i, i2);
            return this;
        }
    }

    public GlideException(String str) {
        List<Throwable> listEmptyList = Collections.emptyList();
        this.f1523 = str;
        setStackTrace(f1518);
        this.f1519 = listEmptyList;
    }

    public GlideException(String str, Throwable th) {
        List<Throwable> listSingletonList = Collections.singletonList(th);
        this.f1523 = str;
        setStackTrace(f1518);
        this.f1519 = listSingletonList;
    }

    public GlideException(String str, List<Throwable> list) {
        this.f1523 = str;
        setStackTrace(f1518);
        this.f1519 = list;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static void m1039(Throwable th, Appendable appendable) {
        try {
            appendable.append(th.getClass().toString()).append(": ").append(th.getMessage()).append('\n');
        } catch (IOException unused) {
            throw new RuntimeException(th);
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static void m1040(List<Throwable> list, Appendable appendable) throws IOException {
        int size = list.size();
        int i = 0;
        while (i < size) {
            int i2 = i + 1;
            appendable.append("Cause (").append(String.valueOf(i2)).append(" of ").append(String.valueOf(size)).append("): ");
            Throwable th = list.get(i);
            if (th instanceof GlideException) {
                ((GlideException) th).m1041(appendable);
            } else {
                m1039(th, appendable);
            }
            i = i2;
        }
    }

    @Override // java.lang.Throwable
    public Throwable fillInStackTrace() {
        return this;
    }

    @Override // java.lang.Throwable
    public String getMessage() {
        String string;
        String string2;
        StringBuilder sb = new StringBuilder(71);
        sb.append(this.f1523);
        String string3 = "";
        if (this.f1522 != null) {
            StringBuilder sbM4889 = C2803.m4889(", ");
            sbM4889.append(this.f1522);
            string = sbM4889.toString();
        } else {
            string = "";
        }
        sb.append(string);
        if (this.f1521 != null) {
            StringBuilder sbM48892 = C2803.m4889(", ");
            sbM48892.append(this.f1521);
            string2 = sbM48892.toString();
        } else {
            string2 = "";
        }
        sb.append(string2);
        if (this.f1520 != null) {
            StringBuilder sbM48893 = C2803.m4889(", ");
            sbM48893.append(this.f1520);
            string3 = sbM48893.toString();
        }
        sb.append(string3);
        ArrayList<Throwable> arrayList = new ArrayList();
        m1043(this, arrayList);
        if (arrayList.isEmpty()) {
            return sb.toString();
        }
        if (arrayList.size() == 1) {
            sb.append("\nThere was 1 cause:");
        } else {
            sb.append("\nThere were ");
            sb.append(arrayList.size());
            sb.append(" causes:");
        }
        for (Throwable th : arrayList) {
            sb.append('\n');
            sb.append(th.getClass().getName());
            sb.append('(');
            sb.append(th.getMessage());
            sb.append(')');
        }
        sb.append("\n call GlideException#logRootCauses(String) for more detail");
        return sb.toString();
    }

    @Override // java.lang.Throwable
    public void printStackTrace() {
        m1041(System.err);
    }

    @Override // java.lang.Throwable
    public void printStackTrace(PrintStream printStream) {
        m1041(printStream);
    }

    @Override // java.lang.Throwable
    public void printStackTrace(PrintWriter printWriter) {
        m1041(printWriter);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m1041(Appendable appendable) {
        m1039(this, appendable);
        try {
            m1040(this.f1519, new C0264(appendable));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public void m1042(String str) {
        ArrayList arrayList = new ArrayList();
        m1043(this, arrayList);
        int size = arrayList.size();
        int i = 0;
        while (i < size) {
            StringBuilder sbM4889 = C2803.m4889("Root cause (");
            int i2 = i + 1;
            sbM4889.append(i2);
            sbM4889.append(" of ");
            sbM4889.append(size);
            sbM4889.append(")");
            Log.i(str, sbM4889.toString(), (Throwable) arrayList.get(i));
            i = i2;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m1043(Throwable th, List<Throwable> list) {
        if (!(th instanceof GlideException)) {
            list.add(th);
            return;
        }
        Iterator<Throwable> it = ((GlideException) th).f1519.iterator();
        while (it.hasNext()) {
            m1043(it.next(), list);
        }
    }
}
