diff --git a/src/main/java/walaniam/scrabble/dictionary/set/WordsReader.java b/src/main/java/walaniam/scrabble/dictionary/set/WordsReader.java index 58a5e70..a3141fd 100644 --- a/src/main/java/walaniam/scrabble/dictionary/set/WordsReader.java +++ b/src/main/java/walaniam/scrabble/dictionary/set/WordsReader.java @@ -49,19 +49,30 @@ public void read(Consumer consumer) throws IOException { if (!Character.isWhitespace(c)) { wordBuffer.append(c); } else { - consumer.accept(READ_BUFFER.apply(wordBuffer)); - wordsLoaded++; + if (consume(consumer, wordBuffer)) { + wordsLoaded++; + } } } } - consumer.accept(READ_BUFFER.apply(wordBuffer)); - wordsLoaded++; + if (consume(consumer, wordBuffer)) { + wordsLoaded++; + } } log.debug("{} words loaded in {} ms", wordsLoaded, System.currentTimeMillis() - start); } + private boolean consume(Consumer consumer, StringBuilder buffer) { + String word = READ_BUFFER.apply(buffer); + if (word != null && word.length() > 0) { + consumer.accept(word); + return true; + } + return false; + } + private Reader readWithEncoding(InputStream input) throws IOException { BufferedInputStream bis = new BufferedInputStream(input);