Skip to content

Commit

Permalink
Merge 3a55a3a into 6c4ac96
Browse files Browse the repository at this point in the history
  • Loading branch information
simonschiller committed Jul 4, 2019
2 parents 6c4ac96 + 3a55a3a commit 7e4f38d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/main/java/com/nulabinc/zxcvbn/matchers/Dictionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
Expand All @@ -14,7 +15,7 @@

public class Dictionary {

private static final String RESOURCES_PACKAGE_PATH = "/com/nulabinc/zxcvbn/matchers/dictionarys/";
private static final String RESOURCES_PACKAGE_PATH = "com/nulabinc/zxcvbn/matchers/dictionarys/";

private static final String EXT = ".txt";

Expand All @@ -40,8 +41,8 @@ private static Map<String, String[]> read() {
Map<String, String[]> freqLists = new HashMap<>();
for (String filename: DICTIONARY_PARAMS) {
List<String> words = new ArrayList<>();
try(InputStream is = Dictionary.class.getResourceAsStream(buildResourcePath(filename));
BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));) {
try(InputStream is = ClassLoader.getSystemResourceAsStream(buildResourcePath(filename));
BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
String line;
while ((line = br.readLine()) != null) {
words.add(line);
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/com/nulabinc/zxcvbn/matchers/Keyboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@

public class Keyboard {

private static final String RESOURCES_PACKAGE_PATH = "com/nulabinc/zxcvbn/matchers/keyboards/";

public static final Keyboard QWERTY =
new Keyboard("qwerty", new SlantedAdjacentGraphBuilder(loadAsString("keyboards/qwerty.txt")));
new Keyboard("qwerty", new SlantedAdjacentGraphBuilder(loadAsString("qwerty.txt")));

public static final Keyboard DVORAK =
new Keyboard("dvorak", new SlantedAdjacentGraphBuilder(loadAsString("keyboards/dvorak.txt")));
new Keyboard("dvorak", new SlantedAdjacentGraphBuilder(loadAsString("dvorak.txt")));

public static final Keyboard JIS =
new Keyboard("jis", new SlantedAdjacentGraphBuilder(loadAsString("keyboards/jis.txt")));
new Keyboard("jis", new SlantedAdjacentGraphBuilder(loadAsString("jis.txt")));

public static final Keyboard KEYPAD =
new Keyboard("keypad", new AlignedAdjacentAdjacentGraphBuilder(loadAsString("keyboards/keypad.txt")));
new Keyboard("keypad", new AlignedAdjacentAdjacentGraphBuilder(loadAsString("keypad.txt")));

public static final Keyboard MAC_KEYPAD =
new Keyboard("mac_keypad", new AlignedAdjacentAdjacentGraphBuilder(loadAsString("keyboards/mac_keypad.txt")));
new Keyboard("mac_keypad", new AlignedAdjacentAdjacentGraphBuilder(loadAsString("mac_keypad.txt")));

public static final List<Keyboard> ALL_KEYBOARDS = Arrays.asList(QWERTY, DVORAK, JIS, KEYPAD, MAC_KEYPAD);

Expand Down Expand Up @@ -69,8 +71,8 @@ private static double calcAverageDegree(final Map<Character, List<String>> adjac
}

private static String loadAsString(final String name) {
try (final InputStream input = Keyboard.class.getResourceAsStream(name);
final BufferedReader reader = new BufferedReader(new InputStreamReader(input, "UTF-8"))) {
try (final InputStream input = ClassLoader.getSystemResourceAsStream(RESOURCES_PACKAGE_PATH + name);
final BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))) {
final StringBuilder sb = new StringBuilder(1024 * 4);
String str;
while ((str = reader.readLine()) != null) {
Expand Down

0 comments on commit 7e4f38d

Please sign in to comment.