122 lines
4.4 KiB
Java
122 lines
4.4 KiB
Java
package com.bumptech.glide.load.model;
|
|
|
|
import android.util.Base64;
|
|
import com.bumptech.glide.Priority;
|
|
import com.bumptech.glide.load.DataSource;
|
|
import com.bumptech.glide.load.Options;
|
|
import com.bumptech.glide.load.data.DataFetcher;
|
|
import com.bumptech.glide.load.model.ModelLoader;
|
|
import com.bumptech.glide.signature.ObjectKey;
|
|
import java.io.ByteArrayInputStream;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class DataUrlLoader<Model, Data> implements ModelLoader<Model, Data> {
|
|
private final DataDecoder<Data> a;
|
|
|
|
public interface DataDecoder<Data> {
|
|
Class<Data> a();
|
|
|
|
void a(Data data) throws IOException;
|
|
|
|
Data decode(String str) throws IllegalArgumentException;
|
|
}
|
|
|
|
public static final class StreamFactory<Model> implements ModelLoaderFactory<Model, InputStream> {
|
|
private final DataDecoder<InputStream> a = new DataDecoder<InputStream>(this) { // from class: com.bumptech.glide.load.model.DataUrlLoader.StreamFactory.1
|
|
@Override // com.bumptech.glide.load.model.DataUrlLoader.DataDecoder
|
|
public void a(InputStream inputStream) throws IOException {
|
|
inputStream.close();
|
|
}
|
|
|
|
/* JADX WARN: Can't rename method to resolve collision */
|
|
@Override // com.bumptech.glide.load.model.DataUrlLoader.DataDecoder
|
|
public InputStream decode(String str) {
|
|
if (!str.startsWith("data:image")) {
|
|
throw new IllegalArgumentException("Not a valid image data URL.");
|
|
}
|
|
int indexOf = str.indexOf(44);
|
|
if (indexOf == -1) {
|
|
throw new IllegalArgumentException("Missing comma in data URL.");
|
|
}
|
|
if (str.substring(0, indexOf).endsWith(";base64")) {
|
|
return new ByteArrayInputStream(Base64.decode(str.substring(indexOf + 1), 0));
|
|
}
|
|
throw new IllegalArgumentException("Not a base64 image data URL.");
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.model.DataUrlLoader.DataDecoder
|
|
public Class<InputStream> a() {
|
|
return InputStream.class;
|
|
}
|
|
};
|
|
|
|
@Override // com.bumptech.glide.load.model.ModelLoaderFactory
|
|
public ModelLoader<Model, InputStream> a(MultiModelLoaderFactory multiModelLoaderFactory) {
|
|
return new DataUrlLoader(this.a);
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.model.ModelLoaderFactory
|
|
public void a() {
|
|
}
|
|
}
|
|
|
|
public DataUrlLoader(DataDecoder<Data> dataDecoder) {
|
|
this.a = dataDecoder;
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.model.ModelLoader
|
|
public ModelLoader.LoadData<Data> a(Model model, int i, int i2, Options options) {
|
|
return new ModelLoader.LoadData<>(new ObjectKey(model), new DataUriFetcher(model.toString(), this.a));
|
|
}
|
|
|
|
private static final class DataUriFetcher<Data> implements DataFetcher<Data> {
|
|
private final String a;
|
|
private final DataDecoder<Data> b;
|
|
private Data c;
|
|
|
|
DataUriFetcher(String str, DataDecoder<Data> dataDecoder) {
|
|
this.a = str;
|
|
this.b = dataDecoder;
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.data.DataFetcher
|
|
public void a(Priority priority, DataFetcher.DataCallback<? super Data> dataCallback) {
|
|
try {
|
|
this.c = this.b.decode(this.a);
|
|
dataCallback.a((DataFetcher.DataCallback<? super Data>) this.c);
|
|
} catch (IllegalArgumentException e) {
|
|
dataCallback.a((Exception) e);
|
|
}
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.data.DataFetcher
|
|
public void b() {
|
|
try {
|
|
this.b.a(this.c);
|
|
} catch (IOException unused) {
|
|
}
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.data.DataFetcher
|
|
public void cancel() {
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.data.DataFetcher
|
|
public DataSource getDataSource() {
|
|
return DataSource.LOCAL;
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.data.DataFetcher
|
|
public Class<Data> a() {
|
|
return this.b.a();
|
|
}
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.model.ModelLoader
|
|
public boolean a(Model model) {
|
|
return model.toString().startsWith("data:image");
|
|
}
|
|
}
|