| 1 |
package io.github.dan2097.jnarinchi; |
| 2 |
|
| 3 |
import java.io.BufferedReader; |
| 4 |
import java.io.IOException; |
| 5 |
import java.io.InputStreamReader; |
| 6 |
import java.util.Arrays; |
| 7 |
import java.util.List; |
| 8 |
|
| 9 |
/** |
| 10 |
* @author Nikolay Kochev |
| 11 |
* @author Uli Fechner |
| 12 |
*/ |
| 13 |
public class TestUtils { |
| 14 |
public static final String LINE_SEPARATOR_NEWLINE = "\n"; |
| 15 |
|
| 16 |
/** |
| 17 |
* Read a text file into a string. |
| 18 |
* |
| 19 |
* @param fileName name of the text file to read |
| 20 |
* @return file content as a single string |
| 21 |
*/ |
| 22 |
public static String readTextFromResourceAsString(String fileName) throws IOException { |
| 23 |
BufferedReader br = new BufferedReader(new InputStreamReader(TestUtils.class.getResourceAsStream(fileName))); |
| 24 |
StringBuilder sb = new StringBuilder(); |
| 25 |
String line; |
| 26 |
while ((line = br.readLine()) != null) { |
| 27 |
sb.append(line).append(LINE_SEPARATOR_NEWLINE); |
| 28 |
} |
| 29 |
|
| 30 |
// clean up |
| 31 |
br.close(); |
| 32 |
|
| 33 |
return sb.toString(); |
| 34 |
} |
| 35 |
|
| 36 |
public static List<String> readTextFromResourceAsList(String filename) throws IOException { |
| 37 |
return Arrays.asList(readTextFromResourceAsString(filename).split(LINE_SEPARATOR_NEWLINE)); |
| 38 |
} |
| 39 |
} |