apk(点击下载) / e.java


package com.bumptech.glide.load.k;

import android.util.Base64;
import androidx.annotation.NonNull;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.f;
import com.bumptech.glide.load.j.d;
import com.bumptech.glide.load.k.n;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

/* compiled from: DataUrlLoader */
public final class e<Model, Data> implements n<Model, Data> {
    private final a<Data> a;

    /* compiled from: DataUrlLoader */
    public interface a<Data> {
        Class<Data> a();

        void b(Data data) throws IOException;

        Data c(String str) throws IllegalArgumentException;
    }

    /* compiled from: DataUrlLoader */
    private static final class b<Data> implements d<Data> {
        private final String a;
        private final a<Data> b;
        private Data c;

        b(String str, a<Data> aVar) {
            this.a = str;
            this.b = aVar;
        }

        @Override // com.bumptech.glide.load.j.d
        @NonNull
        public Class<Data> a() {
            return this.b.a();
        }

        @Override // com.bumptech.glide.load.j.d
        public void b() {
            try {
                this.b.b(this.c);
            } catch (IOException unused) {
            }
        }

        @Override // com.bumptech.glide.load.j.d
        public void cancel() {
        }

        @Override // com.bumptech.glide.load.j.d
        @NonNull
        public DataSource d() {
            return DataSource.LOCAL;
        }

        @Override // com.bumptech.glide.load.j.d
        public void e(@NonNull Priority priority, @NonNull d.a<? super Data> aVar) {
            try {
                Data c2 = this.b.c(this.a);
                this.c = c2;
                aVar.f(c2);
            } catch (IllegalArgumentException e) {
                aVar.c(e);
            }
        }
    }

    /* compiled from: DataUrlLoader */
    public static final class c<Model> implements o<Model, InputStream> {
        private final a<InputStream> a = new a(this);

        /* compiled from: DataUrlLoader */
        class a implements a<InputStream> {
            a(c cVar) {
            }

            @Override // com.bumptech.glide.load.k.e.a
            public Class<InputStream> a() {
                return InputStream.class;
            }

            /* renamed from: d */
            public void b(InputStream inputStream) throws IOException {
                inputStream.close();
            }

            /* renamed from: e */
            public InputStream c(String str) {
                if (str.startsWith("data:image")) {
                    int indexOf = str.indexOf(44);
                    if (indexOf == -1) {
                        throw new IllegalArgumentException("Missing comma in data URL.");
                    } else if (str.substring(0, indexOf).endsWith(";base64")) {
                        return new ByteArrayInputStream(Base64.decode(str.substring(indexOf + 1), 0));
                    } else {
                        throw new IllegalArgumentException("Not a base64 image data URL.");
                    }
                } else {
                    throw new IllegalArgumentException("Not a valid image data URL.");
                }
            }
        }

        @Override // com.bumptech.glide.load.k.o
        @NonNull
        public n<Model, InputStream> b(@NonNull r rVar) {
            return new e(this.a);
        }
    }

    public e(a<Data> aVar) {
        this.a = aVar;
    }

    @Override // com.bumptech.glide.load.k.n
    public boolean a(@NonNull Model model) {
        return model.toString().startsWith("data:image");
    }

    @Override // com.bumptech.glide.load.k.n
    public n.a<Data> b(@NonNull Model model, int i, int i2, @NonNull f fVar) {
        return new n.a<>(new com.bumptech.glide.m.c(model), new b(model.toString(), this.a));
    }
}