Skip to content

Instantly share code, notes, and snippets.

@ClausPolanka
Created December 15, 2020 09:43
Show Gist options
  • Save ClausPolanka/25181c19d1f34b75cb4ab9707b3b4481 to your computer and use it in GitHub Desktop.
Save ClausPolanka/25181c19d1f34b75cb4ab9707b3b4481 to your computer and use it in GitHub Desktop.
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