mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add method
This commit is contained in:
@@ -61,10 +61,14 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------- 私有属性 start
|
||||
/** 属性文件的URL */
|
||||
/**
|
||||
* 属性文件的URL
|
||||
*/
|
||||
private URL propertiesFileUrl;
|
||||
private WatchMonitor watchMonitor;
|
||||
/** properties文件编码 */
|
||||
/**
|
||||
* properties文件编码
|
||||
*/
|
||||
private Charset charset = CharsetUtil.CHARSET_ISO_8859_1;
|
||||
// ----------------------------------------------------------------------- 私有属性 end
|
||||
|
||||
@@ -81,7 +85,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
/**
|
||||
* 获得Classpath下的Properties文件
|
||||
*
|
||||
* @param resource 资源(相对Classpath的路径)
|
||||
* @param resource 资源(相对Classpath的路径)
|
||||
* @param charsetName 字符集
|
||||
* @return Properties
|
||||
*/
|
||||
@@ -93,7 +97,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
* 获得Classpath下的Properties文件
|
||||
*
|
||||
* @param resource 资源(相对Classpath的路径)
|
||||
* @param charset 字符集
|
||||
* @param charset 字符集
|
||||
* @return Properties
|
||||
*/
|
||||
public static Props getProp(String resource, Charset charset) {
|
||||
@@ -101,6 +105,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------- 构造方法 start
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
@@ -119,7 +124,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
/**
|
||||
* 构造,使用相对于Class文件根目录的相对路径
|
||||
*
|
||||
* @param path 相对或绝对路径
|
||||
* @param path 相对或绝对路径
|
||||
* @param charsetName 字符集
|
||||
*/
|
||||
public Props(String path, String charsetName) {
|
||||
@@ -129,7 +134,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
/**
|
||||
* 构造,使用相对于Class文件根目录的相对路径
|
||||
*
|
||||
* @param path 相对或绝对路径
|
||||
* @param path 相对或绝对路径
|
||||
* @param charset 字符集
|
||||
*/
|
||||
public Props(String path, Charset charset) {
|
||||
@@ -153,7 +158,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
* 构造
|
||||
*
|
||||
* @param propertiesFile 配置文件对象
|
||||
* @param charsetName 字符集
|
||||
* @param charsetName 字符集
|
||||
*/
|
||||
public Props(File propertiesFile, String charsetName) {
|
||||
this(propertiesFile, Charset.forName(charsetName));
|
||||
@@ -163,7 +168,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
* 构造
|
||||
*
|
||||
* @param propertiesFile 配置文件对象
|
||||
* @param charset 字符集
|
||||
* @param charset 字符集
|
||||
*/
|
||||
public Props(File propertiesFile, Charset charset) {
|
||||
Assert.notNull(propertiesFile, "Null properties file!");
|
||||
@@ -174,7 +179,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
/**
|
||||
* 构造,相对于classes读取文件
|
||||
*
|
||||
* @param path 相对路径
|
||||
* @param path 相对路径
|
||||
* @param clazz 基准类
|
||||
*/
|
||||
public Props(String path, Class<?> clazz) {
|
||||
@@ -184,8 +189,8 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
/**
|
||||
* 构造,相对于classes读取文件
|
||||
*
|
||||
* @param path 相对路径
|
||||
* @param clazz 基准类
|
||||
* @param path 相对路径
|
||||
* @param clazz 基准类
|
||||
* @param charsetName 字符集
|
||||
*/
|
||||
public Props(String path, Class<?> clazz, String charsetName) {
|
||||
@@ -195,8 +200,8 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
/**
|
||||
* 构造,相对于classes读取文件
|
||||
*
|
||||
* @param path 相对路径
|
||||
* @param clazz 基准类
|
||||
* @param path 相对路径
|
||||
* @param clazz 基准类
|
||||
* @param charset 字符集
|
||||
*/
|
||||
public Props(String path, Class<?> clazz, Charset charset) {
|
||||
@@ -220,7 +225,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
* 构造,使用URL读取
|
||||
*
|
||||
* @param propertiesUrl 属性文件路径
|
||||
* @param charsetName 字符集
|
||||
* @param charsetName 字符集
|
||||
*/
|
||||
public Props(URL propertiesUrl, String charsetName) {
|
||||
this(propertiesUrl, CharsetUtil.charset(charsetName));
|
||||
@@ -230,7 +235,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
* 构造,使用URL读取
|
||||
*
|
||||
* @param propertiesUrl 属性文件路径
|
||||
* @param charset 字符集
|
||||
* @param charset 字符集
|
||||
*/
|
||||
public Props(URL propertiesUrl, Charset charset) {
|
||||
Assert.notNull(propertiesUrl, "Null properties URL !");
|
||||
@@ -494,6 +499,18 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
return (String) value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为标准的{@link Properties}对象
|
||||
*
|
||||
* @return {@link Properties}对象
|
||||
* @since 5.7.4
|
||||
*/
|
||||
public Properties toProperties() {
|
||||
final Properties properties = new Properties();
|
||||
properties.putAll(this);
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将配置文件转换为Bean,支持嵌套Bean<br>
|
||||
* 支持的表达式:
|
||||
@@ -506,7 +523,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
* ['person']['friends'][5]['name']
|
||||
* </pre>
|
||||
*
|
||||
* @param <T> Bean类型
|
||||
* @param <T> Bean类型
|
||||
* @param beanClass Bean类
|
||||
* @return Bean对象
|
||||
* @since 4.6.3
|
||||
@@ -527,9 +544,9 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
* ['person']['friends'][5]['name']
|
||||
* </pre>
|
||||
*
|
||||
* @param <T> Bean类型
|
||||
* @param <T> Bean类型
|
||||
* @param beanClass Bean类
|
||||
* @param prefix 公共前缀,不指定前缀传null,当指定前缀后非此前缀的属性被忽略
|
||||
* @param prefix 公共前缀,不指定前缀传null,当指定前缀后非此前缀的属性被忽略
|
||||
* @return Bean对象
|
||||
* @since 4.6.3
|
||||
*/
|
||||
@@ -550,8 +567,8 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
* ['person']['friends'][5]['name']
|
||||
* </pre>
|
||||
*
|
||||
* @param <T> Bean类型
|
||||
* @param bean Bean对象
|
||||
* @param <T> Bean类型
|
||||
* @param bean Bean对象
|
||||
* @param prefix 公共前缀,不指定前缀传null,当指定前缀后非此前缀的属性被忽略
|
||||
* @return Bean对象
|
||||
* @since 4.6.3
|
||||
@@ -562,7 +579,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
String key;
|
||||
for (java.util.Map.Entry<Object, Object> entry : this.entrySet()) {
|
||||
key = (String) entry.getKey();
|
||||
if(false == StrUtil.startWith(key, prefix)) {
|
||||
if (false == StrUtil.startWith(key, prefix)) {
|
||||
// 非指定开头的属性忽略掉
|
||||
continue;
|
||||
}
|
||||
@@ -580,10 +597,11 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
// ----------------------------------------------------------------------- Get end
|
||||
|
||||
// ----------------------------------------------------------------------- Set start
|
||||
|
||||
/**
|
||||
* 设置值,无给定键创建之。设置后未持久化
|
||||
*
|
||||
* @param key 属性键
|
||||
* @param key 属性键
|
||||
* @param value 属性值
|
||||
*/
|
||||
public void setProperty(String key, Object value) {
|
||||
@@ -611,7 +629,7 @@ public final class Props extends Properties implements BasicTypeGetter<String>,
|
||||
/**
|
||||
* 存储当前设置,会覆盖掉以前的设置
|
||||
*
|
||||
* @param path 相对路径
|
||||
* @param path 相对路径
|
||||
* @param clazz 相对的类
|
||||
*/
|
||||
public void store(String path, Class<?> clazz) {
|
||||
|
Reference in New Issue
Block a user