use of livelessons.utils.SharedString in project LiveLessons by douglascraigschmidt.
the class TestDataFactory method getSharedInput.
/**
* Return the input data in the given @a filename as a list of
* SharedStrings.
*/
public static List<CharSequence> getSharedInput(String filename, String splitter) {
try {
// Convert the filename into a pathname.
URI uri = ClassLoader.getSystemResource(filename).toURI();
// Open the file and get all the bytes.
CharSequence bytes = new String(Files.readAllBytes(Paths.get(uri)));
return // the file into a list of Strings.
Pattern.compile(splitter).splitAsStream(bytes).filter(((Predicate<String>) String::isEmpty).negate()).map(string -> new SharedString(string.toCharArray())).collect(toList());
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
Aggregations