/*
Path{String} => ReadableStream
Given a path we try to open file
if ok return stream
if not
we try to pump from _stdio
return empty stream
504882
function dumpAndWrap(fName /*, localDir:string*/, sourceToDump) {
    let p = new Promise(function (resolve) {
        fs.stat(fName, (err, stat) => {
            if (!err) {
                if (stat.isFile()) {
                    logger.debug(`Found a file to wrap at ${fName}`);
                    let stream = fs.createReadStream(fName, {
                        'encoding': 'utf8'
                    });
                    resolve(stream);
                    return;
                }
                logger.error(`Should not be here:\n ${util.format(stat)}`);
            }
            else {
                logger.warn(`cant find file ${fName}`);
                if (sourceToDump) {
                    logger.debug(`Found alternative source dumping it from \n ${util.format(sourceToDump)}`);
                    let target = fs.createWriteStream(fName, { 'flags': 'a' });
                    sourceToDump.pipe(target);
                    target.on('close', () => {
                        let stream = fs.createReadStream(fName, {
                            'encoding': 'utf8'
                        });
                        logger.debug(`should resolve with ${util.format(stream)}`);
                        resolve(stream);
                        return;
                    });
                }
                else {
                    logger.error("Output file error, Still cant open output file, returning empy stream");
                    let dummyStream = new streamLib.Readable();
                    dummyStream.push(null);
                    resolve(dummyStream);
                    return;
                }
            }
        });
    });
    return p;
}
1292566
function fsRead(filePath) {
    return new Promise((resolve, reject) => {
        fs.readFile(filePath, (err, data) => {
            if (err) {
                if (err.syscall === 'open') {
                    console.log('Open "' + err.path +'" fail!')
                }
                reject(err);
            }
            resolve(data.toString())
        })
    })
}
1154611
protected InputStream getInputStream (String path)
        throws IOException
    {
        FileInputStream fis = new FileInputStream(path);
        return new BufferedInputStream(fis);
    }
1261044
function _gpfReadNashorn (path) {
    var javaPath = java.nio.file.Paths.get(path);
    if (java.nio.file.Files.exists(javaPath)) {
        return new Promise(function (resolve, reject) {
            var javaInputStream = java.nio.file.Files.newInputStream(javaPath),
                iStreamReader = new _GpfStreamJavaReadable(javaInputStream),
                iWritableString = new _GpfStreamWritableString();
            return iStreamReader.read(iWritableString)
                .then(function () {
                    resolve(iWritableString.toString());
                })["catch"](reject);
        });
    }
    return Promise.reject(new Error("File not found")); // To be improved
}
576412
def _file_read(path):
    '''
    
    '''
    content = False
    if os.path.exists(path):
        with salt.utils.files.fopen(path, 'r+') as fp_:
            content = salt.utils.stringutils.to_unicode(fp_.read())
        fp_.close()
    return content
926204
function getFile(path) {
	const
		cache = validateCache(path, filesCache);

	if (!cache.fromCache) {
		filesCache[path] = {
			mtime: cache.mtime,
			content: fs.readFileSync(path, 'utf-8')
		};
	}

	return filesCache[path].content;
}
465946
def read_file(path):
    
    if os.path.isabs(path):
        with wrap_file_exceptions():
            with open(path, 'rb') as stream:
                return stream.read()

    with wrap_file_exceptions():
        stream = ca_storage.open(path)

    try:
        return stream.read()
    finally:
        stream.close()
844576
def read_file(path):
    
    with open(must_exist(path)) as infile:
        r = infile.read()
    return r
814509
public static String readResourceAsStream(String path) {
        try {
            InputStream inputStream = ResourceUtil.getResourceAsStream(path);
            return ResourceUtil.readFromInputStreamIntoString(inputStream);
        } catch (Exception e) {
            throw new DataUtilException("Failed to load resource", e);
        }
    }
189296
public static boolean canOpenReadOnly(String path) {
        try {
            // Use open(2) rather than stat(2) so we require fewer permissions. http://b/6485312.
            FileDescriptor fd = Libcore.os.open(path, O_RDONLY, 0);
            Libcore.os.close(fd);
            return true;
        } catch (ErrnoException errnoException) {
            return false;
        }
    }
317774
function(path){
      var fullPath = []; 
      try{
        var files = fs.readdirSync(path); 
        for(var i = 0; i < files.length; i++){
          fullPath.push(path + '/' + files[i]); 
        }
        return fullPath; 
      }catch(e){
        return [];
      }
    }
39156
function (/*String*/path, /*String?*/encoding) {
        if (encoding === 'utf-8') {
            encoding = 'utf8';
        }
        if (!encoding) {
            encoding = 'utf8';
        }

        return fs.readFileSync(path, encoding);
    }
1095197
function readdir(path) {
	var stats = fs.lstatSync(path);
	var files = null;
	if (stats.isDirectory()) {
		fileNames = fs.readdirSync(path);
		files = _.map(fileNames, function(f) { return path + '/' + f; });
	} else {
		files = [];
	}
	return files;
}
249647
def file_can_be_read(path):
    
    if path is None:
        return False
    try:
        with io.open(path, "rb") as test_file:
            pass
        return True
    except (IOError, OSError):
        pass
    return False
826267
public static String fileToString(FileSystem fs, Path path) throws IOException {
		if(!fs.exists(path)) {
			return null;
		}

		InputStream is = fs.open(path);
		InputStreamReader isr = new InputStreamReader(is);
		BufferedReader br = new BufferedReader(isr);
		char[] buff = new char[256];
		StringBuilder sb = new StringBuilder();
		int read;
		while((read = br.read(buff)) != -1) {
			sb.append(buff, 0, read);
		}
		br.close();
		return sb.toString();
	}
1015512
private static BufferedReader open(final String path) throws IOException {
    if (path.equals("-")) {
      return new BufferedReader(new InputStreamReader(System.in));
    }

    InputStream is = new FileInputStream(path);
    if (path.endsWith(".gz")) {
      is = new GZIPInputStream(is);
    }
    // I <3 Java's IO library.
    return new BufferedReader(new InputStreamReader(is));
  }
605833
function readJSON(path) {
  return new Promise(function ($return, $error) {
    var file, parsed;
    return Promise.resolve(read(path)).then(function ($await_1) {
      try {
        file = $await_1;
        parsed = JSON.parse(file);
        return $return(parsed);
      } catch ($boundEx) {
        return $error($boundEx);
      }
    }.bind(this), $error);
  }.bind(this));
}