WordFetcher.java (790B)
1 package com.wimdupont.service; 2 3 import com.wimdupont.config.ApplicationProperties; 4 5 import java.io.IOException; 6 import java.nio.file.Files; 7 import java.nio.file.Path; 8 import java.util.ArrayList; 9 import java.util.Arrays; 10 import java.util.List; 11 12 public class WordFetcher { 13 14 private final ApplicationProperties applicationProperties = ApplicationProperties.getInstance(); 15 16 public List<String> fetch() { 17 List<String> words = new ArrayList<>(); 18 try (var lines = Files.lines(Path.of(applicationProperties.getWordCsvDir()))) { 19 lines.forEach(line -> words.addAll(Arrays.stream(line.split(";")) 20 .map(String::trim).toList())); 21 } catch (IOException e) { 22 throw new RuntimeException(e); 23 } 24 return words; 25 } 26 }