mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
merge conflict
This commit is contained in:
17
CHANGELOG.md
17
CHANGELOG.md
@@ -3,15 +3,30 @@
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 5.6.7 (2021-06-02)
|
||||
# 5.6.8 (2021-06-09)
|
||||
|
||||
### 🐣新特性
|
||||
|
||||
### 🐞Bug修复
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 5.6.7 (2021-06-08)
|
||||
|
||||
### 🐣新特性
|
||||
* 【core 】 CharSequenceUtil增加join重载(issue#I3TFJ5@Gitee)
|
||||
* 【http 】 HttpRequest增加form方法重载(pr#337@Gitee)
|
||||
* 【http 】 ImgUtil增加getMainColor方法(pr#338@Gitee)
|
||||
* 【core 】 改进TreeUtil.buid算法性能(pr#1594@Github)
|
||||
* 【core 】 CsvConfig的setXXX返回this(issue#I3UIQF@Gitee)
|
||||
* 【all 】 增加jmh基准测试
|
||||
* 【core 】 增加StreamUtil和CollectorUtil
|
||||
* 【poi 】 增加content-type(pr#1639@Github)
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【core 】 修复FileUtil.normalize去掉末尾空格问题(issue#1603@Github)
|
||||
* 【core 】 修复CharsetDetector流关闭问题(issue#1603@Github)
|
||||
* 【core 】 修复RuntimeUtil.exec引号内空格被切分的问题(issue#I3UAYB@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -122,18 +122,18 @@ Each module can be introduced individually, or all modules can be introduced by
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.6.7</version>
|
||||
<version>5.6.8</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### 🍐Gradle
|
||||
```
|
||||
compile 'cn.hutool:hutool-all:5.6.7'
|
||||
compile 'cn.hutool:hutool-all:5.6.8'
|
||||
```
|
||||
|
||||
## 📥Download
|
||||
|
||||
- [Maven Repo](https://repo1.maven.org/maven2/cn/hutool/hutool-all/5.6.7/)
|
||||
- [Maven Repo](https://repo1.maven.org/maven2/cn/hutool/hutool-all/5.6.8/)
|
||||
|
||||
> 🔔️note:
|
||||
> Hutool 5.x supports JDK8+ and is not tested on Android platforms, and cannot guarantee that all tool classes or tool methods are available.
|
||||
|
||||
@@ -120,20 +120,20 @@ Hutool的存在就是为了减少代码搜索成本,避免网络上参差不
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.6.7</version>
|
||||
<version>5.6.8</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
### 🍐Gradle
|
||||
```
|
||||
compile 'cn.hutool:hutool-all:5.6.7'
|
||||
compile 'cn.hutool:hutool-all:5.6.8'
|
||||
```
|
||||
|
||||
### 📥下载jar
|
||||
|
||||
点击以下链接,下载`hutool-all-X.X.X.jar`即可:
|
||||
|
||||
- [Maven中央库](https://repo1.maven.org/maven2/cn/hutool/hutool-all/5.6.7/)
|
||||
- [Maven中央库](https://repo1.maven.org/maven2/cn/hutool/hutool-all/5.6.8/)
|
||||
|
||||
> 🔔️注意
|
||||
> Hutool 5.x支持JDK8+,对Android平台没有测试,不能保证所有工具类或工具方法可用。
|
||||
|
||||
@@ -1 +1 @@
|
||||
5.6.7
|
||||
5.6.8
|
||||
|
||||
@@ -1 +1 @@
|
||||
var version = '5.6.7'
|
||||
var version = '5.6.8'
|
||||
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-parent</artifactId>
|
||||
<version>5.6.7-SNAPSHOT</version>
|
||||
<version>5.6.8-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>hutool-all</artifactId>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-parent</artifactId>
|
||||
<version>5.6.7-SNAPSHOT</version>
|
||||
<version>5.6.8-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>hutool-aop</artifactId>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-parent</artifactId>
|
||||
<version>5.6.7-SNAPSHOT</version>
|
||||
<version>5.6.8-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>hutool-bloomFilter</artifactId>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-parent</artifactId>
|
||||
<version>5.6.7-SNAPSHOT</version>
|
||||
<version>5.6.8-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>hutool-bom</artifactId>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-parent</artifactId>
|
||||
<version>5.6.7-SNAPSHOT</version>
|
||||
<version>5.6.8-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>hutool-cache</artifactId>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-parent</artifactId>
|
||||
<version>5.6.7-SNAPSHOT</version>
|
||||
<version>5.6.8-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>hutool-captcha</artifactId>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-parent</artifactId>
|
||||
<version>5.6.7-SNAPSHOT</version>
|
||||
<version>5.6.8-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>hutool-core</artifactId>
|
||||
|
||||
@@ -273,19 +273,19 @@ public class BeanDesc implements Serializable {
|
||||
if (fieldName.startsWith("is")) {
|
||||
// 字段已经是is开头
|
||||
if (methodName.equals(fieldName) // isName -》 isName
|
||||
|| methodName.equals("get" + handledFieldName)// isName -》 getIsName
|
||||
|| methodName.equals("is" + handledFieldName)// isName -》 isIsName
|
||||
|| ("get" + handledFieldName).equals(methodName)// isName -》 getIsName
|
||||
|| ("is" + handledFieldName).equals(methodName)// isName -》 isIsName
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
} else if (methodName.equals("is" + handledFieldName)) {
|
||||
} else if (("is" + handledFieldName).equals(methodName)) {
|
||||
// 字段非is开头, name -》 isName
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// 包括boolean的任何类型只有一种匹配情况:name -》 getName
|
||||
return methodName.equals("get" + handledFieldName);
|
||||
return ("get" + handledFieldName).equals(methodName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -324,15 +324,15 @@ public class BeanDesc implements Serializable {
|
||||
// 针对Boolean类型特殊检查
|
||||
if (isBooleanField && fieldName.startsWith("is")) {
|
||||
// 字段是is开头
|
||||
if (methodName.equals("set" + StrUtil.removePrefix(fieldName, "is"))// isName -》 setName
|
||||
|| methodName.equals("set" + handledFieldName)// isName -》 setIsName
|
||||
if (("set" + StrUtil.removePrefix(fieldName, "is")).equals(methodName)// isName -》 setName
|
||||
|| ("set" + handledFieldName).equals(methodName)// isName -》 setIsName
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// 包括boolean的任何类型只有一种匹配情况:name -》 setName
|
||||
return methodName.equals("set" + fieldName);
|
||||
return ("set" + fieldName).equals(methodName);
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------------ Private method end
|
||||
}
|
||||
|
||||
@@ -938,7 +938,7 @@ public class HashCodeBuilder implements Builder<Integer> {
|
||||
*/
|
||||
@Override
|
||||
public Integer build() {
|
||||
return Integer.valueOf(toHashCode());
|
||||
return toHashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -132,7 +132,7 @@ public class Base64Encoder {
|
||||
*
|
||||
* @param arr 被编码的数组
|
||||
* @param isMultiLine 在76个char之后是CRLF还是EOF
|
||||
* @param isUrlSafe 是否使用URL安全字符,一般为{@code false}
|
||||
* @param isUrlSafe 是否使用URL安全字符,在URL Safe模式下,=为URL中的关键字符,不需要补充。空余的byte位要去掉,一般为{@code false}
|
||||
* @return 编码后的bytes
|
||||
*/
|
||||
public static byte[] encode(byte[] arr, boolean isMultiLine, boolean isUrlSafe) {
|
||||
|
||||
@@ -27,8 +27,8 @@ public class Morse {
|
||||
* @param dict 二进制
|
||||
*/
|
||||
private static void registerMorse(Character abc, String dict) {
|
||||
ALPHABETS.put(Integer.valueOf(abc), dict);
|
||||
DICTIONARIES.put(dict, Integer.valueOf(abc));
|
||||
ALPHABETS.put((int) abc, dict);
|
||||
DICTIONARIES.put(dict, (int) abc);
|
||||
}
|
||||
|
||||
static {
|
||||
|
||||
@@ -510,6 +510,24 @@ public class CollUtil {
|
||||
return IterUtil.countMap(null == collection ? null : collection.iterator());
|
||||
}
|
||||
|
||||
/**
|
||||
* 以 conjunction 为分隔符将集合转换为字符串
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param iterable {@link Iterable}
|
||||
* @param conjunction 分隔符
|
||||
* @param func 集合元素转换器,将元素转换为字符串
|
||||
* @return 连接后的字符串
|
||||
* @see IterUtil#join(Iterator, CharSequence, Function)
|
||||
* @since 5.6.7
|
||||
*/
|
||||
public static <T> String join(Iterable<T> iterable, CharSequence conjunction, Function<T, ? extends CharSequence> func) {
|
||||
if (null == iterable) {
|
||||
return null;
|
||||
}
|
||||
return IterUtil.join(iterable.iterator(), conjunction, func);
|
||||
}
|
||||
|
||||
/**
|
||||
* 以 conjunction 为分隔符将集合转换为字符串<br>
|
||||
* 如果集合元素为数组、{@link Iterable}或{@link Iterator},则递归组合其为字符串
|
||||
@@ -1617,9 +1635,9 @@ public class CollUtil {
|
||||
* @since 5.6.6
|
||||
*/
|
||||
public static <T> int lastIndexOf(Collection<T> collection, Matcher<T> matcher) {
|
||||
if(collection instanceof List){
|
||||
if (collection instanceof List) {
|
||||
// List的查找最后一个有优化算法
|
||||
return ListUtil.lastIndexOf((List<T>)collection, matcher);
|
||||
return ListUtil.lastIndexOf((List<T>) collection, matcher);
|
||||
}
|
||||
int matchIndex = -1;
|
||||
if (isNotEmpty(collection)) {
|
||||
@@ -2612,7 +2630,7 @@ public class CollUtil {
|
||||
* @since 5.4.7
|
||||
*/
|
||||
public static <T> void forEach(Iterable<T> iterable, Consumer<T> consumer) {
|
||||
if(iterable == null){
|
||||
if (iterable == null) {
|
||||
return;
|
||||
}
|
||||
forEach(iterable.iterator(), consumer);
|
||||
@@ -2626,7 +2644,7 @@ public class CollUtil {
|
||||
* @param consumer {@link Consumer} 遍历的每条数据处理器
|
||||
*/
|
||||
public static <T> void forEach(Iterator<T> iterator, Consumer<T> consumer) {
|
||||
if(iterator == null){
|
||||
if (iterator == null) {
|
||||
return;
|
||||
}
|
||||
int index = 0;
|
||||
@@ -2644,7 +2662,7 @@ public class CollUtil {
|
||||
* @param consumer {@link Consumer} 遍历的每条数据处理器
|
||||
*/
|
||||
public static <T> void forEach(Enumeration<T> enumeration, Consumer<T> consumer) {
|
||||
if(enumeration == null){
|
||||
if (enumeration == null) {
|
||||
return;
|
||||
}
|
||||
int index = 0;
|
||||
@@ -2664,7 +2682,7 @@ public class CollUtil {
|
||||
* @param kvConsumer {@link KVConsumer} 遍历的每条数据处理器
|
||||
*/
|
||||
public static <K, V> void forEach(Map<K, V> map, KVConsumer<K, V> kvConsumer) {
|
||||
if(map == null){
|
||||
if (map == null) {
|
||||
return;
|
||||
}
|
||||
int index = 0;
|
||||
@@ -2986,7 +3004,7 @@ public class CollUtil {
|
||||
* @author Looly
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface KVConsumer<K, V> extends Serializable{
|
||||
public interface KVConsumer<K, V> extends Serializable {
|
||||
/**
|
||||
* 接受并处理一对参数
|
||||
*
|
||||
|
||||
@@ -337,6 +337,31 @@ public class IterUtil {
|
||||
* @since 4.0.10
|
||||
*/
|
||||
public static <T> String join(Iterator<T> iterator, CharSequence conjunction, String prefix, String suffix) {
|
||||
return join(iterator, conjunction, (item)->{
|
||||
if (ArrayUtil.isArray(item)) {
|
||||
return ArrayUtil.join(ArrayUtil.wrap(item), conjunction, prefix, suffix);
|
||||
} else if (item instanceof Iterable<?>) {
|
||||
return join((Iterable<?>) item, conjunction, prefix, suffix);
|
||||
} else if (item instanceof Iterator<?>) {
|
||||
return join((Iterator<?>) item, conjunction, prefix, suffix);
|
||||
} else {
|
||||
return StrUtil.wrap(String.valueOf(item), prefix, suffix);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 以 conjunction 为分隔符将集合转换为字符串<br>
|
||||
* 如果集合元素为数组、{@link Iterable}或{@link Iterator},则递归组合其为字符串
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param iterator 集合
|
||||
* @param conjunction 分隔符
|
||||
* @param func 集合元素转换器,将元素转换为字符串
|
||||
* @return 连接后的字符串
|
||||
* @since 5.6.7
|
||||
*/
|
||||
public static <T> String join(Iterator<T> iterator, CharSequence conjunction, Function<T, ? extends CharSequence> func) {
|
||||
if (null == iterator) {
|
||||
return null;
|
||||
}
|
||||
@@ -352,15 +377,7 @@ public class IterUtil {
|
||||
}
|
||||
|
||||
item = iterator.next();
|
||||
if (ArrayUtil.isArray(item)) {
|
||||
sb.append(ArrayUtil.join(ArrayUtil.wrap(item), conjunction, prefix, suffix));
|
||||
} else if (item instanceof Iterable<?>) {
|
||||
sb.append(join((Iterable<?>) item, conjunction, prefix, suffix));
|
||||
} else if (item instanceof Iterator<?>) {
|
||||
sb.append(join((Iterator<?>) item, conjunction, prefix, suffix));
|
||||
} else {
|
||||
sb.append(StrUtil.wrap(String.valueOf(item), prefix, suffix));
|
||||
}
|
||||
sb.append(func.apply(item));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
@@ -826,7 +843,7 @@ public class IterUtil {
|
||||
* @since 5.5.0
|
||||
*/
|
||||
public static int size(final Iterable<?> iterable) {
|
||||
if(null == iterable){
|
||||
if (null == iterable) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
/**
|
||||
* 时间工具类
|
||||
@@ -931,7 +930,6 @@ public class DateUtil extends CalendarUtil {
|
||||
|
||||
//标准日期格式(包括单个数字的日期时间)
|
||||
dateStr = normalize(dateStr);
|
||||
final Matcher matcher = DatePattern.REGEX_NORM.matcher(dateStr);
|
||||
if (ReUtil.isMatch(DatePattern.REGEX_NORM, dateStr)) {
|
||||
final int colonCount = StrUtil.count(dateStr, CharUtil.COLON);
|
||||
switch (colonCount) {
|
||||
|
||||
@@ -299,7 +299,7 @@ public class FastDatePrinter extends AbstractDateBasic implements DatePrinter {
|
||||
} else if (obj instanceof Calendar) {
|
||||
return format((Calendar) obj);
|
||||
} else if (obj instanceof Long) {
|
||||
return format(((Long) obj).longValue());
|
||||
return format(((Long) obj));
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown class: " + (obj == null ? "<null>" : obj.getClass().getName()));
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ abstract class FormatCache<F extends Format> {
|
||||
*/
|
||||
// package protected, for access from FastDateFormat; do not make public or protected
|
||||
F getDateTimeInstance(final int dateStyle, final int timeStyle, final TimeZone timeZone, final Locale locale) {
|
||||
return getDateTimeInstance(Integer.valueOf(dateStyle), Integer.valueOf(timeStyle), timeZone, locale);
|
||||
return getDateTimeInstance(dateStyle, timeStyle, timeZone, locale);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 特殊异常封装,同时提供异常工具ExceptionUtil
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -10,93 +10,93 @@ import java.math.BigInteger;
|
||||
*/
|
||||
public interface ArrayTypeGetter {
|
||||
/*-------------------------- 数组类型 start -------------------------------*/
|
||||
|
||||
|
||||
/**
|
||||
* 获取Object型属性值数组
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值列表
|
||||
*/
|
||||
String[] getObjs(String key);
|
||||
|
||||
|
||||
/**
|
||||
* 获取String型属性值数组
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值列表
|
||||
*/
|
||||
String[] getStrs(String key);
|
||||
|
||||
|
||||
/**
|
||||
* 获取Integer型属性值数组
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值列表
|
||||
*/
|
||||
Integer[] getInts(String key);
|
||||
|
||||
|
||||
/**
|
||||
* 获取Short型属性值数组
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值列表
|
||||
*/
|
||||
Short[] getShorts(String key);
|
||||
|
||||
|
||||
/**
|
||||
* 获取Boolean型属性值数组
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值列表
|
||||
*/
|
||||
Boolean[] getBools(String key);
|
||||
|
||||
|
||||
/**
|
||||
* 获取Long型属性值数组
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值列表
|
||||
*/
|
||||
Long[] getLongs(String key);
|
||||
|
||||
|
||||
/**
|
||||
* 获取Character型属性值数组
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值列表
|
||||
*/
|
||||
Character[] getChars(String key);
|
||||
|
||||
|
||||
/**
|
||||
* 获取Double型属性值数组
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值列表
|
||||
*/
|
||||
Double[] getDoubles(String key);
|
||||
|
||||
|
||||
/**
|
||||
* 获取Byte型属性值数组
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值列表
|
||||
*/
|
||||
Byte[] getBytes(String key);
|
||||
|
||||
|
||||
/**
|
||||
* 获取BigInteger型属性值数组
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值列表
|
||||
*/
|
||||
BigInteger[] getBigIntegers(String key);
|
||||
|
||||
|
||||
/**
|
||||
* 获取BigDecimal型属性值数组
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值列表
|
||||
*/
|
||||
BigDecimal[] getBigDecimals(String key);
|
||||
/*-------------------------- 数组类型 end -------------------------------*/
|
||||
/*-------------------------- 数组类型 end -------------------------------*/
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.Date;
|
||||
/**
|
||||
* 基本类型的getter接口<br>
|
||||
* 提供一个统一的接口定义返回不同类型的值(基本类型)<br>
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
public interface BasicTypeGetter<K> {
|
||||
@@ -15,7 +15,7 @@ public interface BasicTypeGetter<K> {
|
||||
|
||||
/**
|
||||
* 获取Object属性值
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
*/
|
||||
@@ -23,7 +23,7 @@ public interface BasicTypeGetter<K> {
|
||||
|
||||
/**
|
||||
* 获取字符串型属性值
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
*/
|
||||
@@ -31,7 +31,7 @@ public interface BasicTypeGetter<K> {
|
||||
|
||||
/**
|
||||
* 获取int型属性值
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
*/
|
||||
@@ -39,7 +39,7 @@ public interface BasicTypeGetter<K> {
|
||||
|
||||
/**
|
||||
* 获取short型属性值
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
*/
|
||||
@@ -47,7 +47,7 @@ public interface BasicTypeGetter<K> {
|
||||
|
||||
/**
|
||||
* 获取boolean型属性值
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
*/
|
||||
@@ -55,7 +55,7 @@ public interface BasicTypeGetter<K> {
|
||||
|
||||
/**
|
||||
* 获取long型属性值
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
*/
|
||||
@@ -63,7 +63,7 @@ public interface BasicTypeGetter<K> {
|
||||
|
||||
/**
|
||||
* 获取char型属性值
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
*/
|
||||
@@ -71,7 +71,7 @@ public interface BasicTypeGetter<K> {
|
||||
|
||||
/**
|
||||
* 获取float型属性值<br>
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
*/
|
||||
@@ -79,7 +79,7 @@ public interface BasicTypeGetter<K> {
|
||||
|
||||
/**
|
||||
* 获取double型属性值
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
*/
|
||||
@@ -87,7 +87,7 @@ public interface BasicTypeGetter<K> {
|
||||
|
||||
/**
|
||||
* 获取byte型属性值
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
*/
|
||||
@@ -95,7 +95,7 @@ public interface BasicTypeGetter<K> {
|
||||
|
||||
/**
|
||||
* 获取BigDecimal型属性值
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
*/
|
||||
@@ -103,7 +103,7 @@ public interface BasicTypeGetter<K> {
|
||||
|
||||
/**
|
||||
* 获取BigInteger型属性值
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
*/
|
||||
@@ -111,7 +111,7 @@ public interface BasicTypeGetter<K> {
|
||||
|
||||
/**
|
||||
* 获得Enum类型的值
|
||||
*
|
||||
*
|
||||
* @param <E> 枚举类型
|
||||
* @param clazz Enum的Class
|
||||
* @param key KEY
|
||||
@@ -121,7 +121,7 @@ public interface BasicTypeGetter<K> {
|
||||
|
||||
/**
|
||||
* 获取Date类型值
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return Date类型属性值
|
||||
*/
|
||||
|
||||
@@ -12,88 +12,88 @@ public interface GroupedTypeGetter {
|
||||
/*-------------------------- 基本类型 start -------------------------------*/
|
||||
/**
|
||||
* 获取字符串型属性值<br>
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param group 分组
|
||||
* @return 属性值
|
||||
*/
|
||||
String getStrByGroup(String key, String group);
|
||||
|
||||
|
||||
/**
|
||||
* 获取int型属性值<br>
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param group 分组
|
||||
* @return 属性值
|
||||
*/
|
||||
Integer getIntByGroup(String key, String group);
|
||||
|
||||
|
||||
/**
|
||||
* 获取short型属性值<br>
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param group 分组
|
||||
* @return 属性值
|
||||
*/
|
||||
Short getShortByGroup(String key, String group);
|
||||
|
||||
|
||||
/**
|
||||
* 获取boolean型属性值<br>
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param group 分组
|
||||
* @return 属性值
|
||||
*/
|
||||
Boolean getBoolByGroup(String key, String group);
|
||||
|
||||
|
||||
/**
|
||||
* 获取Long型属性值<br>
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param group 分组
|
||||
* @return 属性值
|
||||
*/
|
||||
Long getLongByGroup(String key, String group);
|
||||
|
||||
|
||||
/**
|
||||
* 获取char型属性值<br>
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param group 分组
|
||||
* @return 属性值
|
||||
*/
|
||||
Character getCharByGroup(String key, String group);
|
||||
|
||||
|
||||
/**
|
||||
* 获取double型属性值<br>
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param group 分组
|
||||
* @return 属性值
|
||||
*/
|
||||
Double getDoubleByGroup(String key, String group);
|
||||
|
||||
|
||||
/**
|
||||
* 获取byte型属性值<br>
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param group 分组
|
||||
* @return 属性值
|
||||
*/
|
||||
Byte getByteByGroup(String key, String group);
|
||||
|
||||
|
||||
/**
|
||||
* 获取BigDecimal型属性值<br>
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param group 分组
|
||||
* @return 属性值
|
||||
*/
|
||||
BigDecimal getBigDecimalByGroup(String key, String group);
|
||||
|
||||
|
||||
/**
|
||||
* 获取BigInteger型属性值<br>
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param group 分组
|
||||
* @return 属性值
|
||||
|
||||
@@ -13,7 +13,7 @@ public interface ListTypeGetter {
|
||||
/*-------------------------- List类型 start -------------------------------*/
|
||||
/**
|
||||
* 获取Object型属性值列表
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值列表
|
||||
*/
|
||||
@@ -21,79 +21,79 @@ public interface ListTypeGetter {
|
||||
|
||||
/**
|
||||
* 获取String型属性值列表
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值列表
|
||||
*/
|
||||
List<String> getStrList(String key);
|
||||
|
||||
|
||||
/**
|
||||
* 获取Integer型属性值列表
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值列表
|
||||
*/
|
||||
List<Integer> getIntList(String key);
|
||||
|
||||
|
||||
/**
|
||||
* 获取Short型属性值列表
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值列表
|
||||
*/
|
||||
List<Short> getShortList(String key);
|
||||
|
||||
|
||||
/**
|
||||
* 获取Boolean型属性值列表
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值列表
|
||||
*/
|
||||
List<Boolean> getBoolList(String key);
|
||||
|
||||
|
||||
/**
|
||||
* 获取BigDecimal型属性值列表
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值列表
|
||||
*/
|
||||
List<Long> getLongList(String key);
|
||||
|
||||
|
||||
/**
|
||||
* 获取Character型属性值列表
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值列表
|
||||
*/
|
||||
List<Character> getCharList(String key);
|
||||
|
||||
|
||||
/**
|
||||
* 获取Double型属性值列表
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值列表
|
||||
*/
|
||||
List<Double> getDoubleList(String key);
|
||||
|
||||
|
||||
/**
|
||||
* 获取Byte型属性值列表
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值列表
|
||||
*/
|
||||
List<Byte> getByteList(String key);
|
||||
|
||||
|
||||
/**
|
||||
* 获取BigDecimal型属性值列表
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值列表
|
||||
*/
|
||||
List<BigDecimal> getBigDecimalList(String key);
|
||||
|
||||
|
||||
/**
|
||||
* 获取BigInteger型属性值列表
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值列表
|
||||
*/
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.math.BigInteger;
|
||||
* 可选默认值的数组类型的Get接口
|
||||
* 提供一个统一的接口定义返回不同类型的值(基本类型)<br>
|
||||
* 如果值不存在或获取错误,返回默认值
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
* @since 4.0.2
|
||||
*
|
||||
@@ -17,7 +17,7 @@ public interface OptArrayTypeGetter {
|
||||
|
||||
/**
|
||||
* 获取Object型属性值数组
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param defaultValue 默认数组值
|
||||
* @return 属性值列表
|
||||
@@ -26,7 +26,7 @@ public interface OptArrayTypeGetter {
|
||||
|
||||
/**
|
||||
* 获取String型属性值数组
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param defaultValue 默认数组值
|
||||
* @return 属性值列表
|
||||
@@ -35,7 +35,7 @@ public interface OptArrayTypeGetter {
|
||||
|
||||
/**
|
||||
* 获取Integer型属性值数组
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param defaultValue 默认数组值
|
||||
* @return 属性值列表
|
||||
@@ -44,7 +44,7 @@ public interface OptArrayTypeGetter {
|
||||
|
||||
/**
|
||||
* 获取Short型属性值数组
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param defaultValue 默认数组值
|
||||
* @return 属性值列表
|
||||
@@ -53,7 +53,7 @@ public interface OptArrayTypeGetter {
|
||||
|
||||
/**
|
||||
* 获取Boolean型属性值数组
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param defaultValue 默认数组值
|
||||
* @return 属性值列表
|
||||
@@ -62,7 +62,7 @@ public interface OptArrayTypeGetter {
|
||||
|
||||
/**
|
||||
* 获取Long型属性值数组
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param defaultValue 默认数组值
|
||||
* @return 属性值列表
|
||||
@@ -71,7 +71,7 @@ public interface OptArrayTypeGetter {
|
||||
|
||||
/**
|
||||
* 获取Character型属性值数组
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param defaultValue 默认数组值
|
||||
* @return 属性值列表
|
||||
@@ -80,7 +80,7 @@ public interface OptArrayTypeGetter {
|
||||
|
||||
/**
|
||||
* 获取Double型属性值数组
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param defaultValue 默认数组值
|
||||
* @return 属性值列表
|
||||
@@ -89,7 +89,7 @@ public interface OptArrayTypeGetter {
|
||||
|
||||
/**
|
||||
* 获取Byte型属性值数组
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param defaultValue 默认数组值
|
||||
* @return 属性值列表
|
||||
@@ -98,7 +98,7 @@ public interface OptArrayTypeGetter {
|
||||
|
||||
/**
|
||||
* 获取BigInteger型属性值数组
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param defaultValue 默认数组值
|
||||
* @return 属性值列表
|
||||
@@ -107,7 +107,7 @@ public interface OptArrayTypeGetter {
|
||||
|
||||
/**
|
||||
* 获取BigDecimal型属性值数组
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param defaultValue 默认数组值
|
||||
* @return 属性值列表
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Date;
|
||||
*/
|
||||
public interface OptBasicTypeGetter<K> {
|
||||
/*-------------------------- 基本类型 start -------------------------------*/
|
||||
|
||||
|
||||
/**
|
||||
* 获取Object属性值
|
||||
* @param key 属性名
|
||||
@@ -20,120 +20,120 @@ public interface OptBasicTypeGetter<K> {
|
||||
* @return 属性值,无对应值返回defaultValue
|
||||
*/
|
||||
Object getObj(K key, Object defaultValue);
|
||||
|
||||
|
||||
/**
|
||||
* 获取字符串型属性值<br>
|
||||
* 若获得的值为不可见字符,使用默认值
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param defaultValue 默认值
|
||||
* @return 属性值,无对应值返回defaultValue
|
||||
*/
|
||||
String getStr(K key, String defaultValue);
|
||||
|
||||
|
||||
/**
|
||||
* 获取int型属性值<br>
|
||||
* 若获得的值为不可见字符,使用默认值
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param defaultValue 默认值
|
||||
* @return 属性值,无对应值返回defaultValue
|
||||
*/
|
||||
Integer getInt(K key, Integer defaultValue);
|
||||
|
||||
|
||||
/**
|
||||
* 获取short型属性值<br>
|
||||
* 若获得的值为不可见字符,使用默认值
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param defaultValue 默认值
|
||||
* @return 属性值,无对应值返回defaultValue
|
||||
*/
|
||||
Short getShort(K key, Short defaultValue);
|
||||
|
||||
|
||||
/**
|
||||
* 获取boolean型属性值<br>
|
||||
* 若获得的值为不可见字符,使用默认值
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param defaultValue 默认值
|
||||
* @return 属性值,无对应值返回defaultValue
|
||||
*/
|
||||
Boolean getBool(K key, Boolean defaultValue);
|
||||
|
||||
|
||||
/**
|
||||
* 获取Long型属性值<br>
|
||||
* 若获得的值为不可见字符,使用默认值
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param defaultValue 默认值
|
||||
* @return 属性值,无对应值返回defaultValue
|
||||
*/
|
||||
Long getLong(K key, Long defaultValue);
|
||||
|
||||
|
||||
/**
|
||||
* 获取char型属性值<br>
|
||||
* 若获得的值为不可见字符,使用默认值
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param defaultValue 默认值
|
||||
* @return 属性值,无对应值返回defaultValue
|
||||
*/
|
||||
Character getChar(K key, Character defaultValue);
|
||||
|
||||
|
||||
/**
|
||||
* 获取float型属性值<br>
|
||||
* 若获得的值为不可见字符,使用默认值
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param defaultValue 默认值
|
||||
* @return 属性值,无对应值返回defaultValue
|
||||
*/
|
||||
Float getFloat(K key, Float defaultValue);
|
||||
|
||||
|
||||
/**
|
||||
* 获取double型属性值<br>
|
||||
* 若获得的值为不可见字符,使用默认值
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param defaultValue 默认值
|
||||
* @return 属性值,无对应值返回defaultValue
|
||||
*/
|
||||
Double getDouble(K key, Double defaultValue);
|
||||
|
||||
|
||||
/**
|
||||
* 获取byte型属性值<br>
|
||||
* 若获得的值为不可见字符,使用默认值
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param defaultValue 默认值
|
||||
* @return 属性值,无对应值返回defaultValue
|
||||
*/
|
||||
Byte getByte(K key, Byte defaultValue);
|
||||
|
||||
|
||||
/**
|
||||
* 获取BigDecimal型属性值<br>
|
||||
* 若获得的值为不可见字符,使用默认值
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param defaultValue 默认值
|
||||
* @return 属性值,无对应值返回defaultValue
|
||||
*/
|
||||
BigDecimal getBigDecimal(K key, BigDecimal defaultValue);
|
||||
|
||||
|
||||
/**
|
||||
* 获取BigInteger型属性值<br>
|
||||
* 若获得的值为不可见字符,使用默认值
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @param defaultValue 默认值
|
||||
* @return 属性值,无对应值返回defaultValue
|
||||
*/
|
||||
BigInteger getBigInteger(K key, BigInteger defaultValue);
|
||||
|
||||
|
||||
/**
|
||||
* 获得Enum类型的值
|
||||
*
|
||||
*
|
||||
* @param <E> 枚举类型
|
||||
* @param clazz Enum的Class
|
||||
* @param key KEY
|
||||
@@ -141,7 +141,7 @@ public interface OptBasicTypeGetter<K> {
|
||||
* @return Enum类型的值,无则返回Null
|
||||
*/
|
||||
<E extends Enum<E>> E getEnum(Class<E> clazz, K key, E defaultValue);
|
||||
|
||||
|
||||
/**
|
||||
* 获取Date类型值
|
||||
* @param key 属性名
|
||||
|
||||
@@ -16,11 +16,11 @@ public interface OptNullBasicTypeGetter<K> extends BasicTypeGetter<K>, OptBasicT
|
||||
default Object getObj(K key) {
|
||||
return getObj(key, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取字符串型属性值<br>
|
||||
* 无值或获取错误返回null
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
*/
|
||||
@@ -28,11 +28,11 @@ public interface OptNullBasicTypeGetter<K> extends BasicTypeGetter<K>, OptBasicT
|
||||
default String getStr(K key){
|
||||
return this.getStr(key, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取int型属性值<br>
|
||||
* 无值或获取错误返回null
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
*/
|
||||
@@ -40,11 +40,11 @@ public interface OptNullBasicTypeGetter<K> extends BasicTypeGetter<K>, OptBasicT
|
||||
default Integer getInt(K key) {
|
||||
return this.getInt(key, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取short型属性值<br>
|
||||
* 无值或获取错误返回null
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
*/
|
||||
@@ -52,11 +52,11 @@ public interface OptNullBasicTypeGetter<K> extends BasicTypeGetter<K>, OptBasicT
|
||||
default Short getShort(K key){
|
||||
return this.getShort(key, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取boolean型属性值<br>
|
||||
* 无值或获取错误返回null
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
*/
|
||||
@@ -64,11 +64,11 @@ public interface OptNullBasicTypeGetter<K> extends BasicTypeGetter<K>, OptBasicT
|
||||
default Boolean getBool(K key){
|
||||
return this.getBool(key, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取long型属性值<br>
|
||||
* 无值或获取错误返回null
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
*/
|
||||
@@ -76,11 +76,11 @@ public interface OptNullBasicTypeGetter<K> extends BasicTypeGetter<K>, OptBasicT
|
||||
default Long getLong(K key){
|
||||
return this.getLong(key, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取char型属性值<br>
|
||||
* 无值或获取错误返回null
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
*/
|
||||
@@ -88,11 +88,11 @@ public interface OptNullBasicTypeGetter<K> extends BasicTypeGetter<K>, OptBasicT
|
||||
default Character getChar(K key){
|
||||
return this.getChar(key, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取float型属性值<br>
|
||||
* 无值或获取错误返回null
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
*/
|
||||
@@ -100,11 +100,11 @@ public interface OptNullBasicTypeGetter<K> extends BasicTypeGetter<K>, OptBasicT
|
||||
default Float getFloat(K key){
|
||||
return this.getFloat(key, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取double型属性值<br>
|
||||
* 无值或获取错误返回null
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
*/
|
||||
@@ -116,7 +116,7 @@ public interface OptNullBasicTypeGetter<K> extends BasicTypeGetter<K>, OptBasicT
|
||||
/**
|
||||
* 获取byte型属性值<br>
|
||||
* 无值或获取错误返回null
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
*/
|
||||
@@ -124,11 +124,11 @@ public interface OptNullBasicTypeGetter<K> extends BasicTypeGetter<K>, OptBasicT
|
||||
default Byte getByte(K key){
|
||||
return this.getByte(key, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取BigDecimal型属性值<br>
|
||||
* 无值或获取错误返回null
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
*/
|
||||
@@ -136,11 +136,11 @@ public interface OptNullBasicTypeGetter<K> extends BasicTypeGetter<K>, OptBasicT
|
||||
default BigDecimal getBigDecimal(K key){
|
||||
return this.getBigDecimal(key, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取BigInteger型属性值<br>
|
||||
* 无值或获取错误返回null
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
*/
|
||||
@@ -148,11 +148,11 @@ public interface OptNullBasicTypeGetter<K> extends BasicTypeGetter<K>, OptBasicT
|
||||
default BigInteger getBigInteger(K key){
|
||||
return this.getBigInteger(key, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取Enum型属性值<br>
|
||||
* 无值或获取错误返回null
|
||||
*
|
||||
*
|
||||
* @param clazz Enum 的 Class
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
@@ -161,11 +161,11 @@ public interface OptNullBasicTypeGetter<K> extends BasicTypeGetter<K>, OptBasicT
|
||||
default <E extends Enum<E>> E getEnum(Class<E> clazz, K key) {
|
||||
return this.getEnum(clazz, key, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取Date型属性值<br>
|
||||
* 无值或获取错误返回null
|
||||
*
|
||||
*
|
||||
* @param key 属性名
|
||||
* @return 属性值
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* getXXX方法的接口和抽象实现
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -43,8 +43,10 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
@@ -1164,7 +1166,7 @@ public class ImgUtil {
|
||||
* @since 4.3.2
|
||||
*/
|
||||
public static BufferedImage toBufferedImage(Image image, String imageType) {
|
||||
final int type = imageType.equalsIgnoreCase(IMAGE_TYPE_PNG)
|
||||
final int type = IMAGE_TYPE_PNG.equalsIgnoreCase(imageType)
|
||||
? BufferedImage.TYPE_INT_ARGB
|
||||
: BufferedImage.TYPE_INT_RGB;
|
||||
return toBufferedImage(image, type);
|
||||
@@ -1724,7 +1726,7 @@ public class ImgUtil {
|
||||
}
|
||||
|
||||
if (null == result) {
|
||||
throw new IllegalArgumentException("Image type of [" + imageUrl.toString() + "] is not supported!");
|
||||
throw new IllegalArgumentException("Image type of [" + imageUrl + "] is not supported!");
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -2002,6 +2004,57 @@ public class ImgUtil {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取给定图片的主色调,背景填充用
|
||||
*
|
||||
* @param image {@link BufferedImage}
|
||||
* @param rgbFilters 过滤多种颜色
|
||||
* @return {@link String} #ffffff
|
||||
* @since 5.6.7
|
||||
*/
|
||||
public static String getMainColor(BufferedImage image, int[]... rgbFilters) {
|
||||
int r, g, b;
|
||||
Map<String, Long> countMap = new HashMap<>();
|
||||
int width = image.getWidth();
|
||||
int height = image.getHeight();
|
||||
int minx = image.getMinX();
|
||||
int miny = image.getMinY();
|
||||
for (int i = minx; i < width; i++) {
|
||||
for (int j = miny; j < height; j++) {
|
||||
int pixel = image.getRGB(i, j);
|
||||
r = (pixel & 0xff0000) >> 16;
|
||||
g = (pixel & 0xff00) >> 8;
|
||||
b = (pixel & 0xff);
|
||||
if (rgbFilters != null && rgbFilters.length > 0) {
|
||||
for (int[] rgbFilter : rgbFilters) {
|
||||
if (r == rgbFilter[0] && g == rgbFilter[1] && b == rgbFilter[2]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
countMap.merge(r + "-" + g + "-" + b, 1L, Long::sum);
|
||||
}
|
||||
}
|
||||
String maxColor = null;
|
||||
long maxCount = 0;
|
||||
for (Map.Entry<String, Long> entry : countMap.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Long count = entry.getValue();
|
||||
if (count > maxCount) {
|
||||
maxColor = key;
|
||||
maxCount = count;
|
||||
}
|
||||
}
|
||||
final String[] splitRgbStr = StrUtil.splitToArray(maxColor, '-');
|
||||
String rHex = Integer.toHexString(Integer.parseInt(splitRgbStr[0]));
|
||||
String gHex = Integer.toHexString(Integer.parseInt(splitRgbStr[1]));
|
||||
String bHex = Integer.toHexString(Integer.parseInt(splitRgbStr[2]));
|
||||
rHex = rHex.length() == 1 ? "0" + rHex : rHex;
|
||||
gHex = gHex.length() == 1 ? "0" + gHex : gHex;
|
||||
bHex = bHex.length() == 1 ? "0" + bHex : bHex;
|
||||
return "#" + rHex + gHex + bHex;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------ 背景图换算
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.awt.Image;
|
||||
|
||||
/**
|
||||
* 图片缩略算法类型
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
* @since 4.5.8
|
||||
*/
|
||||
@@ -23,7 +23,7 @@ public enum ScaleType {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param value 缩放方式
|
||||
* @see Image#SCALE_DEFAULT
|
||||
* @see Image#SCALE_FAST
|
||||
|
||||
@@ -778,9 +778,6 @@ public class GifDecoder {
|
||||
lastRect = new Rectangle(ix, iy, iw, ih);
|
||||
lastImage = image;
|
||||
lastBgColor = bgColor;
|
||||
int dispose = 0;
|
||||
boolean transparency = false;
|
||||
int delay = 0;
|
||||
lct = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ class LZWEncoder {
|
||||
pixAry = pixels;
|
||||
initCodeSize = Math.max(2, color_depth);
|
||||
}
|
||||
|
||||
|
||||
// Add a character to the end of the current packet, and if it is 254
|
||||
// characters, flush the packet to disk.
|
||||
void char_out(byte c, OutputStream outs) throws IOException {
|
||||
@@ -133,7 +133,7 @@ class LZWEncoder {
|
||||
if (a_count >= 254)
|
||||
flush_char(outs);
|
||||
}
|
||||
|
||||
|
||||
// Clear out the hash table
|
||||
|
||||
// table clear for block compress
|
||||
@@ -144,13 +144,13 @@ class LZWEncoder {
|
||||
|
||||
output(ClearCode, outs);
|
||||
}
|
||||
|
||||
|
||||
// reset code table
|
||||
void cl_hash(int hsize) {
|
||||
for (int i = 0; i < hsize; ++i)
|
||||
htab[i] = -1;
|
||||
}
|
||||
|
||||
|
||||
void compress(int init_bits, OutputStream outs) throws IOException {
|
||||
int fcode;
|
||||
int i /* = 0 */;
|
||||
@@ -220,7 +220,7 @@ class LZWEncoder {
|
||||
output(ent, outs);
|
||||
output(EOFCode, outs);
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void encode(OutputStream os) throws IOException {
|
||||
os.write(initCodeSize); // write "initial code size" byte
|
||||
@@ -232,7 +232,7 @@ class LZWEncoder {
|
||||
|
||||
os.write(0); // write block terminator
|
||||
}
|
||||
|
||||
|
||||
// Flush the packet to disk, and reset the accumulator
|
||||
void flush_char(OutputStream outs) throws IOException {
|
||||
if (a_count > 0) {
|
||||
@@ -241,11 +241,11 @@ class LZWEncoder {
|
||||
a_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final int MAXCODE(int n_bits) {
|
||||
return (1 << n_bits) - 1;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Return the next pixel from the image
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -259,7 +259,7 @@ class LZWEncoder {
|
||||
|
||||
return pix & 0xff;
|
||||
}
|
||||
|
||||
|
||||
void output(int code, OutputStream outs) throws IOException {
|
||||
cur_accum &= masks[cur_bits];
|
||||
|
||||
|
||||
@@ -350,10 +350,7 @@ public class NeuQuant {
|
||||
/* Unbias network to give byte values 0..255 and record position i to prepare for sort
|
||||
----------------------------------------------------------------------------------- */
|
||||
public void unbiasnet() {
|
||||
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < NETSIZE; i++) {
|
||||
for (int i = 0; i < NETSIZE; i++) {
|
||||
network[i][0] >>= NETBIASSHIFT;
|
||||
network[i][1] >>= NETBIASSHIFT;
|
||||
network[i][2] >>= NETBIASSHIFT;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* GIF处理,来自:https://github.com/rtyley/animated-gif-lib-for-java
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 图像处理相关工具类封装
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -28,7 +28,7 @@ public class FastByteArrayOutputStream extends OutputStream {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param size 预估大小
|
||||
*/
|
||||
public FastByteArrayOutputStream(int size) {
|
||||
@@ -80,7 +80,7 @@ public class FastByteArrayOutputStream extends OutputStream {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 转为Byte数组
|
||||
* @return Byte数组
|
||||
@@ -102,7 +102,7 @@ public class FastByteArrayOutputStream extends OutputStream {
|
||||
public String toString(String charsetName) {
|
||||
return toString(CharsetUtil.charset(charsetName));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 转为字符串
|
||||
* @param charset 编码,null表示默认编码
|
||||
|
||||
@@ -49,7 +49,7 @@ public class FastByteBuffer {
|
||||
|
||||
/**
|
||||
* 分配下一个缓冲区,不会小于1024
|
||||
*
|
||||
*
|
||||
* @param newSize 理想缓冲区字节数
|
||||
*/
|
||||
private void needNewBuffer(int newSize) {
|
||||
@@ -73,7 +73,7 @@ public class FastByteBuffer {
|
||||
|
||||
/**
|
||||
* 向快速缓冲加入数据
|
||||
*
|
||||
*
|
||||
* @param array 数据
|
||||
* @param off 偏移量
|
||||
* @param len 字节数
|
||||
@@ -117,9 +117,9 @@ public class FastByteBuffer {
|
||||
|
||||
/**
|
||||
* 向快速缓冲加入数据
|
||||
*
|
||||
*
|
||||
* @param array 数据
|
||||
*
|
||||
*
|
||||
* @return 快速缓冲自身 @see FastByteBuffer
|
||||
*/
|
||||
public FastByteBuffer append(byte[] array) {
|
||||
@@ -128,7 +128,7 @@ public class FastByteBuffer {
|
||||
|
||||
/**
|
||||
* 向快速缓冲加入一个字节
|
||||
*
|
||||
*
|
||||
* @param element 一个字节的数据
|
||||
* @return 快速缓冲自身 @see FastByteBuffer
|
||||
*/
|
||||
@@ -146,7 +146,7 @@ public class FastByteBuffer {
|
||||
|
||||
/**
|
||||
* 将另一个快速缓冲加入到自身
|
||||
*
|
||||
*
|
||||
* @param buff 快速缓冲
|
||||
* @return 快速缓冲自身 @see FastByteBuffer
|
||||
*/
|
||||
@@ -171,7 +171,7 @@ public class FastByteBuffer {
|
||||
|
||||
/**
|
||||
* 当前缓冲位于缓冲区的索引位
|
||||
*
|
||||
*
|
||||
* @return {@link #currentBufferIndex}
|
||||
*/
|
||||
public int index() {
|
||||
@@ -184,7 +184,7 @@ public class FastByteBuffer {
|
||||
|
||||
/**
|
||||
* 根据索引位返回缓冲集中的缓冲
|
||||
*
|
||||
*
|
||||
* @param index 索引位
|
||||
* @return 缓冲
|
||||
*/
|
||||
@@ -202,7 +202,7 @@ public class FastByteBuffer {
|
||||
|
||||
/**
|
||||
* 返回快速缓冲中的数据
|
||||
*
|
||||
*
|
||||
* @return 快速缓冲中的数据
|
||||
*/
|
||||
public byte[] toArray() {
|
||||
@@ -226,7 +226,7 @@ public class FastByteBuffer {
|
||||
|
||||
/**
|
||||
* 返回快速缓冲中的数据
|
||||
*
|
||||
*
|
||||
* @param start 逻辑起始位置
|
||||
* @param len 逻辑字节长
|
||||
* @return 快速缓冲中的数据
|
||||
@@ -263,7 +263,7 @@ public class FastByteBuffer {
|
||||
|
||||
/**
|
||||
* 根据索引位返回一个字节
|
||||
*
|
||||
*
|
||||
* @param index 索引位
|
||||
* @return 一个字节
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
|
||||
/**
|
||||
* IO运行时异常,常用于对IOException的包装
|
||||
*
|
||||
*
|
||||
* @author xiaoleilu
|
||||
*/
|
||||
public class IORuntimeException extends RuntimeException {
|
||||
@@ -33,7 +33,7 @@ public class IORuntimeException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* 导致这个异常的异常是否是指定类型的异常
|
||||
*
|
||||
*
|
||||
* @param clazz 异常类
|
||||
* @return 是否为指定类型异常
|
||||
*/
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.io.OutputStream;
|
||||
/**
|
||||
* 此OutputStream写出数据到<b>/dev/null</b>,即忽略所有数据<br>
|
||||
* 来自 Apache Commons io
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
* @since 4.0.6
|
||||
*/
|
||||
@@ -19,7 +19,7 @@ public class NullOutputStream extends OutputStream {
|
||||
|
||||
/**
|
||||
* 什么也不做,写出到<code>/dev/null</code>.
|
||||
*
|
||||
*
|
||||
* @param b 写出的数据
|
||||
* @param off 开始位置
|
||||
* @param len 长度
|
||||
@@ -31,7 +31,7 @@ public class NullOutputStream extends OutputStream {
|
||||
|
||||
/**
|
||||
* 什么也不做,写出到 <code>/dev/null</code>.
|
||||
*
|
||||
*
|
||||
* @param b 写出的数据
|
||||
*/
|
||||
@Override
|
||||
@@ -41,7 +41,7 @@ public class NullOutputStream extends OutputStream {
|
||||
|
||||
/**
|
||||
* 什么也不做,写出到 <code>/dev/null</code>.
|
||||
*
|
||||
*
|
||||
* @param b 写出的数据
|
||||
* @throws IOException 不抛出
|
||||
*/
|
||||
|
||||
@@ -6,18 +6,18 @@ package cn.hutool.core.io;
|
||||
*
|
||||
*/
|
||||
public interface StreamProgress {
|
||||
|
||||
|
||||
/**
|
||||
* 开始
|
||||
*/
|
||||
void start();
|
||||
|
||||
|
||||
/**
|
||||
* 进行中
|
||||
* @param progressSize 已经进行的大小
|
||||
*/
|
||||
void progress(long progressSize);
|
||||
|
||||
|
||||
/**
|
||||
* 结束
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* CRC16相关算法封装为Checksum
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* IO校验相关库和工具
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.List;
|
||||
* 持有一个文件,在内存中积累一定量的数据后统一追加到文件<br>
|
||||
* 此类只有在写入文件时打开文件,并在写入结束后关闭之。因此此类不需要关闭<br>
|
||||
* 在调用append方法后会缓存于内存,只有超过容量后才会一次性写入文件,因此内存中随时有剩余未写入文件的内容,在最后必须调用flush方法将剩余内容刷入文件
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
* @since 3.1.2
|
||||
*/
|
||||
@@ -27,10 +27,10 @@ public class FileAppender implements Serializable{
|
||||
/** 追加内容是否为新行 */
|
||||
private final boolean isNewLineMode;
|
||||
private final List<String> list = new ArrayList<>(100);
|
||||
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param destFile 目标文件
|
||||
* @param capacity 当行数积累多少条时刷入到文件
|
||||
* @param isNewLineMode 追加内容是否为新行
|
||||
@@ -41,7 +41,7 @@ public class FileAppender implements Serializable{
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param destFile 目标文件
|
||||
* @param charset 编码
|
||||
* @param capacity 当行数积累多少条时刷入到文件
|
||||
@@ -55,7 +55,7 @@ public class FileAppender implements Serializable{
|
||||
|
||||
/**
|
||||
* 追加
|
||||
*
|
||||
*
|
||||
* @param line 行
|
||||
* @return this
|
||||
*/
|
||||
@@ -69,7 +69,7 @@ public class FileAppender implements Serializable{
|
||||
|
||||
/**
|
||||
* 刷入到文件
|
||||
*
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public FileAppender flush() {
|
||||
|
||||
@@ -23,13 +23,13 @@ import java.util.ArrayList;
|
||||
* 3、目录复制到目录
|
||||
* 4、目录下的文件和目录复制到另一个目录
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public class FileCopier extends SrcToDestCopier<File, FileCopier>{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
/** 是否覆盖目标文件 */
|
||||
private boolean isOverride;
|
||||
/** 是否拷贝所有属性 */
|
||||
@@ -38,7 +38,7 @@ public class FileCopier extends SrcToDestCopier<File, FileCopier>{
|
||||
private boolean isCopyContentIfDir;
|
||||
/** 当拷贝来源是目录时是否只拷贝文件而忽略子目录 */
|
||||
private boolean isOnlyCopyFile;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------- static method start
|
||||
/**
|
||||
* 新建一个文件复制器
|
||||
@@ -49,7 +49,7 @@ public class FileCopier extends SrcToDestCopier<File, FileCopier>{
|
||||
public static FileCopier create(String srcPath, String destPath) {
|
||||
return new FileCopier(FileUtil.file(srcPath), FileUtil.file(destPath));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新建一个文件复制器
|
||||
* @param src 源文件
|
||||
@@ -60,7 +60,7 @@ public class FileCopier extends SrcToDestCopier<File, FileCopier>{
|
||||
return new FileCopier(src, dest);
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------- static method end
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------- Constructor start
|
||||
/**
|
||||
* 构造
|
||||
@@ -72,7 +72,7 @@ public class FileCopier extends SrcToDestCopier<File, FileCopier>{
|
||||
this.dest = dest;
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------- Constructor end
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------- Getters and Setters start
|
||||
/**
|
||||
* 是否覆盖目标文件
|
||||
@@ -115,7 +115,7 @@ public class FileCopier extends SrcToDestCopier<File, FileCopier>{
|
||||
public boolean isCopyContentIfDir() {
|
||||
return isCopyContentIfDir;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 当拷贝来源是目录时是否只拷贝目录下的内容
|
||||
* @param isCopyContentIfDir 是否只拷贝目录下的内容
|
||||
@@ -125,10 +125,10 @@ public class FileCopier extends SrcToDestCopier<File, FileCopier>{
|
||||
this.isCopyContentIfDir = isCopyContentIfDir;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 当拷贝来源是目录时是否只拷贝文件而忽略子目录
|
||||
*
|
||||
*
|
||||
* @return 当拷贝来源是目录时是否只拷贝文件而忽略子目录
|
||||
* @since 4.1.5
|
||||
*/
|
||||
@@ -138,7 +138,7 @@ public class FileCopier extends SrcToDestCopier<File, FileCopier>{
|
||||
|
||||
/**
|
||||
* 设置当拷贝来源是目录时是否只拷贝文件而忽略子目录
|
||||
*
|
||||
*
|
||||
* @param isOnlyCopyFile 当拷贝来源是目录时是否只拷贝文件而忽略子目录
|
||||
* @return this
|
||||
* @since 4.1.5
|
||||
@@ -161,7 +161,7 @@ public class FileCopier extends SrcToDestCopier<File, FileCopier>{
|
||||
* 6、源为目录,目标为文件,抛出IO异常
|
||||
* 7、源路径和目标路径相同时,抛出IO异常
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @return 拷贝后目标的文件或目录
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
@@ -187,7 +187,7 @@ public class FileCopier extends SrcToDestCopier<File, FileCopier>{
|
||||
if(FileUtil.isSub(src, dest)) {
|
||||
throw new IORuntimeException("Dest is a sub directory of src !");
|
||||
}
|
||||
|
||||
|
||||
final File subTarget = isCopyContentIfDir ? dest : FileUtil.mkdir(FileUtil.file(dest, src.getName()));
|
||||
internalCopyDirContent(src, subTarget);
|
||||
} else {// 复制文件
|
||||
@@ -200,7 +200,7 @@ public class FileCopier extends SrcToDestCopier<File, FileCopier>{
|
||||
/**
|
||||
* 拷贝目录内容,只用于内部,不做任何安全检查<br>
|
||||
* 拷贝内容的意思为源目录下的所有文件和目录拷贝到另一个目录下,而不拷贝源目录本身
|
||||
*
|
||||
*
|
||||
* @param src 源目录
|
||||
* @param dest 目标目录
|
||||
* @throws IORuntimeException IO异常
|
||||
@@ -218,7 +218,7 @@ public class FileCopier extends SrcToDestCopier<File, FileCopier>{
|
||||
} else if (false == dest.isDirectory()) {
|
||||
throw new IORuntimeException(StrUtil.format("Src [{}] is a directory but dest [{}] is a file!", src.getPath(), dest.getPath()));
|
||||
}
|
||||
|
||||
|
||||
final String[] files = src.list();
|
||||
if(ArrayUtil.isNotEmpty(files)){
|
||||
File srcFile;
|
||||
@@ -243,7 +243,7 @@ public class FileCopier extends SrcToDestCopier<File, FileCopier>{
|
||||
* 1、如果目标是一个不存在的路径,则目标以文件对待(自动创建父级目录)比如:/dest/aaa,如果aaa不存在,则aaa被当作文件名
|
||||
* 2、如果目标是一个已存在的目录,则文件拷贝到此目录下,文件名与原文件名一致
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @param src 源文件,必须为文件
|
||||
* @param dest 目标文件,如果非覆盖模式必须为目录
|
||||
* @throws IORuntimeException IO异常
|
||||
@@ -253,14 +253,14 @@ public class FileCopier extends SrcToDestCopier<File, FileCopier>{
|
||||
//被过滤的文件跳过
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 如果已经存在目标文件,切为不覆盖模式,跳过之
|
||||
if (dest.exists()) {
|
||||
if(dest.isDirectory()) {
|
||||
//目标为目录,目录下创建同名文件
|
||||
dest = new File(dest, src.getName());
|
||||
}
|
||||
|
||||
|
||||
if(dest.exists() && false == isOverride) {
|
||||
//非覆盖模式跳过
|
||||
return;
|
||||
@@ -270,7 +270,7 @@ public class FileCopier extends SrcToDestCopier<File, FileCopier>{
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
dest.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
|
||||
final ArrayList<CopyOption> optionList = new ArrayList<>(2);
|
||||
if(isOverride) {
|
||||
optionList.add(StandardCopyOption.REPLACE_EXISTING);
|
||||
@@ -278,7 +278,7 @@ public class FileCopier extends SrcToDestCopier<File, FileCopier>{
|
||||
if(isCopyAttributes) {
|
||||
optionList.add(StandardCopyOption.COPY_ATTRIBUTES);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
Files.copy(src.toPath(), dest.toPath(), optionList.toArray(new CopyOption[0]));
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -2,7 +2,7 @@ package cn.hutool.core.io.file;
|
||||
|
||||
/**
|
||||
* 文件读写模式,常用于RandomAccessFile
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
* @since 4.5.2
|
||||
*/
|
||||
|
||||
@@ -20,13 +20,13 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* 文件读取器
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
*
|
||||
*/
|
||||
public class FileReader extends FileWrapper {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
/**
|
||||
* 创建 FileReader
|
||||
* @param file 文件
|
||||
@@ -36,7 +36,7 @@ public class FileReader extends FileWrapper {
|
||||
public static FileReader create(File file, Charset charset){
|
||||
return new FileReader(file, charset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建 FileReader, 编码:{@link FileWrapper#DEFAULT_CHARSET}
|
||||
* @param file 文件
|
||||
@@ -45,7 +45,7 @@ public class FileReader extends FileWrapper {
|
||||
public static FileReader create(File file){
|
||||
return new FileReader(file);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------- Constructor start
|
||||
/**
|
||||
* 构造
|
||||
@@ -106,7 +106,7 @@ public class FileReader extends FileWrapper {
|
||||
/**
|
||||
* 读取文件所有数据<br>
|
||||
* 文件的长度不能超过 {@link Integer#MAX_VALUE}
|
||||
*
|
||||
*
|
||||
* @return 字节码
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
@@ -136,7 +136,7 @@ public class FileReader extends FileWrapper {
|
||||
|
||||
/**
|
||||
* 读取文件内容
|
||||
*
|
||||
*
|
||||
* @return 内容
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
@@ -146,7 +146,7 @@ public class FileReader extends FileWrapper {
|
||||
|
||||
/**
|
||||
* 从文件中读取每一行数据
|
||||
*
|
||||
*
|
||||
* @param <T> 集合类型
|
||||
* @param collection 集合
|
||||
* @return 文件中的每行内容的集合
|
||||
@@ -171,10 +171,10 @@ public class FileReader extends FileWrapper {
|
||||
IoUtil.close(reader);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 按照行处理文件内容
|
||||
*
|
||||
*
|
||||
* @param lineHandler 行处理器
|
||||
* @throws IORuntimeException IO异常
|
||||
* @since 3.0.9
|
||||
@@ -188,10 +188,10 @@ public class FileReader extends FileWrapper {
|
||||
IoUtil.close(reader);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从文件中读取每一行数据
|
||||
*
|
||||
*
|
||||
* @return 文件中的每行内容的集合
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
@@ -201,7 +201,7 @@ public class FileReader extends FileWrapper {
|
||||
|
||||
/**
|
||||
* 按照给定的readerHandler读取文件中的数据
|
||||
*
|
||||
*
|
||||
* @param <T> 读取的结果对象类型
|
||||
* @param readerHandler Reader处理类
|
||||
* @return 从文件中read出的数据
|
||||
@@ -223,7 +223,7 @@ public class FileReader extends FileWrapper {
|
||||
|
||||
/**
|
||||
* 获得一个文件读取器
|
||||
*
|
||||
*
|
||||
* @return BufferedReader对象
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
@@ -233,7 +233,7 @@ public class FileReader extends FileWrapper {
|
||||
|
||||
/**
|
||||
* 获得输入流
|
||||
*
|
||||
*
|
||||
* @return 输入流
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
@@ -255,10 +255,10 @@ public class FileReader extends FileWrapper {
|
||||
public long writeToStream(OutputStream out) throws IORuntimeException {
|
||||
return writeToStream(out, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将文件写入流中
|
||||
*
|
||||
*
|
||||
* @param out 流
|
||||
* @param isCloseOut 是否关闭输出流
|
||||
* @return 写出的流byte数
|
||||
@@ -280,7 +280,7 @@ public class FileReader extends FileWrapper {
|
||||
// -------------------------------------------------------------------------- Interface start
|
||||
/**
|
||||
* Reader处理接口
|
||||
*
|
||||
*
|
||||
* @author Luxiaolei
|
||||
*
|
||||
* @param <T> Reader处理返回结果类型
|
||||
@@ -289,10 +289,10 @@ public class FileReader extends FileWrapper {
|
||||
T handle(BufferedReader reader) throws IOException;
|
||||
}
|
||||
// -------------------------------------------------------------------------- Interface end
|
||||
|
||||
|
||||
/**
|
||||
* 检查文件
|
||||
*
|
||||
*
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
private void checkFile() throws IORuntimeException {
|
||||
|
||||
@@ -10,16 +10,16 @@ import cn.hutool.core.util.CharsetUtil;
|
||||
|
||||
/**
|
||||
* 文件包装器,扩展文件对象
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
*
|
||||
*/
|
||||
public class FileWrapper implements Serializable{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
protected File file;
|
||||
protected Charset charset;
|
||||
|
||||
|
||||
/** 默认编码:UTF-8 */
|
||||
public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.util.Map.Entry;
|
||||
*/
|
||||
public class FileWriter extends FileWrapper{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
/**
|
||||
* 创建 FileWriter
|
||||
* @param file 文件
|
||||
@@ -37,7 +37,7 @@ public class FileWriter extends FileWrapper{
|
||||
public static FileWriter create(File file, Charset charset){
|
||||
return new FileWriter(file, charset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建 FileWriter, 编码:{@link FileWrapper#DEFAULT_CHARSET}
|
||||
* @param file 文件
|
||||
@@ -46,7 +46,7 @@ public class FileWriter extends FileWrapper{
|
||||
public static FileWriter create(File file){
|
||||
return new FileWriter(file);
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------- Constructor start
|
||||
/**
|
||||
* 构造
|
||||
@@ -103,10 +103,10 @@ public class FileWriter extends FileWrapper{
|
||||
this(filePath, DEFAULT_CHARSET);
|
||||
}
|
||||
// ------------------------------------------------------- Constructor end
|
||||
|
||||
|
||||
/**
|
||||
* 将String写入文件
|
||||
*
|
||||
*
|
||||
* @param content 写入的内容
|
||||
* @param isAppend 是否追加
|
||||
* @return 目标文件
|
||||
@@ -125,10 +125,10 @@ public class FileWriter extends FileWrapper{
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将String写入文件,覆盖模式
|
||||
*
|
||||
*
|
||||
* @param content 写入的内容
|
||||
* @return 目标文件
|
||||
* @throws IORuntimeException IO异常
|
||||
@@ -139,7 +139,7 @@ public class FileWriter extends FileWrapper{
|
||||
|
||||
/**
|
||||
* 将String写入文件,追加模式
|
||||
*
|
||||
*
|
||||
* @param content 写入的内容
|
||||
* @return 写入的文件
|
||||
* @throws IORuntimeException IO异常
|
||||
@@ -150,7 +150,7 @@ public class FileWriter extends FileWrapper{
|
||||
|
||||
/**
|
||||
* 将列表写入文件,覆盖模式
|
||||
*
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param list 列表
|
||||
* @return 目标文件
|
||||
@@ -162,7 +162,7 @@ public class FileWriter extends FileWrapper{
|
||||
|
||||
/**
|
||||
* 将列表写入文件,追加模式
|
||||
*
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param list 列表
|
||||
* @return 目标文件
|
||||
@@ -174,7 +174,7 @@ public class FileWriter extends FileWrapper{
|
||||
|
||||
/**
|
||||
* 将列表写入文件
|
||||
*
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param list 列表
|
||||
* @param isAppend 是否追加
|
||||
@@ -184,10 +184,10 @@ public class FileWriter extends FileWrapper{
|
||||
public <T> File writeLines(Collection<T> list, boolean isAppend) throws IORuntimeException {
|
||||
return writeLines(list, null, isAppend);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将列表写入文件
|
||||
*
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param list 列表
|
||||
* @param lineSeparator 换行符枚举(Windows、Mac或Linux换行符)
|
||||
@@ -208,10 +208,10 @@ public class FileWriter extends FileWrapper{
|
||||
}
|
||||
return this.file;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将Map写入文件,每个键值对为一行,一行中键与值之间使用kvSeparator分隔
|
||||
*
|
||||
*
|
||||
* @param map Map
|
||||
* @param kvSeparator 键和值之间的分隔符,如果传入null使用默认分隔符" = "
|
||||
* @param isAppend 是否追加
|
||||
@@ -222,10 +222,10 @@ public class FileWriter extends FileWrapper{
|
||||
public File writeMap(Map<?, ?> map, String kvSeparator, boolean isAppend) throws IORuntimeException {
|
||||
return writeMap(map, null, kvSeparator, isAppend);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将Map写入文件,每个键值对为一行,一行中键与值之间使用kvSeparator分隔
|
||||
*
|
||||
*
|
||||
* @param map Map
|
||||
* @param lineSeparator 换行符枚举(Windows、Mac或Linux换行符)
|
||||
* @param kvSeparator 键和值之间的分隔符,如果传入null使用默认分隔符" = "
|
||||
@@ -249,10 +249,10 @@ public class FileWriter extends FileWrapper{
|
||||
}
|
||||
return this.file;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 写入数据到文件
|
||||
*
|
||||
*
|
||||
* @param data 数据
|
||||
* @param off 数据开始位置
|
||||
* @param len 数据长度
|
||||
@@ -262,10 +262,10 @@ public class FileWriter extends FileWrapper{
|
||||
public File write(byte[] data, int off, int len) throws IORuntimeException {
|
||||
return write(data, off, len, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 追加数据到文件
|
||||
*
|
||||
*
|
||||
* @param data 数据
|
||||
* @param off 数据开始位置
|
||||
* @param len 数据长度
|
||||
@@ -278,7 +278,7 @@ public class FileWriter extends FileWrapper{
|
||||
|
||||
/**
|
||||
* 写入数据到文件
|
||||
*
|
||||
*
|
||||
* @param data 数据
|
||||
* @param off 数据开始位置
|
||||
* @param len 数据长度
|
||||
@@ -314,7 +314,7 @@ public class FileWriter extends FileWrapper{
|
||||
|
||||
/**
|
||||
* 将流的内容写入文件
|
||||
*
|
||||
*
|
||||
* @param in 输入流,不关闭
|
||||
* @param isCloseIn 是否关闭输入流
|
||||
* @return dest
|
||||
@@ -339,7 +339,7 @@ public class FileWriter extends FileWrapper{
|
||||
|
||||
/**
|
||||
* 获得一个输出流对象
|
||||
*
|
||||
*
|
||||
* @return 输出流对象
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
@@ -353,7 +353,7 @@ public class FileWriter extends FileWrapper{
|
||||
|
||||
/**
|
||||
* 获得一个带缓存的写入对象
|
||||
*
|
||||
*
|
||||
* @param isAppend 是否追加
|
||||
* @return BufferedReader对象
|
||||
* @throws IORuntimeException IO异常
|
||||
@@ -368,7 +368,7 @@ public class FileWriter extends FileWrapper{
|
||||
|
||||
/**
|
||||
* 获得一个打印写入对象,可以有print
|
||||
*
|
||||
*
|
||||
* @param isAppend 是否追加
|
||||
* @return 打印对象
|
||||
* @throws IORuntimeException IO异常
|
||||
@@ -376,10 +376,10 @@ public class FileWriter extends FileWrapper{
|
||||
public PrintWriter getPrintWriter(boolean isAppend) throws IORuntimeException {
|
||||
return new PrintWriter(getWriter(isAppend));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检查文件
|
||||
*
|
||||
*
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
private void checkFile() throws IORuntimeException {
|
||||
@@ -388,7 +388,7 @@ public class FileWriter extends FileWrapper{
|
||||
throw new IORuntimeException("File [{}] is not a file !", this.file.getAbsoluteFile());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 打印新行
|
||||
* @param writer Writer
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.nio.file.WatchEvent;
|
||||
|
||||
/**
|
||||
* 行处理的Watcher实现
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
* @since 4.5.2
|
||||
*/
|
||||
@@ -25,7 +25,7 @@ public class LineReadWatcher extends SimpleWatcher implements Runnable {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param randomAccessFile {@link RandomAccessFile}
|
||||
* @param charset 编码
|
||||
* @param lineHandler 行处理器{@link LineHandler}实现
|
||||
|
||||
@@ -8,7 +8,7 @@ package cn.hutool.core.io.file;
|
||||
* Linux系统换行符:"\n"
|
||||
* Windows系统换行符:"\r\n"
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @see #MAC
|
||||
* @see #LINUX
|
||||
* @see #WINDOWS
|
||||
@@ -19,7 +19,7 @@ public enum LineSeparator {
|
||||
/** Mac系统换行符:"\r" */
|
||||
MAC("\r"),
|
||||
/** Linux系统换行符:"\n" */
|
||||
LINUX("\n"),
|
||||
LINUX("\n"),
|
||||
/** Windows系统换行符:"\r\n" */
|
||||
WINDOWS("\r\n");
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 对文件读写的封装,包括文件拷贝、文件读取、文件写出、行处理等
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* FileVisitor功能性实现,包括递归删除、拷贝等
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* IO相关封装和工具类,包括Inputstream和OutputStream实现类,工具包括流工具IoUtil、文件工具FileUtil和Buffer工具BufferUtil
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.nio.charset.Charset;
|
||||
/**
|
||||
* 基于byte[]的资源获取器<br>
|
||||
* 注意:此对象中getUrl方法始终返回null
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
* @since 4.0.9
|
||||
*/
|
||||
@@ -24,16 +24,16 @@ public class BytesResource implements Resource, Serializable {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param bytes 字节数组
|
||||
*/
|
||||
public BytesResource(byte[] bytes) {
|
||||
this(bytes, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param bytes 字节数组
|
||||
* @param name 资源名称
|
||||
*/
|
||||
@@ -41,7 +41,7 @@ public class BytesResource implements Resource, Serializable {
|
||||
this.bytes = bytes;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* {@link CharSequence}资源,字符串做为资源
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
* @since 5.5.2
|
||||
*/
|
||||
|
||||
@@ -13,7 +13,7 @@ import cn.hutool.core.util.URLUtil;
|
||||
* ClassPath单一资源访问类<br>
|
||||
* 传入路径path必须为相对路径,如果传入绝对路径,Linux路径会去掉开头的“/”,而Windows路径会直接报错。<br>
|
||||
* 传入的path所指向的资源必须存在,否则报错
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
*
|
||||
*/
|
||||
@@ -27,7 +27,7 @@ public class ClassPathResource extends UrlResource {
|
||||
// -------------------------------------------------------------------------------------- Constructor start
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param path 相对于ClassPath的路径
|
||||
*/
|
||||
public ClassPathResource(String path) {
|
||||
@@ -36,7 +36,7 @@ public class ClassPathResource extends UrlResource {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param path 相对于ClassPath的路径
|
||||
* @param classLoader {@link ClassLoader}
|
||||
*/
|
||||
@@ -46,7 +46,7 @@ public class ClassPathResource extends UrlResource {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param path 相对于给定Class的路径
|
||||
* @param clazz {@link Class} 用于定位路径
|
||||
*/
|
||||
@@ -56,7 +56,7 @@ public class ClassPathResource extends UrlResource {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param pathBaseClassLoader 相对路径
|
||||
* @param classLoader {@link ClassLoader}
|
||||
* @param clazz {@link Class} 用于定位路径
|
||||
@@ -64,11 +64,11 @@ public class ClassPathResource extends UrlResource {
|
||||
public ClassPathResource(String pathBaseClassLoader, ClassLoader classLoader, Class<?> clazz) {
|
||||
super((URL) null);
|
||||
Assert.notNull(pathBaseClassLoader, "Path must not be null");
|
||||
|
||||
|
||||
final String path = normalizePath(pathBaseClassLoader);
|
||||
this.path = path;
|
||||
this.name = StrUtil.isBlank(path) ? null : FileUtil.getName(path);
|
||||
|
||||
|
||||
this.classLoader = ObjectUtil.defaultIfNull(classLoader, ClassUtil.getClassLoader());
|
||||
this.clazz = clazz;
|
||||
initUrl();
|
||||
@@ -77,7 +77,7 @@ public class ClassPathResource extends UrlResource {
|
||||
|
||||
/**
|
||||
* 获得Path
|
||||
*
|
||||
*
|
||||
* @return path
|
||||
*/
|
||||
public final String getPath() {
|
||||
@@ -87,7 +87,7 @@ public class ClassPathResource extends UrlResource {
|
||||
/**
|
||||
* 获得绝对路径Path<br>
|
||||
* 对于不存在的资源,返回拼接后的绝对路径
|
||||
*
|
||||
*
|
||||
* @return 绝对路径path
|
||||
*/
|
||||
public final String getAbsolutePath() {
|
||||
@@ -100,7 +100,7 @@ public class ClassPathResource extends UrlResource {
|
||||
|
||||
/**
|
||||
* 获得 {@link ClassLoader}
|
||||
*
|
||||
*
|
||||
* @return {@link ClassLoader}
|
||||
*/
|
||||
public final ClassLoader getClassLoader() {
|
||||
@@ -130,7 +130,7 @@ public class ClassPathResource extends UrlResource {
|
||||
|
||||
/**
|
||||
* 标准化Path格式
|
||||
*
|
||||
*
|
||||
* @param path Path
|
||||
* @return 标准化后的path
|
||||
*/
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* 文件资源访问对象,支持{@link Path} 和 {@link File} 访问
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
public class FileResource implements Resource, Serializable {
|
||||
@@ -22,7 +22,7 @@ public class FileResource implements Resource, Serializable {
|
||||
// ----------------------------------------------------------------------- Constructor start
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param path 文件
|
||||
* @since 4.4.1
|
||||
*/
|
||||
@@ -32,7 +32,7 @@ public class FileResource implements Resource, Serializable {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param file 文件
|
||||
*/
|
||||
public FileResource(File file) {
|
||||
@@ -41,7 +41,7 @@ public class FileResource implements Resource, Serializable {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param file 文件
|
||||
* @param fileName 文件名,如果为null获取文件本身的文件名
|
||||
*/
|
||||
@@ -51,7 +51,7 @@ public class FileResource implements Resource, Serializable {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param path 文件绝对路径或相对ClassPath路径,但是这个路径不能指向一个jar包中的文件
|
||||
*/
|
||||
public FileResource(String path) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.net.URL;
|
||||
/**
|
||||
* 基于{@link InputStream}的资源获取器<br>
|
||||
* 注意:此对象中getUrl方法始终返回null
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
* @since 4.0.9
|
||||
*/
|
||||
@@ -19,16 +19,16 @@ public class InputStreamResource implements Resource, Serializable {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param in {@link InputStream}
|
||||
*/
|
||||
public InputStreamResource(InputStream in) {
|
||||
this(in, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param in {@link InputStream}
|
||||
* @param name 资源名称
|
||||
*/
|
||||
@@ -36,7 +36,7 @@ public class InputStreamResource implements Resource, Serializable {
|
||||
this.in = in;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
|
||||
@@ -6,34 +6,34 @@ import java.util.Collection;
|
||||
/**
|
||||
* 多文件组合资源<br>
|
||||
* 此资源为一个利用游标自循环资源,只有调用{@link #next()} 方法才会获取下一个资源,使用完毕后调用{@link #reset()}方法重置游标
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public class MultiFileResource extends MultiResource{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param files 文件资源列表
|
||||
*/
|
||||
public MultiFileResource(Collection<File> files) {
|
||||
add(files);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param files 文件资源列表
|
||||
*/
|
||||
public MultiFileResource(File... files) {
|
||||
add(files);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 增加文件资源
|
||||
*
|
||||
*
|
||||
* @param files 文件资源
|
||||
* @return this
|
||||
*/
|
||||
@@ -43,10 +43,10 @@ public class MultiFileResource extends MultiResource{
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 增加文件资源
|
||||
*
|
||||
*
|
||||
* @param files 文件资源
|
||||
* @return this
|
||||
*/
|
||||
@@ -56,7 +56,7 @@ public class MultiFileResource extends MultiResource{
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MultiFileResource add(Resource resource) {
|
||||
return (MultiFileResource)super.add(resource);
|
||||
|
||||
@@ -16,7 +16,7 @@ import java.util.List;
|
||||
/**
|
||||
* 多资源组合资源<br>
|
||||
* 此资源为一个利用游标自循环资源,只有调用{@link #next()} 方法才会获取下一个资源,使用完毕后调用{@link #reset()}方法重置游标
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
* @since 4.1.0
|
||||
*/
|
||||
@@ -25,10 +25,10 @@ public class MultiResource implements Resource, Iterable<Resource>, Iterator<Res
|
||||
|
||||
private final List<Resource> resources;
|
||||
private int cursor;
|
||||
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param resources 资源数组
|
||||
*/
|
||||
public MultiResource(Resource... resources) {
|
||||
@@ -37,7 +37,7 @@ public class MultiResource implements Resource, Iterable<Resource>, Iterator<Res
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param resources 资源列表
|
||||
*/
|
||||
public MultiResource(Collection<Resource> resources) {
|
||||
@@ -113,7 +113,7 @@ public class MultiResource implements Resource, Iterable<Resource>, Iterator<Res
|
||||
public synchronized void reset() {
|
||||
this.cursor = 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 增加资源
|
||||
* @param resource 资源
|
||||
|
||||
@@ -6,7 +6,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
|
||||
/**
|
||||
* 资源文件或资源不存在异常
|
||||
*
|
||||
*
|
||||
* @author xiaoleilu
|
||||
* @since 4.0.2
|
||||
*/
|
||||
@@ -35,7 +35,7 @@ public class NoResourceException extends IORuntimeException {
|
||||
|
||||
/**
|
||||
* 导致这个异常的异常是否是指定类型的异常
|
||||
*
|
||||
*
|
||||
* @param clazz 异常类
|
||||
* @return 是否为指定类型异常
|
||||
*/
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* Resource资源工具类
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
*
|
||||
*/
|
||||
@@ -27,7 +27,7 @@ public class ResourceUtil {
|
||||
|
||||
/**
|
||||
* 读取Classpath下的资源为字符串,使用UTF-8编码
|
||||
*
|
||||
*
|
||||
* @param resource 资源路径,使用相对ClassPath的路径
|
||||
* @return 资源内容
|
||||
* @since 3.1.1
|
||||
@@ -38,7 +38,7 @@ public class ResourceUtil {
|
||||
|
||||
/**
|
||||
* 读取Classpath下的资源为字符串
|
||||
*
|
||||
*
|
||||
* @param resource 可以是绝对路径,也可以是相对路径(相对ClassPath)
|
||||
* @param charset 编码
|
||||
* @return 资源内容
|
||||
@@ -47,10 +47,10 @@ public class ResourceUtil {
|
||||
public static String readStr(String resource, Charset charset) {
|
||||
return getResourceObj(resource).readStr(charset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 读取Classpath下的资源为byte[]
|
||||
*
|
||||
*
|
||||
* @param resource 可以是绝对路径,也可以是相对路径(相对ClassPath)
|
||||
* @return 资源内容
|
||||
* @since 4.5.19
|
||||
@@ -61,7 +61,7 @@ public class ResourceUtil {
|
||||
|
||||
/**
|
||||
* 从ClassPath资源中获取{@link InputStream}
|
||||
*
|
||||
*
|
||||
* @param resource ClassPath资源
|
||||
* @return {@link InputStream}
|
||||
* @throws NoResourceException 资源不存在异常
|
||||
@@ -73,7 +73,7 @@ public class ResourceUtil {
|
||||
|
||||
/**
|
||||
* 从ClassPath资源中获取{@link InputStream},当资源不存在时返回null
|
||||
*
|
||||
*
|
||||
* @param resource ClassPath资源
|
||||
* @return {@link InputStream}
|
||||
* @since 4.0.3
|
||||
@@ -100,7 +100,7 @@ public class ResourceUtil {
|
||||
|
||||
/**
|
||||
* 从ClassPath资源中获取{@link BufferedReader}
|
||||
*
|
||||
*
|
||||
* @param resource ClassPath资源
|
||||
* @param charset 编码
|
||||
* @return {@link InputStream}
|
||||
@@ -113,12 +113,12 @@ public class ResourceUtil {
|
||||
/**
|
||||
* 获得资源的URL<br>
|
||||
* 路径用/分隔,例如:
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* config/a/db.config
|
||||
* spring/xml/test.xml
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @param resource 资源(相对Classpath的路径)
|
||||
* @return 资源URL
|
||||
*/
|
||||
@@ -129,12 +129,12 @@ public class ResourceUtil {
|
||||
/**
|
||||
* 获取指定路径下的资源列表<br>
|
||||
* 路径格式必须为目录格式,用/分隔,例如:
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* config/a
|
||||
* spring/xml
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @param resource 资源路径
|
||||
* @return 资源列表
|
||||
*/
|
||||
@@ -151,12 +151,12 @@ public class ResourceUtil {
|
||||
/**
|
||||
* 获取指定路径下的资源Iterator<br>
|
||||
* 路径格式必须为目录格式,用/分隔,例如:
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* config/a
|
||||
* spring/xml
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @param resource 资源路径
|
||||
* @return 资源列表
|
||||
* @since 4.1.5
|
||||
@@ -173,7 +173,7 @@ public class ResourceUtil {
|
||||
|
||||
/**
|
||||
* 获得资源相对路径对应的URL
|
||||
*
|
||||
*
|
||||
* @param resource 资源相对路径
|
||||
* @param baseClass 基准Class,获得的相对路径相对于此Class所在路径,如果为{@code null}则相对ClassPath
|
||||
* @return {@link URL}
|
||||
@@ -185,7 +185,7 @@ public class ResourceUtil {
|
||||
/**
|
||||
* 获取{@link Resource} 资源对象<br>
|
||||
* 如果提供路径为绝对路径或路径以file:开头,返回{@link FileResource},否则返回{@link ClassPathResource}
|
||||
*
|
||||
*
|
||||
* @param path 路径,可以是绝对路径,也可以是相对路径(相对ClassPath)
|
||||
* @return {@link Resource} 资源对象
|
||||
* @since 3.2.1
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* 字符串资源,字符串做为资源
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
* @since 4.1.0
|
||||
* @see CharSequenceResource
|
||||
|
||||
@@ -16,10 +16,10 @@ import java.net.URL;
|
||||
*/
|
||||
public class UrlResource implements Resource, Serializable{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
protected URL url;
|
||||
protected String name;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------- Constructor start
|
||||
/**
|
||||
* 构造
|
||||
@@ -28,7 +28,7 @@ public class UrlResource implements Resource, Serializable{
|
||||
public UrlResource(URL url) {
|
||||
this(url, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构造
|
||||
* @param url URL,允许为空
|
||||
@@ -38,7 +38,7 @@ public class UrlResource implements Resource, Serializable{
|
||||
this.url = url;
|
||||
this.name = ObjectUtil.defaultIfNull(name, (null != url) ? FileUtil.getName(url.getPath()) : null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构造
|
||||
* @param file 文件路径
|
||||
@@ -49,17 +49,17 @@ public class UrlResource implements Resource, Serializable{
|
||||
this.url = URLUtil.getURL(file);
|
||||
}
|
||||
//-------------------------------------------------------------------------------------- Constructor end
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public URL getUrl(){
|
||||
return this.url;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public InputStream getStream() throws NoResourceException{
|
||||
if(null == this.url){
|
||||
@@ -67,7 +67,7 @@ public class UrlResource implements Resource, Serializable{
|
||||
}
|
||||
return URLUtil.getStream(url);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获得File
|
||||
* @return {@link File}
|
||||
@@ -75,7 +75,7 @@ public class UrlResource implements Resource, Serializable{
|
||||
public File getFile(){
|
||||
return FileUtil.file(this.url);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 返回路径
|
||||
* @return 返回URL路径
|
||||
|
||||
@@ -6,7 +6,7 @@ import cn.hutool.core.io.FileUtil;
|
||||
|
||||
/**
|
||||
* Web root资源访问对象
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
* @since 4.1.11
|
||||
*/
|
||||
@@ -15,7 +15,7 @@ public class WebAppResource extends FileResource {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param path 相对于Web root的路径
|
||||
*/
|
||||
public WebAppResource(String path) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 针对ClassPath和文件中资源读取的封装,主要入口为工具类ResourceUtil
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 数据单位相关封装,包括DataUnit数据单位和DataSize数据大小
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
* @since 5.3.10
|
||||
*/
|
||||
|
||||
@@ -9,5 +9,5 @@ import cn.hutool.core.io.watch.watchers.IgnoreWatcher;
|
||||
*
|
||||
*/
|
||||
public class SimpleWatcher extends IgnoreWatcher{
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -12,14 +12,14 @@ import cn.hutool.core.util.URLUtil;
|
||||
/**
|
||||
* 监听工具类<br>
|
||||
* 主要负责文件监听器的快捷创建
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
* @since 3.1.0
|
||||
*/
|
||||
public class WatchUtil {
|
||||
/**
|
||||
* 创建并初始化监听
|
||||
*
|
||||
*
|
||||
* @param url URL
|
||||
* @param events 监听的事件列表
|
||||
* @return 监听对象
|
||||
@@ -30,7 +30,7 @@ public class WatchUtil {
|
||||
|
||||
/**
|
||||
* 创建并初始化监听
|
||||
*
|
||||
*
|
||||
* @param url URL
|
||||
* @param events 监听的事件列表
|
||||
* @param maxDepth 当监听目录时,监听目录的最大深度,当设置值为1(或小于1)时,表示不递归监听子目录
|
||||
@@ -42,7 +42,7 @@ public class WatchUtil {
|
||||
|
||||
/**
|
||||
* 创建并初始化监听
|
||||
*
|
||||
*
|
||||
* @param uri URI
|
||||
* @param events 监听的事件列表
|
||||
* @return 监听对象
|
||||
@@ -53,7 +53,7 @@ public class WatchUtil {
|
||||
|
||||
/**
|
||||
* 创建并初始化监听
|
||||
*
|
||||
*
|
||||
* @param uri URI
|
||||
* @param events 监听的事件列表
|
||||
* @param maxDepth 当监听目录时,监听目录的最大深度,当设置值为1(或小于1)时,表示不递归监听子目录
|
||||
@@ -65,7 +65,7 @@ public class WatchUtil {
|
||||
|
||||
/**
|
||||
* 创建并初始化监听
|
||||
*
|
||||
*
|
||||
* @param file 文件
|
||||
* @param events 监听的事件列表
|
||||
* @return 监听对象
|
||||
@@ -76,7 +76,7 @@ public class WatchUtil {
|
||||
|
||||
/**
|
||||
* 创建并初始化监听
|
||||
*
|
||||
*
|
||||
* @param file 文件
|
||||
* @param events 监听的事件列表
|
||||
* @param maxDepth 当监听目录时,监听目录的最大深度,当设置值为1(或小于1)时,表示不递归监听子目录
|
||||
@@ -88,7 +88,7 @@ public class WatchUtil {
|
||||
|
||||
/**
|
||||
* 创建并初始化监听
|
||||
*
|
||||
*
|
||||
* @param path 路径
|
||||
* @param events 监听的事件列表
|
||||
* @return 监听对象
|
||||
@@ -99,7 +99,7 @@ public class WatchUtil {
|
||||
|
||||
/**
|
||||
* 创建并初始化监听
|
||||
*
|
||||
*
|
||||
* @param path 路径
|
||||
* @param events 监听的事件列表
|
||||
* @param maxDepth 当监听目录时,监听目录的最大深度,当设置值为1(或小于1)时,表示不递归监听子目录
|
||||
@@ -111,7 +111,7 @@ public class WatchUtil {
|
||||
|
||||
/**
|
||||
* 创建并初始化监听
|
||||
*
|
||||
*
|
||||
* @param path 路径
|
||||
* @param events 监听事件列表
|
||||
* @return 监听对象
|
||||
@@ -122,7 +122,7 @@ public class WatchUtil {
|
||||
|
||||
/**
|
||||
* 创建并初始化监听
|
||||
*
|
||||
*
|
||||
* @param path 路径
|
||||
* @param events 监听事件列表
|
||||
* @param maxDepth 当监听目录时,监听目录的最大深度,当设置值为1(或小于1)时,表示不递归监听子目录
|
||||
@@ -135,7 +135,7 @@ public class WatchUtil {
|
||||
// ---------------------------------------------------------------------------------------------------------- createAll
|
||||
/**
|
||||
* 创建并初始化监听,监听所有事件
|
||||
*
|
||||
*
|
||||
* @param url URL
|
||||
* @param watcher {@link Watcher}
|
||||
* @return {@link WatchMonitor}
|
||||
@@ -143,10 +143,10 @@ public class WatchUtil {
|
||||
public static WatchMonitor createAll(URL url, Watcher watcher) {
|
||||
return createAll(url, 0, watcher);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建并初始化监听,监听所有事件
|
||||
*
|
||||
*
|
||||
* @param url URL
|
||||
* @param maxDepth 当监听目录时,监听目录的最大深度,当设置值为1(或小于1)时,表示不递归监听子目录
|
||||
* @param watcher {@link Watcher}
|
||||
@@ -155,10 +155,10 @@ public class WatchUtil {
|
||||
public static WatchMonitor createAll(URL url, int maxDepth, Watcher watcher) {
|
||||
return createAll(URLUtil.toURI(url), maxDepth, watcher);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建并初始化监听,监听所有事件
|
||||
*
|
||||
*
|
||||
* @param uri URI
|
||||
* @param watcher {@link Watcher}
|
||||
* @return {@link WatchMonitor}
|
||||
@@ -166,10 +166,10 @@ public class WatchUtil {
|
||||
public static WatchMonitor createAll(URI uri, Watcher watcher) {
|
||||
return createAll(uri, 0, watcher);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建并初始化监听,监听所有事件
|
||||
*
|
||||
*
|
||||
* @param uri URI
|
||||
* @param maxDepth 当监听目录时,监听目录的最大深度,当设置值为1(或小于1)时,表示不递归监听子目录
|
||||
* @param watcher {@link Watcher}
|
||||
@@ -181,7 +181,7 @@ public class WatchUtil {
|
||||
|
||||
/**
|
||||
* 创建并初始化监听,监听所有事件
|
||||
*
|
||||
*
|
||||
* @param file 被监听文件
|
||||
* @param watcher {@link Watcher}
|
||||
* @return {@link WatchMonitor}
|
||||
@@ -189,10 +189,10 @@ public class WatchUtil {
|
||||
public static WatchMonitor createAll(File file, Watcher watcher) {
|
||||
return createAll(file, 0, watcher);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建并初始化监听,监听所有事件
|
||||
*
|
||||
*
|
||||
* @param file 被监听文件
|
||||
* @param maxDepth 当监听目录时,监听目录的最大深度,当设置值为1(或小于1)时,表示不递归监听子目录
|
||||
* @param watcher {@link Watcher}
|
||||
@@ -204,7 +204,7 @@ public class WatchUtil {
|
||||
|
||||
/**
|
||||
* 创建并初始化监听,监听所有事件
|
||||
*
|
||||
*
|
||||
* @param path 路径
|
||||
* @param watcher {@link Watcher}
|
||||
* @return {@link WatchMonitor}
|
||||
@@ -212,10 +212,10 @@ public class WatchUtil {
|
||||
public static WatchMonitor createAll(String path, Watcher watcher) {
|
||||
return createAll(path, 0, watcher);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建并初始化监听,监听所有事件
|
||||
*
|
||||
*
|
||||
* @param path 路径
|
||||
* @param maxDepth 当监听目录时,监听目录的最大深度,当设置值为1(或小于1)时,表示不递归监听子目录
|
||||
* @param watcher {@link Watcher}
|
||||
@@ -227,7 +227,7 @@ public class WatchUtil {
|
||||
|
||||
/**
|
||||
* 创建并初始化监听,监听所有事件
|
||||
*
|
||||
*
|
||||
* @param path 路径
|
||||
* @param watcher {@link Watcher}
|
||||
* @return {@link WatchMonitor}
|
||||
@@ -235,10 +235,10 @@ public class WatchUtil {
|
||||
public static WatchMonitor createAll(Path path, Watcher watcher) {
|
||||
return createAll(path, 0, watcher);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建并初始化监听,监听所有事件
|
||||
*
|
||||
*
|
||||
* @param path 路径
|
||||
* @param maxDepth 当监听目录时,监听目录的最大深度,当设置值为1(或小于1)时,表示不递归监听子目录
|
||||
* @param watcher {@link Watcher}
|
||||
@@ -249,11 +249,11 @@ public class WatchUtil {
|
||||
watchMonitor.setWatcher(watcher);
|
||||
return watchMonitor;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------------- createModify
|
||||
/**
|
||||
* 创建并初始化监听,监听修改事件
|
||||
*
|
||||
*
|
||||
* @param url URL
|
||||
* @param watcher {@link Watcher}
|
||||
* @return {@link WatchMonitor}
|
||||
@@ -262,10 +262,10 @@ public class WatchUtil {
|
||||
public static WatchMonitor createModify(URL url, Watcher watcher) {
|
||||
return createModify(url, 0, watcher);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建并初始化监听,监听修改事件
|
||||
*
|
||||
*
|
||||
* @param url URL
|
||||
* @param maxDepth 当监听目录时,监听目录的最大深度,当设置值为1(或小于1)时,表示不递归监听子目录
|
||||
* @param watcher {@link Watcher}
|
||||
@@ -275,10 +275,10 @@ public class WatchUtil {
|
||||
public static WatchMonitor createModify(URL url, int maxDepth, Watcher watcher) {
|
||||
return createModify(URLUtil.toURI(url), maxDepth, watcher);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建并初始化监听,监听修改事件
|
||||
*
|
||||
*
|
||||
* @param uri URI
|
||||
* @param watcher {@link Watcher}
|
||||
* @return {@link WatchMonitor}
|
||||
@@ -287,10 +287,10 @@ public class WatchUtil {
|
||||
public static WatchMonitor createModify(URI uri, Watcher watcher) {
|
||||
return createModify(uri, 0, watcher);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建并初始化监听,监听修改事件
|
||||
*
|
||||
*
|
||||
* @param uri URI
|
||||
* @param maxDepth 当监听目录时,监听目录的最大深度,当设置值为1(或小于1)时,表示不递归监听子目录
|
||||
* @param watcher {@link Watcher}
|
||||
@@ -300,10 +300,10 @@ public class WatchUtil {
|
||||
public static WatchMonitor createModify(URI uri, int maxDepth, Watcher watcher) {
|
||||
return createModify(Paths.get(uri), maxDepth, watcher);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建并初始化监听,监听修改事件
|
||||
*
|
||||
*
|
||||
* @param file 被监听文件
|
||||
* @param watcher {@link Watcher}
|
||||
* @return {@link WatchMonitor}
|
||||
@@ -312,10 +312,10 @@ public class WatchUtil {
|
||||
public static WatchMonitor createModify(File file, Watcher watcher) {
|
||||
return createModify(file, 0, watcher);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建并初始化监听,监听修改事件
|
||||
*
|
||||
*
|
||||
* @param file 被监听文件
|
||||
* @param maxDepth 当监听目录时,监听目录的最大深度,当设置值为1(或小于1)时,表示不递归监听子目录
|
||||
* @param watcher {@link Watcher}
|
||||
@@ -325,10 +325,10 @@ public class WatchUtil {
|
||||
public static WatchMonitor createModify(File file, int maxDepth, Watcher watcher) {
|
||||
return createModify(file.toPath(), 0, watcher);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建并初始化监听,监听修改事件
|
||||
*
|
||||
*
|
||||
* @param path 路径
|
||||
* @param watcher {@link Watcher}
|
||||
* @return {@link WatchMonitor}
|
||||
@@ -337,10 +337,10 @@ public class WatchUtil {
|
||||
public static WatchMonitor createModify(String path, Watcher watcher) {
|
||||
return createModify(path, 0, watcher);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建并初始化监听,监听修改事件
|
||||
*
|
||||
*
|
||||
* @param path 路径
|
||||
* @param maxDepth 当监听目录时,监听目录的最大深度,当设置值为1(或小于1)时,表示不递归监听子目录
|
||||
* @param watcher {@link Watcher}
|
||||
@@ -350,10 +350,10 @@ public class WatchUtil {
|
||||
public static WatchMonitor createModify(String path, int maxDepth, Watcher watcher) {
|
||||
return createModify(Paths.get(path), maxDepth, watcher);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建并初始化监听,监听修改事件
|
||||
*
|
||||
*
|
||||
* @param path 路径
|
||||
* @param watcher {@link Watcher}
|
||||
* @return {@link WatchMonitor}
|
||||
@@ -362,10 +362,10 @@ public class WatchUtil {
|
||||
public static WatchMonitor createModify(Path path, Watcher watcher) {
|
||||
return createModify(path, 0, watcher);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建并初始化监听,监听修改事件
|
||||
*
|
||||
*
|
||||
* @param path 路径
|
||||
* @param maxDepth 当监听目录时,监听目录的最大深度,当设置值为1(或小于1)时,表示不递归监听子目录
|
||||
* @param watcher {@link Watcher}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 基于JDK7+ WatchService的文件和目录监听封装,支持多级目录
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -17,19 +17,19 @@ import java.util.Set;
|
||||
* 在监听目录或文件时,如果这个文件有修改操作,会多次触发modify方法。<br>
|
||||
* 此类通过维护一个Set将短时间内相同文件多次modify的事件合并处理触发,从而避免以上问题。<br>
|
||||
* 注意:延迟只针对modify事件,其它事件无效
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
* @since 3.1.0
|
||||
*/
|
||||
public class DelayWatcher implements Watcher {
|
||||
|
||||
|
||||
/** Path集合。此集合用于去重在指定delay内多次触发的文件Path */
|
||||
private final Set<Path> eventSet = new ConcurrentHashSet<>();
|
||||
/** 实际处理 */
|
||||
private final Watcher watcher;
|
||||
/** 延迟,单位毫秒 */
|
||||
private final long delay;
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------- Constructor start
|
||||
/**
|
||||
* 构造
|
||||
@@ -45,7 +45,7 @@ public class DelayWatcher implements Watcher {
|
||||
this.delay = delay;
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------- Constructor end
|
||||
|
||||
|
||||
@Override
|
||||
public void onModify(WatchEvent<?> event, Path currentPath) {
|
||||
if(this.delay < 1) {
|
||||
@@ -54,22 +54,22 @@ public class DelayWatcher implements Watcher {
|
||||
onDelayModify(event, currentPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(WatchEvent<?> event, Path currentPath) {
|
||||
watcher.onCreate(event, currentPath);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDelete(WatchEvent<?> event, Path currentPath) {
|
||||
watcher.onDelete(event, currentPath);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onOverflow(WatchEvent<?> event, Path currentPath) {
|
||||
watcher.onOverflow(event, currentPath);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------- Private method start
|
||||
/**
|
||||
* 触发延迟修改
|
||||
@@ -82,15 +82,15 @@ public class DelayWatcher implements Watcher {
|
||||
//此事件已经被触发过,后续事件忽略,等待统一处理。
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//事件第一次触发,此时标记事件,并启动处理线程延迟处理,处理结束后会删除标记
|
||||
eventSet.add(eventPath);
|
||||
startHandleModifyThread(event, currentPath);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 开启处理线程
|
||||
*
|
||||
*
|
||||
* @param event 事件
|
||||
* @param currentPath 事件发生的当前Path路径
|
||||
*/
|
||||
|
||||
@@ -8,7 +8,7 @@ import cn.hutool.core.io.watch.Watcher;
|
||||
/**
|
||||
* 跳过所有事件处理Watcher<br>
|
||||
* 用户继承此类后实现需要监听的方法
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
* @since 3.1.0
|
||||
*/
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.List;
|
||||
/**
|
||||
* 观察者链<br>
|
||||
* 用于加入多个观察者
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
* @since 3.1.0
|
||||
*/
|
||||
@@ -20,7 +20,7 @@ public class WatcherChain implements Watcher, Chain<Watcher, WatcherChain>{
|
||||
|
||||
/** 观察者列表 */
|
||||
final private List<Watcher> chain;
|
||||
|
||||
|
||||
/**
|
||||
* 创建观察者链{@link WatcherChain}
|
||||
* @param watchers 观察者列表
|
||||
@@ -29,7 +29,7 @@ public class WatcherChain implements Watcher, Chain<Watcher, WatcherChain>{
|
||||
public static WatcherChain create(Watcher... watchers) {
|
||||
return new WatcherChain(watchers);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构造
|
||||
* @param watchers 观察者列表
|
||||
@@ -37,7 +37,7 @@ public class WatcherChain implements Watcher, Chain<Watcher, WatcherChain>{
|
||||
public WatcherChain(Watcher... watchers) {
|
||||
chain = CollUtil.newArrayList(watchers);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(WatchEvent<?> event, Path currentPath) {
|
||||
for (Watcher watcher : chain) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 文件监听中的观察者实现类,包括延迟处理、处理链等
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -18,14 +18,14 @@ import java.util.TreeMap;
|
||||
*/
|
||||
public class ConsistentHash<T> implements Serializable{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
/** Hash计算对象,用于自定义hash算法 */
|
||||
Hash32<Object> hashFunc;
|
||||
/** 复制的节点个数 */
|
||||
private final int numberOfReplicas;
|
||||
/** 一致性Hash环 */
|
||||
private final SortedMap<Integer, T> circle = new TreeMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* 构造,使用Java默认的Hash算法
|
||||
* @param numberOfReplicas 复制的节点个数,增加每个节点的复制节点有利于负载均衡
|
||||
|
||||
@@ -13,7 +13,7 @@ public final class Holder<T> extends MutableObj<T>{
|
||||
|
||||
/**
|
||||
* 新建Holder类,持有指定值,当值为空时抛出空指针异常
|
||||
*
|
||||
*
|
||||
* @param <T> 被持有的对象类型
|
||||
* @param value 值,不能为空
|
||||
* @return Holder
|
||||
@@ -24,14 +24,14 @@ public final class Holder<T> extends MutableObj<T>{
|
||||
}
|
||||
return new Holder<>(value);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------- Constructor start
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public Holder() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构造
|
||||
* @param value 被包装的对象
|
||||
|
||||
@@ -14,16 +14,16 @@ import cn.hutool.core.util.StrUtil;
|
||||
/**
|
||||
* MongoDB ID生成策略实现<br>
|
||||
* ObjectId由以下几部分组成:
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* 1. Time 时间戳。
|
||||
* 2. Machine 所在主机的唯一标识符,一般是机器主机名的散列值。
|
||||
* 3. PID 进程ID。确保同一机器中不冲突
|
||||
* 4. INC 自增计数器。确保同一秒内产生objectId的唯一性。
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* 参考:http://blog.csdn.net/qxc1281/article/details/54021882
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
* @since 4.0.0
|
||||
*
|
||||
@@ -37,7 +37,7 @@ public class ObjectId {
|
||||
|
||||
/**
|
||||
* 给定的字符串是否为有效的ObjectId
|
||||
*
|
||||
*
|
||||
* @param s 字符串
|
||||
* @return 是否为有效的ObjectId
|
||||
*/
|
||||
@@ -70,7 +70,7 @@ public class ObjectId {
|
||||
|
||||
/**
|
||||
* 获取一个objectId的bytes表现形式
|
||||
*
|
||||
*
|
||||
* @return objectId
|
||||
* @since 4.1.15
|
||||
*/
|
||||
@@ -85,7 +85,7 @@ public class ObjectId {
|
||||
|
||||
/**
|
||||
* 获取一个objectId用下划线分割
|
||||
*
|
||||
*
|
||||
* @return objectId
|
||||
*/
|
||||
public static String next() {
|
||||
@@ -94,7 +94,7 @@ public class ObjectId {
|
||||
|
||||
/**
|
||||
* 获取一个objectId
|
||||
*
|
||||
*
|
||||
* @param withHyphen 是否包含分隔符
|
||||
* @return objectId
|
||||
*/
|
||||
@@ -119,7 +119,7 @@ public class ObjectId {
|
||||
// ----------------------------------------------------------------------------------------- Private method start
|
||||
/**
|
||||
* 获取机器码片段
|
||||
*
|
||||
*
|
||||
* @return 机器码片段
|
||||
*/
|
||||
private static int getMachinePiece() {
|
||||
@@ -146,7 +146,7 @@ public class ObjectId {
|
||||
|
||||
/**
|
||||
* 获取进程码片段
|
||||
*
|
||||
*
|
||||
* @return 进程码片段
|
||||
*/
|
||||
private static int getProcessPiece() {
|
||||
|
||||
@@ -9,20 +9,20 @@ import cn.hutool.core.util.StrUtil;
|
||||
|
||||
/**
|
||||
* {@link ParameterizedType} 接口实现,用于重新定义泛型类型
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
* @since 4.5.7
|
||||
*/
|
||||
public class ParameterizedTypeImpl implements ParameterizedType, Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
private final Type[] actualTypeArguments;
|
||||
private final Type ownerType;
|
||||
private final Type rawType;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param actualTypeArguments 实际的泛型参数类型
|
||||
* @param ownerType 拥有者类型
|
||||
* @param rawType 原始类型
|
||||
@@ -71,7 +71,7 @@ public class ParameterizedTypeImpl implements ParameterizedType, Serializable {
|
||||
|
||||
/**
|
||||
* 追加 {@code types} 到 @{code buf},使用 {@code sep} 分隔
|
||||
*
|
||||
*
|
||||
* @param buf 目标
|
||||
* @param sep 分隔符
|
||||
* @param types 加入的类型
|
||||
@@ -86,14 +86,14 @@ public class ParameterizedTypeImpl implements ParameterizedType, Serializable {
|
||||
} else {
|
||||
buf.append(sep);
|
||||
}
|
||||
|
||||
|
||||
String typeStr;
|
||||
if(type instanceof Class) {
|
||||
typeStr = ((Class<?>)type).getName();
|
||||
}else {
|
||||
typeStr = StrUtil.toString(type);
|
||||
}
|
||||
|
||||
|
||||
buf.append(typeStr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,11 +12,11 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
/**
|
||||
* 范围生成器。根据给定的初始值、结束值和步进生成一个步进列表生成器<br>
|
||||
* 由于用户自行实现{@link Steper}来定义步进,因此Range本身无法判定边界(是否达到end),需在step实现边界判定逻辑。
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* 此类使用{@link ReentrantReadWriteLock}保证线程安全
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
*
|
||||
* @param <T> 生成范围对象的类型
|
||||
@@ -45,7 +45,7 @@ public class Range<T> implements Iterable<T>, Iterator<T>, Serializable {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param start 起始对象
|
||||
* @param steper 步进
|
||||
*/
|
||||
@@ -55,7 +55,7 @@ public class Range<T> implements Iterable<T>, Iterator<T>, Serializable {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param start 起始对象(包含)
|
||||
* @param end 结束对象(包含)
|
||||
* @param steper 步进
|
||||
@@ -66,7 +66,7 @@ public class Range<T> implements Iterable<T>, Iterator<T>, Serializable {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param start 起始对象
|
||||
* @param end 结束对象
|
||||
* @param steper 步进
|
||||
@@ -86,7 +86,7 @@ public class Range<T> implements Iterable<T>, Iterator<T>, Serializable {
|
||||
|
||||
/**
|
||||
* 禁用锁,调用此方法后不在 使用锁保护
|
||||
*
|
||||
*
|
||||
* @return this
|
||||
* @since 4.3.1
|
||||
*/
|
||||
@@ -143,7 +143,7 @@ public class Range<T> implements Iterable<T>, Iterator<T>, Serializable {
|
||||
|
||||
/**
|
||||
* 不抛异常的获取下一步进的元素,如果获取失败返回{@code null}
|
||||
*
|
||||
*
|
||||
* @param base 上一个元素
|
||||
* @return 下一步进
|
||||
*/
|
||||
@@ -169,7 +169,7 @@ public class Range<T> implements Iterable<T>, Iterator<T>, Serializable {
|
||||
|
||||
/**
|
||||
* 重置{@link Range}
|
||||
*
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public Range<T> reset() {
|
||||
@@ -186,13 +186,13 @@ public class Range<T> implements Iterable<T>, Iterator<T>, Serializable {
|
||||
/**
|
||||
* 步进接口,此接口用于实现如何对一个对象按照指定步进增加步进<br>
|
||||
* 步进接口可以定义以下逻辑:
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* 1、步进规则,即对象如何做步进
|
||||
* 2、步进大小,通过实现此接口,在实现类中定义一个对象属性,可灵活定义步进大小
|
||||
* 3、限制range个数,通过实现此接口,在实现类中定义一个对象属性,可灵活定义limit,限制range个数
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
*
|
||||
* @param <T> 需要增加步进的对象
|
||||
@@ -202,7 +202,7 @@ public class Range<T> implements Iterable<T>, Iterator<T>, Serializable {
|
||||
* 增加步进<br>
|
||||
* 增加步进后的返回值如果为{@code null}则表示步进结束<br>
|
||||
* 用户需根据end参数自行定义边界,当达到边界时返回null表示结束,否则Range中边界对象无效,会导致无限循环
|
||||
*
|
||||
*
|
||||
* @param current 上一次增加步进后的基础对象
|
||||
* @param end 结束对象
|
||||
* @param index 当前索引(步进到第几个元素),从0开始计数
|
||||
|
||||
@@ -3,7 +3,7 @@ package cn.hutool.core.lang;
|
||||
/**
|
||||
* 替换器<br>
|
||||
* 通过实现此接口完成指定类型对象的替换操作,替换后的目标类型依旧为指定类型
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
* @param <T> 被替换操作的类型
|
||||
@@ -11,10 +11,10 @@ package cn.hutool.core.lang;
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface Replacer<T> {
|
||||
|
||||
|
||||
/**
|
||||
* 替换指定类型为目标类型
|
||||
*
|
||||
*
|
||||
* @param t 被替换的对象
|
||||
* @return 替代后的对象
|
||||
*/
|
||||
|
||||
@@ -7,17 +7,17 @@ import cn.hutool.core.util.TypeUtil;
|
||||
/**
|
||||
* Type类型参考<br>
|
||||
* 通过构建一个类型参考子类,可以获取其泛型参数中的Type类型。例如:
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* TypeReference<List<String>> list = new TypeReference<List<String>>() {};
|
||||
* Type t = tr.getType();
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* 此类无法应用于通配符泛型参数(wildcard parameters),比如:{@code Class<?>} 或者 {@code List? extends CharSequence>}
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* 此类参考FastJSON的TypeReference实现
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
* @param <T> 需要自定义的参考类型
|
||||
@@ -37,13 +37,13 @@ public abstract class TypeReference<T> implements Type {
|
||||
|
||||
/**
|
||||
* 获取用户定义的泛型参数
|
||||
*
|
||||
*
|
||||
* @return 泛型参数
|
||||
*/
|
||||
public Type getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.type.toString();
|
||||
|
||||
@@ -19,11 +19,11 @@ import java.util.TreeMap;
|
||||
* </p>
|
||||
* 总体思路:累加每个元素的权重A(1)-B(3)-C(6)-D(10),则4个元素的的权重管辖区间分别为[0,1)、[1,3)、[3,6)、[6,10)。<br>
|
||||
* 然后随机出一个[0,10)之间的随机数。落在哪个区间,则该区间之后的元素即为按权重命中的元素。<br>
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* 参考博客:https://www.cnblogs.com/waterystone/p/5708063.html
|
||||
* <p>
|
||||
*
|
||||
*
|
||||
* @param <T> 权重随机获取的对象类型
|
||||
* @author looly
|
||||
* @since 3.3.0
|
||||
@@ -55,7 +55,7 @@ public class WeightRandom<T> implements Serializable {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param weightObj 带有权重的对象
|
||||
*/
|
||||
public WeightRandom(WeightObj<T> weightObj) {
|
||||
@@ -67,7 +67,7 @@ public class WeightRandom<T> implements Serializable {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param weightObjs 带有权重的对象
|
||||
*/
|
||||
public WeightRandom(Iterable<WeightObj<T>> weightObjs) {
|
||||
@@ -81,7 +81,7 @@ public class WeightRandom<T> implements Serializable {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param weightObjs 带有权重的对象
|
||||
*/
|
||||
public WeightRandom(WeightObj<T>[] weightObjs) {
|
||||
@@ -94,7 +94,7 @@ public class WeightRandom<T> implements Serializable {
|
||||
|
||||
/**
|
||||
* 增加对象
|
||||
*
|
||||
*
|
||||
* @param obj 对象
|
||||
* @param weight 权重
|
||||
* @return this
|
||||
@@ -105,7 +105,7 @@ public class WeightRandom<T> implements Serializable {
|
||||
|
||||
/**
|
||||
* 增加对象权重
|
||||
*
|
||||
*
|
||||
* @param weightObj 权重对象
|
||||
* @return this
|
||||
*/
|
||||
@@ -122,7 +122,7 @@ public class WeightRandom<T> implements Serializable {
|
||||
|
||||
/**
|
||||
* 清空权重表
|
||||
*
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public WeightRandom<T> clear() {
|
||||
@@ -134,7 +134,7 @@ public class WeightRandom<T> implements Serializable {
|
||||
|
||||
/**
|
||||
* 下一个随机对象
|
||||
*
|
||||
*
|
||||
* @return 随机对象
|
||||
*/
|
||||
public T next() {
|
||||
@@ -149,7 +149,7 @@ public class WeightRandom<T> implements Serializable {
|
||||
|
||||
/**
|
||||
* 带有权重的对象包装
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
* @param <T> 对象类型
|
||||
@@ -162,7 +162,7 @@ public class WeightRandom<T> implements Serializable {
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
*
|
||||
* @param obj 对象
|
||||
* @param weight 权重
|
||||
*/
|
||||
@@ -173,7 +173,7 @@ public class WeightRandom<T> implements Serializable {
|
||||
|
||||
/**
|
||||
* 获取对象
|
||||
*
|
||||
*
|
||||
* @return 对象
|
||||
*/
|
||||
public T getObj() {
|
||||
@@ -182,7 +182,7 @@ public class WeightRandom<T> implements Serializable {
|
||||
|
||||
/**
|
||||
* 设置对象
|
||||
*
|
||||
*
|
||||
* @param obj 对象
|
||||
*/
|
||||
public void setObj(T obj) {
|
||||
@@ -191,7 +191,7 @@ public class WeightRandom<T> implements Serializable {
|
||||
|
||||
/**
|
||||
* 获取权重
|
||||
*
|
||||
*
|
||||
* @return 权重
|
||||
*/
|
||||
public double getWeight() {
|
||||
@@ -231,5 +231,5 @@ public class WeightRandom<T> implements Serializable {
|
||||
return Double.doubleToLongBits(weight) == Double.doubleToLongBits(other.weight);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,35 +3,35 @@ package cn.hutool.core.lang.caller;
|
||||
/**
|
||||
* 调用者接口<br>
|
||||
* 可以通过此接口的实现类方法获取调用者、多级调用者以及判断是否被调用
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
*
|
||||
*/
|
||||
public interface Caller {
|
||||
/**
|
||||
* 获得调用者
|
||||
*
|
||||
*
|
||||
* @return 调用者
|
||||
*/
|
||||
Class<?> getCaller();
|
||||
|
||||
/**
|
||||
* 获得调用者的调用者
|
||||
*
|
||||
*
|
||||
* @return 调用者的调用者
|
||||
*/
|
||||
Class<?> getCallerCaller();
|
||||
|
||||
/**
|
||||
* 获得调用者,指定第几级调用者 调用者层级关系:
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* 0 {@link CallerUtil}
|
||||
* 1 调用{@link CallerUtil}中方法的类
|
||||
* 2 调用者的调用者
|
||||
* ...
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @param depth 层级。0表示{@link CallerUtil}本身,1表示调用{@link CallerUtil}的类,2表示调用者的调用者,依次类推
|
||||
* @return 第几级调用者
|
||||
*/
|
||||
@@ -39,7 +39,7 @@ public interface Caller {
|
||||
|
||||
/**
|
||||
* 是否被指定类调用
|
||||
*
|
||||
*
|
||||
* @param clazz 调用者类
|
||||
* @return 是否被调用
|
||||
*/
|
||||
|
||||
@@ -2,7 +2,7 @@ package cn.hutool.core.lang.caller;
|
||||
|
||||
/**
|
||||
* 调用者。可以通过此类的方法获取调用者、多级调用者以及判断是否被调用
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
* @since 4.1.6
|
||||
*/
|
||||
@@ -14,7 +14,7 @@ public class CallerUtil {
|
||||
|
||||
/**
|
||||
* 获得调用者
|
||||
*
|
||||
*
|
||||
* @return 调用者
|
||||
*/
|
||||
public static Class<?> getCaller() {
|
||||
@@ -23,7 +23,7 @@ public class CallerUtil {
|
||||
|
||||
/**
|
||||
* 获得调用者的调用者
|
||||
*
|
||||
*
|
||||
* @return 调用者的调用者
|
||||
*/
|
||||
public static Class<?> getCallerCaller() {
|
||||
@@ -33,14 +33,14 @@ public class CallerUtil {
|
||||
/**
|
||||
* 获得调用者,指定第几级调用者<br>
|
||||
* 调用者层级关系:
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* 0 {@link CallerUtil}
|
||||
* 1 调用{@link CallerUtil}中方法的类
|
||||
* 2 调用者的调用者
|
||||
* ...
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @param depth 层级。0表示{@link CallerUtil}本身,1表示调用{@link CallerUtil}的类,2表示调用者的调用者,依次类推
|
||||
* @return 第几级调用者
|
||||
*/
|
||||
@@ -50,7 +50,7 @@ public class CallerUtil {
|
||||
|
||||
/**
|
||||
* 是否被指定类调用
|
||||
*
|
||||
*
|
||||
* @param clazz 调用者类
|
||||
* @return 是否被调用
|
||||
*/
|
||||
@@ -77,7 +77,7 @@ public class CallerUtil {
|
||||
|
||||
/**
|
||||
* 尝试创建{@link Caller}实现
|
||||
*
|
||||
*
|
||||
* @return {@link Caller}实现
|
||||
*/
|
||||
private static Caller tryCreateCaller() {
|
||||
@@ -90,7 +90,7 @@ public class CallerUtil {
|
||||
} catch (Throwable e) {
|
||||
//ignore
|
||||
}
|
||||
|
||||
|
||||
caller = new StackTraceCaller();
|
||||
return caller;
|
||||
}
|
||||
|
||||
@@ -6,12 +6,12 @@ import cn.hutool.core.util.ArrayUtil;
|
||||
|
||||
/**
|
||||
* {@link SecurityManager} 方式获取调用者
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
public class SecurityManagerCaller extends SecurityManager implements Caller, Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
private static final int OFFSET = 1;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,7 +6,7 @@ import cn.hutool.core.exceptions.UtilException;
|
||||
|
||||
/**
|
||||
* 通过StackTrace方式获取调用者。此方式效率最低,不推荐使用
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
public class StackTraceCaller implements Caller, Serializable {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 调用者接口及实现。可以通过此类的方法获取调用者、多级调用者以及判断是否被调用
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -7,7 +7,7 @@ import cn.hutool.core.lang.Filter;
|
||||
/**
|
||||
* 复制器抽象类<br>
|
||||
* 抽象复制器抽象了一个对象复制到另一个对象,通过实现{@link #copy()}方法实现复制逻辑。<br>
|
||||
*
|
||||
*
|
||||
* @author Looly
|
||||
*
|
||||
* @param <T> 拷贝的对象
|
||||
@@ -16,14 +16,14 @@ import cn.hutool.core.lang.Filter;
|
||||
*/
|
||||
public abstract class SrcToDestCopier<T, C extends SrcToDestCopier<T, C>> implements Copier<T>, Serializable{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
/** 源 */
|
||||
protected T src;
|
||||
/** 目标 */
|
||||
protected T dest;
|
||||
/** 拷贝过滤器,可以过滤掉不需要拷贝的源 */
|
||||
protected Filter<T> copyFilter;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------- Getters and Setters start
|
||||
/**
|
||||
* 获取源
|
||||
@@ -34,7 +34,7 @@ public abstract class SrcToDestCopier<T, C extends SrcToDestCopier<T, C>> implem
|
||||
}
|
||||
/**
|
||||
* 设置源
|
||||
*
|
||||
*
|
||||
* @param src 源
|
||||
* @return this
|
||||
*/
|
||||
@@ -46,7 +46,7 @@ public abstract class SrcToDestCopier<T, C extends SrcToDestCopier<T, C>> implem
|
||||
|
||||
/**
|
||||
* 获得目标
|
||||
*
|
||||
*
|
||||
* @return 目标
|
||||
*/
|
||||
public T getDest() {
|
||||
@@ -54,7 +54,7 @@ public abstract class SrcToDestCopier<T, C extends SrcToDestCopier<T, C>> implem
|
||||
}
|
||||
/**
|
||||
* 设置目标
|
||||
*
|
||||
*
|
||||
* @param dest 目标
|
||||
* @return this
|
||||
*/
|
||||
@@ -73,7 +73,7 @@ public abstract class SrcToDestCopier<T, C extends SrcToDestCopier<T, C>> implem
|
||||
}
|
||||
/**
|
||||
* 设置过滤器
|
||||
*
|
||||
*
|
||||
* @param copyFilter 过滤器
|
||||
* @return this
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 拷贝抽象实现,通过抽象拷贝,可以实现文件、流、Buffer之间的拷贝实现
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* 接口灵感来自于<a href="http://actframework.org/">ActFramework</a><br>
|
||||
* 一个函数接口代表一个一个函数,用于包装一个函数为对象<br>
|
||||
* 在JDK8之前,Java的函数并不能作为参数传递,也不能作为返回值存在,此接口用于将一个函数包装成为一个对象,从而传递对象
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 提供生成器接口及相关封装
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -9,12 +9,12 @@ import java.nio.charset.Charset;
|
||||
/**
|
||||
* Murmur3 32bit、64bit、128bit 哈希算法实现<br>
|
||||
* 此算法来自于:https://github.com/xlturing/Simhash4J/blob/master/src/main/java/bee/simhash/main/Murmur3.java
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* 32-bit Java port of https://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp#94 <br>
|
||||
* 128-bit Java port of https://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp#255
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @author looly,Simhash4J
|
||||
* @since 4.3.3
|
||||
*/
|
||||
@@ -41,7 +41,7 @@ public class MurmurHash implements Serializable{
|
||||
|
||||
private static final int DEFAULT_SEED = 0;
|
||||
private static final Charset DEFAULT_CHARSET = CharsetUtil.CHARSET_UTF_8;
|
||||
|
||||
|
||||
/**
|
||||
* Murmur3 32-bit Hash值计算
|
||||
*
|
||||
@@ -118,7 +118,7 @@ public class MurmurHash implements Serializable{
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Murmur3 64-bit Hash值计算
|
||||
*
|
||||
@@ -132,7 +132,7 @@ public class MurmurHash implements Serializable{
|
||||
/**
|
||||
* Murmur3 64-bit 算法<br>
|
||||
* This is essentially MSB 8 bytes of Murmur3 128-bit variant.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param data 数据
|
||||
* @return Hash值
|
||||
@@ -204,7 +204,7 @@ public class MurmurHash implements Serializable{
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Murmur3 128-bit Hash值计算
|
||||
*
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 提供Hash算法的封装
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -10,9 +10,9 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
* 1. 检查引用中是否有加载好的对象,有则返回
|
||||
* 2. 如果没有则初始化一个对象,并再次比较引用中是否有其它线程加载好的对象,无则加入,有则返回已有的
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* 当对象未被创建,对象的初始化操作在多线程情况下可能会被调用多次(多次创建对象),但是总是返回同一对象
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
* @param <T> 被加载对象类型
|
||||
@@ -44,7 +44,7 @@ public abstract class AtomicLoader<T> implements Loader<T>, Serializable {
|
||||
/**
|
||||
* 初始化被加载的对象<br>
|
||||
* 如果对象从未被加载过,调用此方法初始化加载对象,此方法只被调用一次
|
||||
*
|
||||
*
|
||||
* @return 被加载的对象
|
||||
*/
|
||||
protected abstract T init();
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.io.Serializable;
|
||||
* 在load方法被调用前,对象未被加载,直到被调用后才开始加载<br>
|
||||
* 此加载器常用于对象比较庞大而不一定被使用的情况,用于减少启动时资源占用问题<br>
|
||||
* 此加载器使用双重检查(Double-Check)方式检查对象是否被加载,避免多线程下重复加载或加载丢失问题
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
* @param <T> 被加载对象类型
|
||||
@@ -38,7 +38,7 @@ public abstract class LazyLoader<T> implements Loader<T>, Serializable {
|
||||
/**
|
||||
* 初始化被加载的对象<br>
|
||||
* 如果对象从未被加载过,调用此方法初始化加载对象,此方法只被调用一次
|
||||
*
|
||||
*
|
||||
* @return 被加载的对象
|
||||
*/
|
||||
protected abstract T init();
|
||||
|
||||
@@ -3,7 +3,7 @@ package cn.hutool.core.lang.loader;
|
||||
/**
|
||||
* 对象加载抽象接口<br>
|
||||
* 通过实现此接口自定义实现对象的加载方式,例如懒加载机制、多线程加载等
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
* @param <T> 对象类型
|
||||
@@ -14,7 +14,7 @@ public interface Loader<T> {
|
||||
/**
|
||||
* 获取一个准备好的对象<br>
|
||||
* 通过准备逻辑准备好被加载的对象,然后返回。在准备完毕之前此方法应该被阻塞
|
||||
*
|
||||
*
|
||||
* @return 加载完毕的对象
|
||||
*/
|
||||
T get();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 加载器的抽象接口和实现,包括懒加载的实现等
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -2,7 +2,7 @@ package cn.hutool.core.lang.mutable;
|
||||
|
||||
/**
|
||||
* 提供可变值类型接口
|
||||
*
|
||||
*
|
||||
* @param <T> 值得类型
|
||||
* @since 3.0.1
|
||||
*/
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user