package com.google.android.exoplayer2.upstream;

import android.net.Uri;
import android.text.TextUtils;
import java.io.EOFException;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
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 FileDataSource extends AbstractC4092 {

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public RandomAccessFile f1971;

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

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

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

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

        public FileDataSourceException(String str, IOException iOException) {
            super(str, iOException);
        }
    }

    public FileDataSource() {
        super(false);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static RandomAccessFile m1285(Uri uri) throws FileDataSourceException {
        try {
            String path = uri.getPath();
            C0567.m1856(path);
            return new RandomAccessFile(path, "r");
        } catch (FileNotFoundException e) {
            if (TextUtils.isEmpty(uri.getQuery()) && TextUtils.isEmpty(uri.getFragment())) {
                throw new FileDataSourceException(e);
            }
            throw new FileDataSourceException(String.format("uri has query and/or fragment, which are not supported. Did you call Uri.parse() on a string containing '?' or '#'? Use Uri.fromFile(new File(path)) to avoid this. path=%s,query=%s,fragment=%s", uri.getPath(), uri.getQuery(), uri.getFragment()), e);
        }
    }

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

    @Override // p138.p176.p177.p190.p238.InterfaceC4095
    /* JADX INFO: renamed from: ֏ */
    public int mo1282(byte[] bArr, int i, int i2) throws FileDataSourceException {
        if (i2 == 0) {
            return 0;
        }
        if (this.f1973 == 0) {
            return -1;
        }
        try {
            RandomAccessFile randomAccessFile = this.f1971;
            C4150.m6755(randomAccessFile);
            int i3 = randomAccessFile.read(bArr, i, (int) Math.min(this.f1973, i2));
            if (i3 > 0) {
                this.f1973 -= (long) i3;
                m6579(i3);
            }
            return i3;
        } catch (IOException e) {
            throw new FileDataSourceException(e);
        }
    }

    @Override // p138.p176.p177.p190.p238.InterfaceC4095
    /* JADX INFO: renamed from: ֏ */
    public long mo1283(C4098 c4098) throws FileDataSourceException {
        try {
            Uri uri = c4098.f13076;
            this.f1972 = uri;
            m6580(c4098);
            RandomAccessFile randomAccessFileM1285 = m1285(uri);
            this.f1971 = randomAccessFileM1285;
            randomAccessFileM1285.seek(c4098.f13081);
            long length = c4098.f13082 == -1 ? this.f1971.length() - c4098.f13081 : c4098.f13082;
            this.f1973 = length;
            if (length < 0) {
                throw new EOFException();
            }
            this.f1974 = true;
            m6582(c4098);
            return this.f1973;
        } catch (IOException e) {
            throw new FileDataSourceException(e);
        }
    }

    @Override // p138.p176.p177.p190.p238.InterfaceC4095
    /* JADX INFO: renamed from: ؠ */
    public Uri mo1284() {
        return this.f1972;
    }
}
