Search in sources :

Example 1 with SharedString

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;
    }
}
Also used : Arrays(java.util.Arrays) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) SharedString(livelessons.utils.SharedString) Files(java.nio.file.Files) Paths(java.nio.file.Paths) Predicate(java.util.function.Predicate) URI(java.net.URI) Pattern(java.util.regex.Pattern) SharedString(livelessons.utils.SharedString) SharedString(livelessons.utils.SharedString) URI(java.net.URI)

Aggregations

URI (java.net.URI)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Predicate (java.util.function.Predicate)1 Pattern (java.util.regex.Pattern)1 Collectors.toList (java.util.stream.Collectors.toList)1 SharedString (livelessons.utils.SharedString)1