You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2023/04/11 00:08:18 UTC
[shardingsphere] branch master updated: Remove UnstableApiUsage on CharDigestLikeEncryptAlgorithm (#25086)
This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 244dd188db6 Remove UnstableApiUsage on CharDigestLikeEncryptAlgorithm (#25086)
244dd188db6 is described below
commit 244dd188db6911d5d1f2ac31d946afe9169a404c
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Tue Apr 11 08:08:00 2023 +0800
Remove UnstableApiUsage on CharDigestLikeEncryptAlgorithm (#25086)
* Remove UnstableApiUsage on CharDigestLikeEncryptAlgorithm
* Remove UnstableApiUsage on CharDigestLikeEncryptAlgorithm
* Remove UnstableApiUsage on CharDigestLikeEncryptAlgorithm
---
.../like/CharDigestLikeEncryptAlgorithm.java | 50 ++++++++--------------
1 file changed, 18 insertions(+), 32 deletions(-)
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/like/CharDigestLikeEncryptAlgorithm.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/like/CharDigestLikeEncryptAlgorithm.java
index edabec91b15..887a55bcd5b 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/like/CharDigestLikeEncryptAlgorithm.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/like/CharDigestLikeEncryptAlgorithm.java
@@ -17,25 +17,24 @@
package org.apache.shardingsphere.encrypt.algorithm.like;
-import com.google.common.base.Charsets;
import com.google.common.base.Strings;
-import com.google.common.io.CharStreams;
-import com.google.common.io.LineProcessor;
import lombok.SneakyThrows;
-import org.apache.shardingsphere.encrypt.spi.LikeEncryptAlgorithm;
-import org.apache.shardingsphere.encrypt.exception.algorithm.EncryptAlgorithmInitializationException;
import org.apache.shardingsphere.encrypt.api.context.EncryptContext;
+import org.apache.shardingsphere.encrypt.exception.algorithm.EncryptAlgorithmInitializationException;
+import org.apache.shardingsphere.encrypt.spi.LikeEncryptAlgorithm;
+import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.HashMap;
import java.util.Map;
+import java.util.Objects;
import java.util.Properties;
+import java.util.Scanner;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
/**
* Char digest like encrypt algorithm.
*/
-@SuppressWarnings("UnstableApiUsage")
public final class CharDigestLikeEncryptAlgorithm implements LikeEncryptAlgorithm<Object, String> {
private static final String DELTA = "delta";
@@ -108,36 +107,23 @@ public final class CharDigestLikeEncryptAlgorithm implements LikeEncryptAlgorith
private Map<Character, Integer> createCharIndexes(final Properties props) {
String dictContent = props.containsKey(DICT) && !Strings.isNullOrEmpty(props.getProperty(DICT)) ? props.getProperty(DICT) : initDefaultDict();
- Map<Character, Integer> result = new HashMap<>(dictContent.length(), 1);
- for (int index = 0; index < dictContent.length(); index++) {
- result.put(dictContent.charAt(index), index);
- }
- return result;
+ return IntStream.range(0, dictContent.length()).boxed().collect(Collectors.toMap(dictContent::charAt, index -> index, (a, b) -> b));
}
- @SneakyThrows
+ @SneakyThrows(IOException.class)
private String initDefaultDict() {
- InputStream inputStream = CharDigestLikeEncryptAlgorithm.class.getClassLoader().getResourceAsStream("algorithm/like/common_chinese_character.dict");
- LineProcessor<String> lineProcessor = new LineProcessor<String>() {
-
- private final StringBuilder builder = new StringBuilder();
-
- @Override
- public boolean processLine(final String line) {
- if (line.startsWith("#") || 0 == line.length()) {
- return true;
- } else {
+ StringBuilder builder = new StringBuilder();
+ try (
+ InputStream inputStream = Objects.requireNonNull(CharDigestLikeEncryptAlgorithm.class.getClassLoader().getResourceAsStream("algorithm/like/common_chinese_character.dict"));
+ Scanner scanner = new Scanner(inputStream)) {
+ while (scanner.hasNextLine()) {
+ String line = scanner.nextLine();
+ if (!line.isEmpty() && !line.startsWith("#")) {
builder.append(line);
- return false;
}
}
-
- @Override
- public String getResult() {
- return builder.toString();
- }
- };
- return CharStreams.readLines(new InputStreamReader(inputStream, Charsets.UTF_8), lineProcessor);
+ }
+ return builder.toString();
}
@Override