package a0;

import android.content.Context;
import b0.AbstractC0399d;
import b0.D;
import java.io.IOException;

/* JADX INFO: loaded from: classes.dex */
public final class l implements x {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private final x f1982a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final x f1983b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final x f1984c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private final x f1985d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private x f1986e;

    public l(Context context, String str) {
        this(context, null, str, false);
    }

    @Override // a0.f
    public long a(h hVar) throws IOException {
        AbstractC0399d.e(this.f1986e == null);
        String scheme = hVar.f1940a.getScheme();
        if (D.D(hVar.f1940a)) {
            if (hVar.f1940a.getPath().startsWith("/android_asset/")) {
                this.f1986e = this.f1984c;
            } else {
                this.f1986e = this.f1983b;
            }
        } else if ("asset".equals(scheme)) {
            this.f1986e = this.f1984c;
        } else if ("content".equals(scheme)) {
            this.f1986e = this.f1985d;
        } else {
            this.f1986e = this.f1982a;
        }
        try {
            return this.f1986e.a(hVar);
        } catch (IOException e2) {
            close();
            throw e2;
        }
    }

    @Override // a0.f
    public void close() {
        x xVar = this.f1986e;
        if (xVar != null) {
            try {
                xVar.close();
            } finally {
                this.f1986e = null;
            }
        }
    }

    @Override // a0.x
    public String getUri() {
        x xVar = this.f1986e;
        if (xVar == null) {
            return null;
        }
        return xVar.getUri();
    }

    @Override // a0.f
    public int read(byte[] bArr, int i2, int i3) {
        return this.f1986e.read(bArr, i2, i3);
    }

    public l(Context context, w wVar, String str) {
        this(context, wVar, str, false);
    }

    public l(Context context, w wVar, String str, boolean z2) {
        this(context, wVar, new k(str, null, wVar, 8000, 8000, z2));
    }

    public l(Context context, w wVar, x xVar) {
        this.f1982a = (x) AbstractC0399d.d(xVar);
        this.f1983b = new m(wVar);
        this.f1984c = new c(context, wVar);
        this.f1985d = new e(context, wVar);
    }
}
