Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
</properties>

<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down Expand Up @@ -74,6 +69,11 @@
<version>1.9.54</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>rome</groupId>
<artifactId>rome</artifactId>
Expand Down Expand Up @@ -106,4 +106,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
30 changes: 16 additions & 14 deletions src/main/java/bg/bozho/ikratko/Checker.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package bg.bozho.ikratko;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand All @@ -10,10 +12,10 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import javax.annotation.PostConstruct;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -307,15 +309,11 @@ private boolean agreesOnPlurality(String word, String agreeingWord, Set<String>
}

public static void load() {
InputStream is = Checker.class.getResourceAsStream("/bg_BG.dic");
List<String> lines = null;

try {
lines = IOUtils.readLines(is, "utf-8");
List<String> lines;
try (InputStream is = Checker.class.getResourceAsStream("/bg_BG.dic")) {
lines = readUtf8Lines(is);
} catch (IOException ex) {
throw new IllegalStateException(ex);
} finally {
IOUtils.closeQuietly(is);
}

dictionary = new PatriciaTrie<Set<String>>();
Expand Down Expand Up @@ -405,13 +403,11 @@ public static void loadInflections() {
}

private static void fillInflectionClasses(Map<String, Multimap<String, String>> map, InputStream is) {
List<String> lines = null;
try {
lines = IOUtils.readLines(is, "utf-8");
List<String> lines;
try (InputStream autoClose = is) {
lines = readUtf8Lines(autoClose);
} catch (IOException ex) {
throw new IllegalStateException(ex);
} finally {
IOUtils.closeQuietly(is);
}

boolean newInflectionClass = false;
Expand Down Expand Up @@ -444,6 +440,12 @@ private static void fillInflectionClasses(Map<String, Multimap<String, String>>
}
}

private static List<String> readUtf8Lines(InputStream inputStream) throws IOException {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"))) {
return reader.lines().collect(Collectors.toList());
}
}

private static String[] charToStringArray(char[] array) {
String[] result = new String[array.length];
for (int i = 0; i < array.length; i ++) {
Expand Down Expand Up @@ -600,4 +602,4 @@ public boolean isVerb() {
return verb;
}
}
}
}