package com.google.android.exoplayer2.upstream;

import android.content.Context;
import android.content.res.AssetManager;
import android.net.Uri;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import p000.p001.p002.p003.p004.C0567;
import p138.p176.p177.p190.p238.AbstractC4092;
import p138.p176.p177.p190.p238.C4098;
import p138.p176.p177.p190.p239.C4150;

/* JADX INFO: loaded from: classes.dex */
public final class AssetDataSource extends AbstractC4092 {

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public final AssetManager f1960;

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public Uri f1961;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public InputStream f1962;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public long f1963;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public boolean f1964;

    public static final class AssetDataSourceException extends IOException {
        public AssetDataSourceException(IOException iOException) {
            super(iOException);
        }
    }

    public AssetDataSource(Context context) {
        super(false);
        this.f1960 = context.getAssets();
    }

    @Override // p138.p176.p177.p190.p238.InterfaceC4095
    public void close() {
        this.f1961 = null;
        try {
            try {
                if (this.f1962 != null) {
                    this.f1962.close();
                }
            } catch (IOException e) {
                throw new AssetDataSourceException(e);
            }
        } finally {
            this.f1962 = null;
            if (this.f1964) {
                this.f1964 = false;
                m6581();
            }
        }
    }

    @Override // p138.p176.p177.p190.p238.InterfaceC4095
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public int mo1282(byte[] bArr, int i, int i2) throws AssetDataSourceException {
        if (i2 == 0) {
            return 0;
        }
        long j = this.f1963;
        if (j == 0) {
            return -1;
        }
        if (j != -1) {
            try {
                i2 = (int) Math.min(j, i2);
            } catch (IOException e) {
                throw new AssetDataSourceException(e);
            }
        }
        InputStream inputStream = this.f1962;
        C4150.m6755(inputStream);
        int i3 = inputStream.read(bArr, i, i2);
        if (i3 == -1) {
            if (this.f1963 == -1) {
                return -1;
            }
            throw new AssetDataSourceException(new EOFException());
        }
        long j2 = this.f1963;
        if (j2 != -1) {
            this.f1963 = j2 - ((long) i3);
        }
        m6579(i3);
        return i3;
    }

    @Override // p138.p176.p177.p190.p238.InterfaceC4095
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public long mo1283(C4098 c4098) throws AssetDataSourceException {
        try {
            Uri uri = c4098.f13076;
            this.f1961 = uri;
            String path = uri.getPath();
            C0567.m1856(path);
            String strSubstring = path;
            if (strSubstring.startsWith("/android_asset/")) {
                strSubstring = strSubstring.substring(15);
            } else if (strSubstring.startsWith("/")) {
                strSubstring = strSubstring.substring(1);
            }
            m6580(c4098);
            InputStream inputStreamOpen = this.f1960.open(strSubstring, 1);
            this.f1962 = inputStreamOpen;
            if (inputStreamOpen.skip(c4098.f13081) < c4098.f13081) {
                throw new EOFException();
            }
            if (c4098.f13082 != -1) {
                this.f1963 = c4098.f13082;
            } else {
                long jAvailable = this.f1962.available();
                this.f1963 = jAvailable;
                if (jAvailable == 2147483647L) {
                    this.f1963 = -1L;
                }
            }
            this.f1964 = true;
            m6582(c4098);
            return this.f1963;
        } catch (IOException e) {
            throw new AssetDataSourceException(e);
        }
    }

    @Override // p138.p176.p177.p190.p238.InterfaceC4095
    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public Uri mo1284() {
        return this.f1961;
    }
}
