Here you can find the source of readFileOrResource(String source)
private static Reader readFileOrResource(String source)
//package com.java2s; // Licensed to the Software Freedom Conservancy (SFC) under one import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.util.Objects; import java.util.function.Function; import java.util.stream.Stream; public class Main { private static Reader readFileOrResource(String source) { Stream<Function<String, InputStream>> suppliers = Stream.of((path) -> { try { return new FileInputStream(path); } catch (FileNotFoundException e) { return null; }/*from ww w .j a v a2 s . c o m*/ }, (path) -> Thread.currentThread().getContextClassLoader() .getResourceAsStream("org/openqa/grid/common/" + path), (path) -> Thread.currentThread().getContextClassLoader().getResourceAsStream(path), (path) -> new ByteArrayInputStream(path.getBytes())); InputStream in = suppliers.map(supplier -> supplier.apply(source)).filter(Objects::nonNull).findFirst() .orElseThrow(() -> new RuntimeException("Resource or file not found: " + source)); return new BufferedReader(new InputStreamReader(in)); } }