219 lines
6.8 KiB
Java
219 lines
6.8 KiB
Java
package com.bumptech.glide.load.engine;
|
|
|
|
import android.util.Log;
|
|
import com.bumptech.glide.load.DataSource;
|
|
import com.bumptech.glide.load.Key;
|
|
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;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class GlideException extends Exception {
|
|
private static final StackTraceElement[] EMPTY_ELEMENTS = new StackTraceElement[0];
|
|
private static final long serialVersionUID = 1;
|
|
private final List<Throwable> causes;
|
|
private Class<?> dataClass;
|
|
private DataSource dataSource;
|
|
private String detailMessage;
|
|
private Key key;
|
|
|
|
public GlideException(String str) {
|
|
this(str, (List<Throwable>) Collections.emptyList());
|
|
}
|
|
|
|
private void addRootCauses(Throwable th, List<Throwable> list) {
|
|
if (!(th instanceof GlideException)) {
|
|
list.add(th);
|
|
return;
|
|
}
|
|
Iterator<Throwable> it = ((GlideException) th).getCauses().iterator();
|
|
while (it.hasNext()) {
|
|
addRootCauses(it.next(), list);
|
|
}
|
|
}
|
|
|
|
private static void appendCauses(List<Throwable> list, Appendable appendable) {
|
|
try {
|
|
appendCausesWrapped(list, appendable);
|
|
} catch (IOException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
}
|
|
|
|
private static void appendCausesWrapped(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).printStackTrace(appendable);
|
|
} else {
|
|
appendExceptionMessage(th, appendable);
|
|
}
|
|
i = i2;
|
|
}
|
|
}
|
|
|
|
private static void appendExceptionMessage(Throwable th, Appendable appendable) {
|
|
try {
|
|
appendable.append(th.getClass().toString()).append(": ").append(th.getMessage()).append('\n');
|
|
} catch (IOException unused) {
|
|
throw new RuntimeException(th);
|
|
}
|
|
}
|
|
|
|
@Override // java.lang.Throwable
|
|
public Throwable fillInStackTrace() {
|
|
return this;
|
|
}
|
|
|
|
public List<Throwable> getCauses() {
|
|
return this.causes;
|
|
}
|
|
|
|
@Override // java.lang.Throwable
|
|
public String getMessage() {
|
|
StringBuilder sb = new StringBuilder(71);
|
|
sb.append(this.detailMessage);
|
|
sb.append(this.dataClass != null ? ", " + this.dataClass : "");
|
|
sb.append(this.dataSource != null ? ", " + this.dataSource : "");
|
|
sb.append(this.key != null ? ", " + this.key : "");
|
|
List<Throwable> rootCauses = getRootCauses();
|
|
if (rootCauses.isEmpty()) {
|
|
return sb.toString();
|
|
}
|
|
if (rootCauses.size() == 1) {
|
|
sb.append("\nThere was 1 cause:");
|
|
} else {
|
|
sb.append("\nThere were ");
|
|
sb.append(rootCauses.size());
|
|
sb.append(" causes:");
|
|
}
|
|
for (Throwable th : rootCauses) {
|
|
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();
|
|
}
|
|
|
|
public List<Throwable> getRootCauses() {
|
|
ArrayList arrayList = new ArrayList();
|
|
addRootCauses(this, arrayList);
|
|
return arrayList;
|
|
}
|
|
|
|
public void logRootCauses(String str) {
|
|
List<Throwable> rootCauses = getRootCauses();
|
|
int size = rootCauses.size();
|
|
int i = 0;
|
|
while (i < size) {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("Root cause (");
|
|
int i2 = i + 1;
|
|
sb.append(i2);
|
|
sb.append(" of ");
|
|
sb.append(size);
|
|
sb.append(")");
|
|
Log.i(str, sb.toString(), rootCauses.get(i));
|
|
i = i2;
|
|
}
|
|
}
|
|
|
|
@Override // java.lang.Throwable
|
|
public void printStackTrace() {
|
|
printStackTrace(System.err);
|
|
}
|
|
|
|
void setLoggingDetails(Key key, DataSource dataSource) {
|
|
setLoggingDetails(key, dataSource, null);
|
|
}
|
|
|
|
public GlideException(String str, Throwable th) {
|
|
this(str, (List<Throwable>) Collections.singletonList(th));
|
|
}
|
|
|
|
@Override // java.lang.Throwable
|
|
public void printStackTrace(PrintStream printStream) {
|
|
printStackTrace((Appendable) printStream);
|
|
}
|
|
|
|
void setLoggingDetails(Key key, DataSource dataSource, Class<?> cls) {
|
|
this.key = key;
|
|
this.dataSource = dataSource;
|
|
this.dataClass = cls;
|
|
}
|
|
|
|
public GlideException(String str, List<Throwable> list) {
|
|
this.detailMessage = str;
|
|
setStackTrace(EMPTY_ELEMENTS);
|
|
this.causes = list;
|
|
}
|
|
|
|
@Override // java.lang.Throwable
|
|
public void printStackTrace(PrintWriter printWriter) {
|
|
printStackTrace((Appendable) printWriter);
|
|
}
|
|
|
|
private void printStackTrace(Appendable appendable) {
|
|
appendExceptionMessage(this, appendable);
|
|
appendCauses(getCauses(), new IndentedAppendable(appendable));
|
|
}
|
|
|
|
private static final class IndentedAppendable implements Appendable {
|
|
private final Appendable a;
|
|
private boolean b = true;
|
|
|
|
IndentedAppendable(Appendable appendable) {
|
|
this.a = appendable;
|
|
}
|
|
|
|
private CharSequence a(CharSequence charSequence) {
|
|
return charSequence == null ? "" : charSequence;
|
|
}
|
|
|
|
@Override // java.lang.Appendable
|
|
public Appendable append(char c) throws IOException {
|
|
if (this.b) {
|
|
this.b = false;
|
|
this.a.append(" ");
|
|
}
|
|
this.b = c == '\n';
|
|
this.a.append(c);
|
|
return this;
|
|
}
|
|
|
|
@Override // java.lang.Appendable
|
|
public Appendable append(CharSequence charSequence) throws IOException {
|
|
CharSequence a = a(charSequence);
|
|
append(a, 0, a.length());
|
|
return this;
|
|
}
|
|
|
|
@Override // java.lang.Appendable
|
|
public Appendable append(CharSequence charSequence, int i, int i2) throws IOException {
|
|
CharSequence a = a(charSequence);
|
|
boolean z = false;
|
|
if (this.b) {
|
|
this.b = false;
|
|
this.a.append(" ");
|
|
}
|
|
if (a.length() > 0 && a.charAt(i2 - 1) == '\n') {
|
|
z = true;
|
|
}
|
|
this.b = z;
|
|
this.a.append(a, i, i2);
|
|
return this;
|
|
}
|
|
}
|
|
}
|