mirror of
https://github.com/houbb/sensitive-word.git
synced 2026-03-22 08:27:36 +08:00
release branch 0.27.1
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
package com.github.houbb.sensitive.word.support.allow;
|
||||
|
||||
import com.github.houbb.heaven.annotation.ThreadSafe;
|
||||
import com.github.houbb.heaven.util.io.StreamUtil;
|
||||
import com.github.houbb.sensitive.word.api.IWordAllow;
|
||||
import com.github.houbb.sensitive.word.api.IWordDeny;
|
||||
import com.github.houbb.sensitive.word.utils.InnerStreamUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -26,7 +25,7 @@ public class WordAllowSystem implements IWordAllow {
|
||||
|
||||
@Override
|
||||
public List<String> allow() {
|
||||
return StreamUtil.readAllLines("/sensitive_word_allow.txt");
|
||||
return InnerStreamUtils.readAllLines("/sensitive_word_allow.txt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.github.houbb.sensitive.word.support.deny;
|
||||
|
||||
import com.github.houbb.heaven.annotation.ThreadSafe;
|
||||
import com.github.houbb.heaven.util.io.StreamUtil;
|
||||
import com.github.houbb.sensitive.word.api.IWordDeny;
|
||||
import com.github.houbb.sensitive.word.utils.InnerStreamUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -25,9 +25,9 @@ public class WordDenySystem implements IWordDeny {
|
||||
|
||||
@Override
|
||||
public List<String> deny() {
|
||||
List<String> results = StreamUtil.readAllLines("/sensitive_word_dict.txt");
|
||||
results.addAll(StreamUtil.readAllLines("/sensitive_word_dict_en.txt"));
|
||||
results.addAll(StreamUtil.readAllLines("/sensitive_word_deny.txt"));
|
||||
List<String> results = InnerStreamUtils.readAllLines("/sensitive_word_dict.txt");
|
||||
results.addAll(InnerStreamUtils.readAllLines("/sensitive_word_dict_en.txt"));
|
||||
results.addAll(InnerStreamUtils.readAllLines("/sensitive_word_deny.txt"));
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.github.houbb.sensitive.word.support.tag;
|
||||
|
||||
import com.github.houbb.heaven.util.io.StreamUtil;
|
||||
import com.github.houbb.sensitive.word.api.IWordTag;
|
||||
import com.github.houbb.sensitive.word.utils.InnerStreamUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -16,7 +16,7 @@ public class WordTagSystem extends AbstractWordTag {
|
||||
private final IWordTag wordTag;
|
||||
|
||||
public WordTagSystem() {
|
||||
List<String> lines = StreamUtil.readAllLines("/sensitive_word_tags.txt");
|
||||
List<String> lines = InnerStreamUtils.readAllLines("/sensitive_word_tags.txt");
|
||||
this.wordTag = WordTags.lines(lines);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.github.houbb.sensitive.word.utils;
|
||||
|
||||
import com.github.houbb.heaven.util.io.StreamUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @since 0.27.1
|
||||
*/
|
||||
public class InnerStreamUtils {
|
||||
|
||||
/**
|
||||
* 获取文件,兼容为空的场景
|
||||
* @param path 路径
|
||||
* @return 结果
|
||||
*/
|
||||
public static List<String> readAllLines(String path) {
|
||||
try(InputStream inputStream = StreamUtil.class.getResourceAsStream(path);) {
|
||||
if(inputStream == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return StreamUtil.readAllLines(path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user