Created
December 15, 2020 09:43
-
-
Save ClausPolanka/25181c19d1f34b75cb4ab9707b3b4481 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package wordcount.io; | |
import wordcount.domain.Stopwords; | |
import java.io.File; | |
import java.io.IOException; | |
import java.net.URL; | |
import java.nio.file.Files; | |
import java.util.Collection; | |
import static java.util.Collections.emptyList; | |
public class FileSystemStopwords implements Stopwords { | |
private String filePath; | |
public FileSystemStopwords(String filePath) { | |
this.filePath = filePath; | |
} | |
@Override | |
public Collection<String> stopwords() { | |
URL url = getClass().getClassLoader().getResource(filePath); | |
if (url == null) { | |
return emptyList(); | |
} | |
File f = new File(url.getFile()); | |
try { | |
return Files.readAllLines(f.toPath()); | |
} catch (IOException e) { | |
return emptyList(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment