package g.d.a.u;

import g.d.a.k;
import g.d.a.o;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;

/* JADX INFO: loaded from: classes.dex */
public class c implements o {
    @Override // g.d.a.o
    public Reader a(String str) {
        FileInputStream fileInputStream;
        File file = new File(str);
        if (file.exists() && file.isFile()) {
            try {
                File canonicalFile = new File("").getCanonicalFile();
                File canonicalFile2 = file.getCanonicalFile();
                do {
                    canonicalFile2 = canonicalFile2.getParentFile();
                    if (canonicalFile2 == null) {
                        break;
                    }
                } while (!canonicalFile2.equals(canonicalFile));
                if (canonicalFile2 == null) {
                    throw new k("File not under root: " + canonicalFile.getAbsolutePath());
                }
                fileInputStream = new FileInputStream(file);
            } catch (IOException e2) {
                throw new k("Found file, could not open: " + file, e2);
            }
        } else {
            fileInputStream = null;
        }
        if (fileInputStream != null) {
            return new BufferedReader(new InputStreamReader(fileInputStream, StandardCharsets.UTF_8));
        }
        return null;
    }
}
