Optimize PropertiesUtils.java

This commit is contained in:
hongqiaowei
2021-12-23 16:32:00 +08:00
parent 0268eb00e0
commit 95e871f53c
2 changed files with 15 additions and 11 deletions

View File

@@ -1,9 +1,12 @@
package we.util;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.PropertyAccessor;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
@@ -16,6 +19,15 @@ public abstract class PropertiesUtils {
private PropertiesUtils() {
}
public static Properties from(String config) {
Resource resource = new ByteArrayResource(config.getBytes());
try {
return PropertiesLoaderUtils.loadProperties(resource);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static String normalize(String propertyName) {
char[] chars = propertyName.toCharArray();
StringBuilder b = new StringBuilder(chars.length);