package defpackage;

import android.content.Context;
import android.content.res.AssetManager;
import android.net.Uri;
import androidx.media3.datasource.AssetDataSource$AssetDataSourceException;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

/* renamed from: ᵨˁᵝ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C3714 extends AbstractC1628 {

    /* renamed from: ˀᵗᵝᵭ, reason: contains not printable characters */
    public InputStream f13872;

    /* renamed from: ˑᵥˁ, reason: contains not printable characters */
    public boolean f13873;

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public long f13874;

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public Uri f13875;

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public final AssetManager f13876;

    public C3714(Context context) {
        super(false);
        this.f13876 = context.getAssets();
    }

    @Override // defpackage.InterfaceC2569
    public final void close() {
        this.f13875 = null;
        try {
            try {
                InputStream inputStream = this.f13872;
                if (inputStream != null) {
                    inputStream.close();
                }
            } catch (IOException e) {
                throw new AssetDataSource$AssetDataSourceException(2000, e);
            }
        } finally {
            this.f13872 = null;
            if (this.f13873) {
                this.f13873 = false;
                m4667();
            }
        }
    }

    @Override // defpackage.InterfaceC1463
    public final int read(byte[] bArr, int i, int i2) throws IOException {
        if (i2 == 0) {
            return 0;
        }
        long j = this.f13874;
        if (j != 0) {
            if (j != -1) {
                try {
                    i2 = (int) Math.min(j, i2);
                } catch (IOException e) {
                    throw new AssetDataSource$AssetDataSourceException(2000, e);
                }
            }
            InputStream inputStream = this.f13872;
            String str = AbstractC3558.f13329;
            int i3 = inputStream.read(bArr, i, i2);
            if (i3 != -1) {
                long j2 = this.f13874;
                if (j2 != -1) {
                    this.f13874 = j2 - i3;
                }
                m4668(i3);
                return i3;
            }
        }
        return -1;
    }

    @Override // defpackage.InterfaceC2569
    /* renamed from: ˏˋٴ */
    public final long mo1165(C4179 c4179) throws IOException {
        try {
            Uri uri = c4179.f15620;
            long j = c4179.f15616;
            this.f13875 = uri;
            String path = uri.getPath();
            path.getClass();
            if (path.startsWith("/android_asset/")) {
                path = path.substring(15);
            } else if (path.startsWith("/")) {
                path = path.substring(1);
            }
            m4666();
            InputStream inputStreamOpen = this.f13876.open(path, 1);
            this.f13872 = inputStreamOpen;
            if (inputStreamOpen.skip(j) < j) {
                throw new AssetDataSource$AssetDataSourceException(2008, null);
            }
            long j2 = c4179.f15618;
            if (j2 != -1) {
                this.f13874 = j2;
            } else {
                long jAvailable = this.f13872.available();
                this.f13874 = jAvailable;
                if (jAvailable == 2147483647L) {
                    this.f13874 = -1L;
                }
            }
            this.f13873 = true;
            m4669(c4179);
            return this.f13874;
        } catch (AssetDataSource$AssetDataSourceException e) {
            throw e;
        } catch (IOException e2) {
            throw new AssetDataSource$AssetDataSourceException(e2 instanceof FileNotFoundException ? 2005 : 2000, e2);
        }
    }

    @Override // defpackage.InterfaceC2569
    /* renamed from: ᵿʗᵝʽ */
    public final Uri mo1166() {
        return this.f13875;
    }
}
