Stream < String > getRessourceLines ( Class < ? > clazz , String filepath ) { try ( final BufferedReader fileReader = new BufferedReader ( new InputStreamReader ( clazz . getResourceAsStream ( filepath ) , StandardCharsets . UTF_8 ) ) ) { // Collect the read lines before converting back to a Java stream // so that we can ensure that we close the InputStream and prevent leaks return fileReader . lines ( ) . collect ( Collectors . toList ( ) ) . stream ( ) ; } catch ( IOException e ) { throw new RuntimeException ( e ) ; } }
Package protected for testing purposes