package ph;

import android.util.Base64;
import com.bumptech.glide.load.data.d;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import ph.n;

/* loaded from: classes4.dex */
public final class e implements n {

    /* renamed from: a, reason: collision with root package name */
    private final a f32657a;

    /* loaded from: classes4.dex */
    public interface a {
        Class a();

        void b(Object obj);

        Object c(String str);
    }

    /* loaded from: classes4.dex */
    private static final class b implements com.bumptech.glide.load.data.d {

        /* renamed from: p, reason: collision with root package name */
        private final String f32658p;

        /* renamed from: q, reason: collision with root package name */
        private final a f32659q;

        /* renamed from: r, reason: collision with root package name */
        private Object f32660r;

        b(String str, a aVar) {
            this.f32658p = str;
            this.f32659q = aVar;
        }

        @Override // com.bumptech.glide.load.data.d
        public Class a() {
            return this.f32659q.a();
        }

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

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

        @Override // com.bumptech.glide.load.data.d
        public jh.a d() {
            return jh.a.LOCAL;
        }

        @Override // com.bumptech.glide.load.data.d
        public void e(com.bumptech.glide.g gVar, d.a aVar) {
            try {
                Object c10 = this.f32659q.c(this.f32658p);
                this.f32660r = c10;
                aVar.f(c10);
            } catch (IllegalArgumentException e10) {
                aVar.c(e10);
            }
        }
    }

    /* loaded from: classes4.dex */
    public static final class c implements o {

        /* renamed from: a, reason: collision with root package name */
        private final a f32661a = new a();

        /* loaded from: classes4.dex */
        class a implements a {
            a() {
            }

            @Override // ph.e.a
            public Class a() {
                return InputStream.class;
            }

            @Override // ph.e.a
            /* renamed from: d, reason: merged with bridge method [inline-methods] */
            public void b(InputStream inputStream) {
                inputStream.close();
            }

            @Override // ph.e.a
            /* renamed from: e, reason: merged with bridge method [inline-methods] */
            public InputStream c(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 // ph.o
        public void d() {
        }

        @Override // ph.o
        public n e(r rVar) {
            return new e(this.f32661a);
        }
    }

    public e(a aVar) {
        this.f32657a = aVar;
    }

    @Override // ph.n
    public boolean a(Object obj) {
        return obj.toString().startsWith("data:image");
    }

    @Override // ph.n
    public n.a b(Object obj, int i10, int i11, jh.h hVar) {
        return new n.a(new di.b(obj), new b(obj.toString(), this.f32657a));
    }
}
