Skip to content

Apache Lucene open-source search software

LUCENE-2564: Cut over WordListLoader to CharArrayMap/Set and use CharSetDecoder to detect encoding problems early

Simon Willnauerc0a7abbec095
diff --git a/modules/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/SmartChineseAnalyzer.java b/modules/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/SmartChineseAnalyzer.java
index 8de8b34d567..7710209b863 100644
--- a/modules/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/SmartChineseAnalyzer.java
+++ b/modules/analysis/smartcn/src/java/org/apache/lucene/analysis/cn/smart/SmartChineseAnalyzer.java
@@ -33,6 +33,7 @@ import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.cn.smart.SentenceTokenizer;
import org.apache.lucene.analysis.cn.smart.WordTokenFilter;
import org.apache.lucene.analysis.core.StopFilter;
+import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.Version;
/**
@@ -89,16 +90,11 @@ public final class SmartChineseAnalyzer extends Analyzer {
}
static CharArraySet loadDefaultStopWordSet() throws IOException {
- InputStream stream = SmartChineseAnalyzer.class
- .getResourceAsStream(DEFAULT_STOPWORD_FILE);
- try {
- InputStreamReader reader = new InputStreamReader(stream, "UTF-8");
- // make sure it is unmodifiable as we expose it in the outer class
- return CharArraySet.unmodifiableSet(WordlistLoader.getWordSet(reader,
- STOPWORD_FILE_COMMENT, Version.LUCENE_CURRENT));
- } finally {
- stream.close();
- }
+ // make sure it is unmodifiable as we expose it in the outer class
+ return CharArraySet.unmodifiableSet(WordlistLoader.getWordSet(IOUtils
+ .getDecodingReader(SmartChineseAnalyzer.class, DEFAULT_STOPWORD_FILE,
+ IOUtils.CHARSET_UTF_8), STOPWORD_FILE_COMMENT,
+ Version.LUCENE_CURRENT));
}
}