This commit is contained in:
Looly
2019-09-28 03:13:27 +08:00
parent daf85caf9e
commit 596a4f1e57
110 changed files with 535 additions and 617 deletions

View File

@@ -1,10 +1,9 @@
package cn.hutool.aop.aspects; package cn.hutool.aop.aspects;
import java.lang.reflect.Method;
import cn.hutool.core.date.TimeInterval; import cn.hutool.core.date.TimeInterval;
import cn.hutool.core.lang.Console; import cn.hutool.core.lang.Console;
import cn.hutool.core.util.StrUtil;
import java.lang.reflect.Method;
/** /**
* 通过日志打印方法的执行时间的切面 * 通过日志打印方法的执行时间的切面

View File

@@ -1,15 +1,14 @@
package cn.hutool.aop.interceptor; package cn.hutool.aop.interceptor;
import cn.hutool.aop.aspects.Aspect;
import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.ReflectUtil;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import cn.hutool.aop.aspects.Aspect;
import cn.hutool.core.exceptions.UtilException;
import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.ReflectUtil;
/** /**
* JDK实现的动态代理切面 * JDK实现的动态代理切面
* *

View File

@@ -16,7 +16,7 @@ public interface BloomFilter extends Serializable{
* @param str 字符串 * @param str 字符串
* @return 判断一个字符串是否bitMap中存在 * @return 判断一个字符串是否bitMap中存在
*/ */
public boolean contains(String str); boolean contains(String str);
/** /**
* 在boolean的bitMap中增加一个字符串<br> * 在boolean的bitMap中增加一个字符串<br>
@@ -25,5 +25,5 @@ public interface BloomFilter extends Serializable{
* @param str 字符串 * @param str 字符串
* @return 是否加入成功,如果存在就返回<code>false</code> .如果不存在返回<code>true</code> * @return 是否加入成功,如果存在就返回<code>false</code> .如果不存在返回<code>true</code>
*/ */
public boolean add(String str); boolean add(String str);
} }

View File

@@ -8,22 +8,22 @@ package cn.hutool.bloomfilter.bitMap;
*/ */
public interface BitMap{ public interface BitMap{
public final int MACHINE32 = 32; int MACHINE32 = 32;
public final int MACHINE64 = 64; int MACHINE64 = 64;
/** /**
* 加入值 * 加入值
* *
* @param i 值 * @param i 值
*/ */
public void add(long i); void add(long i);
/** /**
* 检查是否包含值 * 检查是否包含值
* *
* @param i 值 * @param i 值
*/ */
public boolean contains(long i); boolean contains(long i);
/** /**
* 移除值 * 移除值

View File

@@ -30,7 +30,7 @@ public enum GlobalPruneTimer {
/** /**
* 构造 * 构造
*/ */
private GlobalPruneTimer() { GlobalPruneTimer() {
create(); create();
} }

View File

@@ -44,10 +44,8 @@ public class CacheObj<K, V> implements Serializable{
boolean isExpired() { boolean isExpired() {
if(this.ttl > 0) { if(this.ttl > 0) {
final long expiredTime = this.lastAccess + this.ttl; final long expiredTime = this.lastAccess + this.ttl;
if(expiredTime > 0 && expiredTime < System.currentTimeMillis()) {
// expiredTime > 0 杜绝Long类型溢出变负数问题当当前时间超过过期时间表示过期 // expiredTime > 0 杜绝Long类型溢出变负数问题当当前时间超过过期时间表示过期
return true; return expiredTime > 0 && expiredTime < System.currentTimeMillis();
}
} }
return false; return false;
} }

View File

@@ -183,8 +183,8 @@ public class ShearCaptcha extends AbstractCaptcha {
int dy = (int) ddy; int dy = (int) ddy;
// Now we can compute the corner points... // Now we can compute the corner points...
int xPoints[] = new int[4]; int[] xPoints = new int[4];
int yPoints[] = new int[4]; int[] yPoints = new int[4];
xPoints[0] = x1 + dx; xPoints[0] = x1 + dx;
yPoints[0] = y1 + dy; yPoints[0] = y1 + dy;

View File

@@ -14,7 +14,7 @@ public interface CodeGenerator extends Serializable{
* *
* @return 验证码 * @return 验证码
*/ */
public String generate(); String generate();
/** /**
* 验证用户输入的字符串是否与生成的验证码匹配<br> * 验证用户输入的字符串是否与生成的验证码匹配<br>
@@ -24,5 +24,5 @@ public interface CodeGenerator extends Serializable{
* @param userInputCode 用户输入的验证码 * @param userInputCode 用户输入的验证码
* @return 是否验证通过 * @return 是否验证通过
*/ */
public boolean verify(String code, String userInputCode); boolean verify(String code, String userInputCode);
} }

View File

@@ -23,7 +23,7 @@ public interface ValueProvider<T>{
* @param valueType 被注入的值得类型 * @param valueType 被注入的值得类型
* @return 对应参数名的值 * @return 对应参数名的值
*/ */
public Object value(T key, Type valueType); Object value(T key, Type valueType);
/** /**
* 是否包含指定KEY如果不包含则忽略注入<br> * 是否包含指定KEY如果不包含则忽略注入<br>
@@ -32,5 +32,5 @@ public interface ValueProvider<T>{
* @param key Bean对象中参数名 * @param key Bean对象中参数名
* @return 是否包含指定KEY * @return 是否包含指定KEY
*/ */
public boolean containsKey(T key); boolean containsKey(T key);
} }

View File

@@ -152,19 +152,9 @@ public class EqualsBuilder implements Builder<Boolean> {
} }
} }
/**
* If the fields tested are equals.
* The default value is <code>true</code>.
*/
/** 是否equals此值随着构建会变更默认true */ /** 是否equals此值随着构建会变更默认true */
private boolean isEquals = true; private boolean isEquals = true;
/**
* <p>Constructor for EqualsBuilder.</p>
*
* <p>Starts off assuming that equals is <code>true</code>.</p>
* @see Object#equals(Object)
*/
/** /**
* 构造初始状态值为true * 构造初始状态值为true
*/ */

View File

@@ -21,11 +21,12 @@ public class BCD {
asc = "0" + asc; asc = "0" + asc;
len = asc.length(); len = asc.length();
} }
byte abt[] = new byte[len]; byte[] abt;
if (len >= 2) { if (len >= 2) {
len >>= 1; len >>= 1;
} }
byte bbt[] = new byte[len]; byte[] bbt;
bbt = new byte[len];
abt = asc.getBytes(); abt = asc.getBytes();
int j; int j;
int k; int k;
@@ -82,7 +83,8 @@ public class BCD {
* @return ASCII字符串 * @return ASCII字符串
*/ */
public static String bcdToStr(byte[] bytes) { public static String bcdToStr(byte[] bytes) {
char temp[] = new char[bytes.length * 2], val; char[] temp = new char[bytes.length * 2];
char val;
for (int i = 0; i < bytes.length; i++) { for (int i = 0; i < bytes.length; i++) {
val = (char) (((bytes[i] & 0xf0) >> 4) & 0x0f); val = (char) (((bytes[i] & 0xf0) >> 4) & 0x0f);

View File

@@ -129,7 +129,7 @@ public class Base62Codec implements Serializable{
* @return 计算结果 * @return 计算结果
*/ */
private byte[] convert(byte[] message, int sourceBase, int targetBase) { private byte[] convert(byte[] message, int sourceBase, int targetBase) {
/** 计算结果长度算法来自http://codegolf.stackexchange.com/a/21672 */ // 计算结果长度算法来自http://codegolf.stackexchange.com/a/21672
final int estimatedLength = estimateOutputLength(message.length, sourceBase, targetBase); final int estimatedLength = estimateOutputLength(message.length, sourceBase, targetBase);
final ByteArrayOutputStream out = new ByteArrayOutputStream(estimatedLength); final ByteArrayOutputStream out = new ByteArrayOutputStream(estimatedLength);

View File

@@ -2,7 +2,6 @@ package cn.hutool.core.collection;
import java.io.Serializable; import java.io.Serializable;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
/** /**

View File

@@ -17,6 +17,6 @@ public interface Converter<T> {
* @return 转换后的值 * @return 转换后的值
* @throws IllegalArgumentException 无法确定目标类型,且默认值为{@code null},无法确定类型 * @throws IllegalArgumentException 无法确定目标类型,且默认值为{@code null},无法确定类型
*/ */
public T convert(Object value, T defaultValue) throws IllegalArgumentException; T convert(Object value, T defaultValue) throws IllegalArgumentException;
} }

View File

@@ -75,7 +75,7 @@ public class BetweenFormater implements Serializable{
} }
if(isLevelCountValid(levelCount) && 0 != millisecond && level >= Level.MILLSECOND.ordinal()){ if(isLevelCountValid(levelCount) && 0 != millisecond && level >= Level.MILLSECOND.ordinal()){
sb.append(millisecond).append(Level.MILLSECOND.name); sb.append(millisecond).append(Level.MILLSECOND.name);
levelCount++; // levelCount++;
} }
} }
@@ -123,7 +123,7 @@ public class BetweenFormater implements Serializable{
* *
* @author Looly * @author Looly
*/ */
public static enum Level { public enum Level {
/** 天 */ /** 天 */
DAY(""), DAY(""),
@@ -143,7 +143,7 @@ public class BetweenFormater implements Serializable{
* 构造 * 构造
* @param name 级别名称 * @param name 级别名称
*/ */
private Level(String name) { Level(String name) {
this.name = name; this.name = name;
} }

View File

@@ -105,7 +105,7 @@ public enum DateField {
// --------------------------------------------------------------- // ---------------------------------------------------------------
private int value; private int value;
private DateField(int value) { DateField(int value) {
this.value = value; this.value = value;
} }

View File

@@ -129,7 +129,7 @@ public class DateModifier {
* @author looly * @author looly
* *
*/ */
public static enum ModifyType { public enum ModifyType {
/** /**
* 取指定日期短的起始值. * 取指定日期短的起始值.
*/ */

View File

@@ -32,7 +32,7 @@ public class DateUtil {
/** /**
* java.util.Date EEE MMM zzz 缩写数组 * java.util.Date EEE MMM zzz 缩写数组
*/ */
private final static String wtb[] = { // private final static String[] wtb = { //
"sun", "mon", "tue", "wed", "thu", "fri", "sat", // 星期 "sun", "mon", "tue", "wed", "thu", "fri", "sat", // 星期
"jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec", // "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec", //
"gmt", "ut", "utc", "est", "edt", "cst", "cdt", "mst", "mdt", "pst", "pdt"// "gmt", "ut", "utc", "est", "edt", "cst", "cdt", "mst", "mdt", "pst", "pdt"//
@@ -461,7 +461,7 @@ public class DateUtil {
*/ */
public static LinkedHashSet<String> yearAndQuarter(Date startDate, Date endDate) { public static LinkedHashSet<String> yearAndQuarter(Date startDate, Date endDate) {
if (startDate == null || endDate == null) { if (startDate == null || endDate == null) {
return new LinkedHashSet<String>(0); return new LinkedHashSet<>(0);
} }
return yearAndQuarter(startDate.getTime(), endDate.getTime()); return yearAndQuarter(startDate.getTime(), endDate.getTime());
} }
@@ -608,9 +608,9 @@ public class DateUtil {
builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(1, 2)), false)); builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(1, 2)), false));
builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(2, 3)), false)); builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(2, 3)), false));
builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(3, 4)), false)); builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(3, 4)), false));
builder.append(format.substring(4, 5)); builder.append(format, 4, 5);
builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(5, 7)), false)); builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(5, 7)), false));
builder.append(format.substring(7, 8)); builder.append(format, 7, 8);
builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(8, 10)), false)); builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(8, 10)), false));
builder.append(format.substring(10)); builder.append(format.substring(10));
format = builder.toString().replace('零', ''); format = builder.toString().replace('零', '');
@@ -1888,7 +1888,7 @@ public class DateUtil {
* @param cal 日期 * @param cal 日期
*/ */
private static String yearAndQuarter(Calendar cal) { private static String yearAndQuarter(Calendar cal) {
return new StringBuilder().append(cal.get(Calendar.YEAR)).append(cal.get(Calendar.MONTH) / 3 + 1).toString(); return StrUtil.builder().append(cal.get(Calendar.YEAR)).append(cal.get(Calendar.MONTH) / 3 + 1).toString();
} }
/** /**
@@ -1937,7 +1937,7 @@ public class DateUtil {
final StringBuilder builder = StrUtil.builder(); final StringBuilder builder = StrUtil.builder();
// 日期部分("\"、"/"、"."、"年"、"月"都替换为"-" // 日期部分("\"、"/"、"."、"年"、"月"都替换为"-"
String datePart = dateAndTime.get(0).replaceAll("[\\/.年月]", "-"); String datePart = dateAndTime.get(0).replaceAll("[/.年月]", "-");
datePart = StrUtil.removeSuffix(datePart, ""); datePart = StrUtil.removeSuffix(datePart, "");
builder.append(datePart); builder.append(datePart);

View File

@@ -55,7 +55,7 @@ public enum Month {
// --------------------------------------------------------------- // ---------------------------------------------------------------
private int value; private int value;
private Month(int value) { Month(int value) {
this.value = value; this.value = value;
} }

View File

@@ -25,7 +25,7 @@ public enum Quarter {
// --------------------------------------------------------------- // ---------------------------------------------------------------
private int value; private int value;
private Quarter(int value) { Quarter(int value) {
this.value = value; this.value = value;
} }

View File

@@ -26,7 +26,7 @@ public enum Season {
// --------------------------------------------------------------- // ---------------------------------------------------------------
private int value; private int value;
private Season(int value) { Season(int value) {
this.value = value; this.value = value;
} }

View File

@@ -43,7 +43,7 @@ public enum Week {
* *
* @param value 星期对应{@link Calendar} 中的Week值 * @param value 星期对应{@link Calendar} 中的Week值
*/ */
private Week(int value) { Week(int value) {
this.value = value; this.value = value;
} }

View File

@@ -140,7 +140,7 @@ public interface OptBasicTypeGetter<K> {
* @param defaultValue 默认值 * @param defaultValue 默认值
* @return Enum类型的值无则返回Null * @return Enum类型的值无则返回Null
*/ */
public <E extends Enum<E>> E getEnum(Class<E> clazz, K key, E defaultValue); <E extends Enum<E>> E getEnum(Class<E> clazz, K key, E defaultValue);
/** /**
* 获取Date类型值 * 获取Date类型值

View File

@@ -389,8 +389,8 @@ public class ImgUtil {
try { try {
if (srcWidth > destWidth && srcHeight > destHeight) { if (srcWidth > destWidth && srcHeight > destHeight) {
int cols = 0; // 切片横向数量 int cols; // 切片横向数量
int rows = 0; // 切片纵向数量 int rows; // 切片纵向数量
// 计算切片的横向和纵向数量 // 计算切片的横向和纵向数量
if (srcWidth % destWidth == 0) { if (srcWidth % destWidth == 0) {
cols = srcWidth / destWidth; cols = srcWidth / destWidth;
@@ -1772,7 +1772,7 @@ public class ImgUtil {
return Color.LIGHT_GRAY; return Color.LIGHT_GRAY;
} else if ("GRAY".equals(colorName)) { } else if ("GRAY".equals(colorName)) {
return Color.GRAY; return Color.GRAY;
} else if ("DARK_GRAY".equals(colorName) || "DARK_GRAY".equals(colorName)) { } else if ("DARKGRAY".equals(colorName) || "DARK_GRAY".equals(colorName)) {
return Color.DARK_GRAY; return Color.DARK_GRAY;
} else if ("RED".equals(colorName)) { } else if ("RED".equals(colorName)) {
return Color.RED; return Color.RED;

View File

@@ -31,7 +31,7 @@ public enum ScaleType {
* @see Image#SCALE_REPLICATE * @see Image#SCALE_REPLICATE
* @see Image#SCALE_AREA_AVERAGING * @see Image#SCALE_AREA_AVERAGING
*/ */
private ScaleType(int value) { ScaleType(int value) {
this.value = value; this.value = value;
} }

View File

@@ -82,7 +82,7 @@ public class BOMInputStream extends InputStream {
return; return;
} }
byte bom[] = new byte[BOM_SIZE]; byte[] bom = new byte[BOM_SIZE];
int n, unread; int n, unread;
n = in.read(bom, 0, bom.length); n = in.read(bom, 0, bom.length);

View File

@@ -19,10 +19,7 @@ import cn.hutool.core.util.StrUtil;
* @author Looly * @author Looly
* *
*/ */
public final class FileTypeUtil { public class FileTypeUtil {
private FileTypeUtil() {
};
private static final Map<String, String> fileTypeMap; private static final Map<String, String> fileTypeMap;
@@ -42,7 +39,6 @@ public final class FileTypeUtil {
fileTypeMap.put("38425053000100000000", "psd"); // Photoshop (psd) fileTypeMap.put("38425053000100000000", "psd"); // Photoshop (psd)
fileTypeMap.put("46726f6d3a203d3f6762", "eml"); // Email [Outlook Express 6] (eml) fileTypeMap.put("46726f6d3a203d3f6762", "eml"); // Email [Outlook Express 6] (eml)
fileTypeMap.put("d0cf11e0a1b11ae10000", "doc"); // MS Excel 注意word、msi 和 excel的文件头一样 fileTypeMap.put("d0cf11e0a1b11ae10000", "doc"); // MS Excel 注意word、msi 和 excel的文件头一样
fileTypeMap.put("d0cf11e0a1b11ae10000", "vsd"); // Visio 绘图
fileTypeMap.put("5374616E64617264204A", "mdb"); // MS Access (mdb) fileTypeMap.put("5374616E64617264204A", "mdb"); // MS Access (mdb)
fileTypeMap.put("252150532D41646F6265", "ps"); fileTypeMap.put("252150532D41646F6265", "ps");
fileTypeMap.put("255044462d312e", "pdf"); // Adobe Acrobat (pdf) fileTypeMap.put("255044462d312e", "pdf"); // Adobe Acrobat (pdf)
@@ -70,7 +66,6 @@ public final class FileTypeUtil {
fileTypeMap.put("cafebabe0000002e0041", "class");// bat文件 fileTypeMap.put("cafebabe0000002e0041", "class");// bat文件
fileTypeMap.put("49545346030000006000", "chm");// bat文件 fileTypeMap.put("49545346030000006000", "chm");// bat文件
fileTypeMap.put("04000000010000001300", "mxp");// bat文件 fileTypeMap.put("04000000010000001300", "mxp");// bat文件
fileTypeMap.put("d0cf11e0a1b11ae10000", "wps");// WPS文字wps、表格et、演示dps都是一样的
fileTypeMap.put("6431303a637265617465", "torrent"); fileTypeMap.put("6431303a637265617465", "torrent");
fileTypeMap.put("6D6F6F76", "mov"); // Quicktime (mov) fileTypeMap.put("6D6F6F76", "mov"); // Quicktime (mov)
fileTypeMap.put("FF575043", "wpd"); // WordPerfect (wpd) fileTypeMap.put("FF575043", "wpd"); // WordPerfect (wpd)

View File

@@ -31,6 +31,7 @@ import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel; import java.nio.channels.WritableByteChannel;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.Collection; import java.util.Collection;
import java.util.Objects;
import java.util.zip.CRC32; import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream; import java.util.zip.CheckedInputStream;
import java.util.zip.Checksum; import java.util.zip.Checksum;
@@ -170,7 +171,7 @@ public class IoUtil {
} }
long size = 0; long size = 0;
try { try {
for (int readSize = -1; (readSize = in.read(buffer)) != EOF;) { for (int readSize; (readSize = in.read(buffer)) != EOF;) {
out.write(buffer, 0, readSize); out.write(buffer, 0, readSize);
size += readSize; size += readSize;
out.flush(); out.flush();
@@ -314,7 +315,7 @@ public class IoUtil {
return null; return null;
} }
InputStreamReader reader = null; InputStreamReader reader;
if (null == charset) { if (null == charset) {
reader = new InputStreamReader(in); reader = new InputStreamReader(in);
} else { } else {
@@ -605,7 +606,7 @@ public class IoUtil {
if (in == null) { if (in == null) {
throw new IllegalArgumentException("The InputStream must not be null"); throw new IllegalArgumentException("The InputStream must not be null");
} }
ObjectInputStream ois = null; ObjectInputStream ois;
try { try {
ois = new ObjectInputStream(in); ois = new ObjectInputStream(in);
@SuppressWarnings("unchecked") // may fail with CCE if serialised form is incorrect @SuppressWarnings("unchecked") // may fail with CCE if serialised form is incorrect
@@ -717,7 +718,7 @@ public class IoUtil {
// 从返回的内容中读取所需内容 // 从返回的内容中读取所需内容
final BufferedReader bReader = getReader(reader); final BufferedReader bReader = getReader(reader);
String line = null; String line;
try { try {
while ((line = bReader.readLine()) != null) { while ((line = bReader.readLine()) != null) {
lineHandler.handle(line); lineHandler.handle(line);
@@ -1092,11 +1093,11 @@ public class IoUtil {
try { try {
String line1 = br1.readLine(); String line1 = br1.readLine();
String line2 = br2.readLine(); String line2 = br2.readLine();
while (line1 != null && line2 != null && line1.equals(line2)) { while (line1 != null && line1.equals(line2)) {
line1 = br1.readLine(); line1 = br1.readLine();
line2 = br2.readLine(); line2 = br2.readLine();
} }
return line1 == null ? line2 == null ? true : false : line1.equals(line2); return Objects.equals(line1, line2);
} catch (IOException e) { } catch (IOException e) {
throw new IORuntimeException(e); throw new IORuntimeException(e);
} }

View File

@@ -10,16 +10,16 @@ public interface StreamProgress {
/** /**
* 开始 * 开始
*/ */
public void start(); void start();
/** /**
* 进行中 * 进行中
* @param progressSize 已经进行的大小 * @param progressSize 已经进行的大小
*/ */
public void progress(long progressSize); void progress(long progressSize);
/** /**
* 结束 * 结束
*/ */
public void finish(); void finish();
} }

View File

@@ -216,7 +216,7 @@ public class FileCopier extends SrcToDestCopier<File, FileCopier>{
throw new IORuntimeException(StrUtil.format("Src [{}] is a directory but dest [{}] is a file!", src.getPath(), dest.getPath())); throw new IORuntimeException(StrUtil.format("Src [{}] is a directory but dest [{}] is a file!", src.getPath(), dest.getPath()));
} }
final String files[] = src.list(); final String[] files = src.list();
File srcFile; File srcFile;
File destFile; File destFile;
for (String file : files) { for (String file : files) {

View File

@@ -14,6 +14,6 @@ public enum FileMode {
/** 打开以便读取和写入。相对于 "rw""rws" 还要求对“文件的内容”或“元数据”的每个更新都同步写入到基础存储设备。 */ /** 打开以便读取和写入。相对于 "rw""rws" 还要求对“文件的内容”或“元数据”的每个更新都同步写入到基础存储设备。 */
rws, rws,
/** 打开以便读取和写入,相对于 "rw""rwd" 还要求对“文件的内容”的每个更新都同步写入到基础存储设备。 */ /** 打开以便读取和写入,相对于 "rw""rwd" 还要求对“文件的内容”的每个更新都同步写入到基础存储设备。 */
rwd; rwd
} }

View File

@@ -209,7 +209,7 @@ public class FileReader extends FileWrapper {
*/ */
public <T> T read(ReaderHandler<T> readerHandler) throws IORuntimeException { public <T> T read(ReaderHandler<T> readerHandler) throws IORuntimeException {
BufferedReader reader = null; BufferedReader reader = null;
T result = null; T result;
try { try {
reader = FileUtil.getReader(this.file, charset); reader = FileUtil.getReader(this.file, charset);
result = readerHandler.handle(reader); result = readerHandler.handle(reader);
@@ -274,7 +274,7 @@ public class FileReader extends FileWrapper {
* @param <T> Reader处理返回结果类型 * @param <T> Reader处理返回结果类型
*/ */
public interface ReaderHandler<T> { public interface ReaderHandler<T> {
public T handle(BufferedReader reader) throws IOException; T handle(BufferedReader reader) throws IOException;
} }
// -------------------------------------------------------------------------- Interface end // -------------------------------------------------------------------------- Interface end

View File

@@ -25,7 +25,7 @@ public enum LineSeparator {
private String value; private String value;
private LineSeparator(String lineSeparator) { LineSeparator(String lineSeparator) {
this.value = lineSeparator; this.value = lineSeparator;
} }

View File

@@ -41,7 +41,7 @@ public class NoResourceException extends IORuntimeException {
*/ */
public boolean causeInstanceOf(Class<? extends Throwable> clazz) { public boolean causeInstanceOf(Class<? extends Throwable> clazz) {
Throwable cause = this.getCause(); Throwable cause = this.getCause();
if (null != cause && clazz.isInstance(cause)) { if (clazz.isInstance(cause)) {
return true; return true;
} }
return false; return false;

View File

@@ -13,7 +13,7 @@ public interface Watcher {
* @param event 事件 * @param event 事件
* @param currentPath 事件发生的当前Path路径 * @param currentPath 事件发生的当前Path路径
*/ */
public void onCreate(WatchEvent<?> event, Path currentPath); void onCreate(WatchEvent<?> event, Path currentPath);
/** /**
* 文件修改时执行的方法<br> * 文件修改时执行的方法<br>
@@ -21,19 +21,19 @@ public interface Watcher {
* @param event 事件 * @param event 事件
* @param currentPath 事件发生的当前Path路径 * @param currentPath 事件发生的当前Path路径
*/ */
public void onModify(WatchEvent<?> event, Path currentPath); void onModify(WatchEvent<?> event, Path currentPath);
/** /**
* 文件删除时执行的方法 * 文件删除时执行的方法
* @param event 事件 * @param event 事件
* @param currentPath 事件发生的当前Path路径 * @param currentPath 事件发生的当前Path路径
*/ */
public void onDelete(WatchEvent<?> event, Path currentPath); void onDelete(WatchEvent<?> event, Path currentPath);
/** /**
* 事件丢失或出错时执行的方法 * 事件丢失或出错时执行的方法
* @param event 事件 * @param event 事件
* @param currentPath 事件发生的当前Path路径 * @param currentPath 事件发生的当前Path路径
*/ */
public void onOverflow(WatchEvent<?> event, Path currentPath); void onOverflow(WatchEvent<?> event, Path currentPath);
} }

View File

@@ -108,6 +108,6 @@ public class ConsistentHash<T> implements Serializable{
* *
*/ */
public interface HashFunc { public interface HashFunc {
public Integer hash(Object key); Integer hash(Object key);
} }
} }

View File

@@ -19,5 +19,5 @@ public interface Editor<T> {
* @param t 被过滤的对象 * @param t 被过滤的对象
* @return 修改后的对象,如果被过滤返回<code>null</code> * @return 修改后的对象,如果被过滤返回<code>null</code>
*/ */
public T edit(T t); T edit(T t);
} }

View File

@@ -12,5 +12,5 @@ public interface Matcher<T>{
* @param t 对象 * @param t 对象
* @return 是否匹配 * @return 是否匹配
*/ */
public boolean match(T t); boolean match(T t);
} }

View File

@@ -196,7 +196,7 @@ public class Range<T> implements Iterable<T>, Iterator<T>, Serializable {
* *
* @param <T> 需要增加步进的对象 * @param <T> 需要增加步进的对象
*/ */
public static interface Steper<T> { public interface Steper<T> {
/** /**
* 增加步进<br> * 增加步进<br>
* 增加步进后的返回值如果为{@code null}则表示步进结束<br> * 增加步进后的返回值如果为{@code null}则表示步进结束<br>

View File

@@ -17,5 +17,5 @@ public interface Replacer<T> {
* @param t 被替换的对象 * @param t 被替换的对象
* @return 替代后的对象 * @return 替代后的对象
*/ */
public T replace(T t); T replace(T t);
} }

View File

@@ -55,16 +55,16 @@ public class NetUtil {
* @return IP V4 地址 * @return IP V4 地址
*/ */
public static String longToIpv4(long longIP) { public static String longToIpv4(long longIP) {
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = StrUtil.builder();
// 直接右移24位 // 直接右移24位
sb.append(String.valueOf(longIP >>> 24)); sb.append((longIP >>> 24));
sb.append("."); sb.append(".");
// 将高8位置0然后右移16位 // 将高8位置0然后右移16位
sb.append(String.valueOf((longIP & 0x00FFFFFF) >>> 16)); sb.append(((longIP & 0x00FFFFFF) >>> 16));
sb.append("."); sb.append(".");
sb.append(String.valueOf((longIP & 0x0000FFFF) >>> 8)); sb.append(((longIP & 0x0000FFFF) >>> 8));
sb.append("."); sb.append(".");
sb.append(String.valueOf(longIP & 0x000000FF)); sb.append((longIP & 0x000000FF));
return sb.toString(); return sb.toString();
} }
@@ -202,7 +202,7 @@ public class NetUtil {
* @return 是否为内网IP * @return 是否为内网IP
*/ */
public static boolean isInnerIP(String ipAddress) { public static boolean isInnerIP(String ipAddress) {
boolean isInnerIp = false; boolean isInnerIp;
long ipNum = NetUtil.ipv4ToLong(ipAddress); long ipNum = NetUtil.ipv4ToLong(ipAddress);
long aBegin = NetUtil.ipv4ToLong("10.0.0.0"); long aBegin = NetUtil.ipv4ToLong("10.0.0.0");
@@ -241,7 +241,7 @@ public class NetUtil {
* @return 隐藏部分后的IP * @return 隐藏部分后的IP
*/ */
public static String hideIpPart(String ip) { public static String hideIpPart(String ip) {
return new StringBuffer(ip.length()).append(ip.substring(0, ip.lastIndexOf(".") + 1)).append("*").toString(); return StrUtil.builder(ip.length()).append(ip, 0, ip.lastIndexOf(".") + 1).append("*").toString();
} }
/** /**
@@ -268,8 +268,8 @@ public class NetUtil {
host = LOCAL_IP; host = LOCAL_IP;
} }
String destHost = null; String destHost;
int port = 0; int port;
int index = host.indexOf(":"); int index = host.indexOf(":");
if (index != -1) { if (index != -1) {
// host:port形式 // host:port形式
@@ -304,7 +304,7 @@ public class NetUtil {
* @since 3.0.1 * @since 3.0.1
*/ */
public static Collection<NetworkInterface> getNetworkInterfaces() { public static Collection<NetworkInterface> getNetworkInterfaces() {
Enumeration<NetworkInterface> networkInterfaces = null; Enumeration<NetworkInterface> networkInterfaces;
try { try {
networkInterfaces = NetworkInterface.getNetworkInterfaces(); networkInterfaces = NetworkInterface.getNetworkInterfaces();
} catch (SocketException e) { } catch (SocketException e) {
@@ -386,7 +386,7 @@ public class NetUtil {
* @since 4.5.17 * @since 4.5.17
*/ */
public static LinkedHashSet<InetAddress> localAddressList(Filter<InetAddress> addressFilter) { public static LinkedHashSet<InetAddress> localAddressList(Filter<InetAddress> addressFilter) {
Enumeration<NetworkInterface> networkInterfaces = null; Enumeration<NetworkInterface> networkInterfaces;
try { try {
networkInterfaces = NetworkInterface.getNetworkInterfaces(); networkInterfaces = NetworkInterface.getNetworkInterfaces();
} catch (SocketException e) { } catch (SocketException e) {
@@ -460,8 +460,7 @@ public class NetUtil {
}); });
if (CollUtil.isNotEmpty(localAddressList)) { if (CollUtil.isNotEmpty(localAddressList)) {
InetAddress address = CollUtil.get(localAddressList, 0); return CollUtil.get(localAddressList, 0);
return address;
} }
try { try {
@@ -568,7 +567,7 @@ public class NetUtil {
* @param host Server主机 * @param host Server主机
* @param port Server端口 * @param port Server端口
* @param data 数据 * @param data 数据
* @throws IOException IO异常 * @throws IORuntimeException IO异常
* @since 3.3.0 * @since 3.3.0
*/ */
public static void netCat(String host, int port, byte[] data) throws IORuntimeException { public static void netCat(String host, int port, byte[] data) throws IORuntimeException {

View File

@@ -39,7 +39,7 @@ public enum ClipboardMonitor implements ClipboardOwner, Runnable, Closeable {
/** /**
* 构造尝试获取剪贴板内容的次数为10第二次之后延迟100毫秒 * 构造尝试获取剪贴板内容的次数为10第二次之后延迟100毫秒
*/ */
private ClipboardMonitor() { ClipboardMonitor() {
this(DEFAULT_TRY_COUNT, DEFAULT_DELAY); this(DEFAULT_TRY_COUNT, DEFAULT_DELAY);
} }
@@ -49,7 +49,7 @@ public enum ClipboardMonitor implements ClipboardOwner, Runnable, Closeable {
* @param tryCount 尝试获取剪贴板内容的次数 * @param tryCount 尝试获取剪贴板内容的次数
* @param delay 响应延迟当从第二次开始延迟一定毫秒数等待剪贴板可以获取当tryCount小于2时无效 * @param delay 响应延迟当从第二次开始延迟一定毫秒数等待剪贴板可以获取当tryCount小于2时无效
*/ */
private ClipboardMonitor(int tryCount, long delay) { ClipboardMonitor(int tryCount, long delay) {
this(tryCount, delay, ClipboardUtil.getClipboard()); this(tryCount, delay, ClipboardUtil.getClipboard());
} }
@@ -60,7 +60,7 @@ public enum ClipboardMonitor implements ClipboardOwner, Runnable, Closeable {
* @param delay 响应延迟当从第二次开始延迟一定毫秒数等待剪贴板可以获取当tryCount小于2时无效 * @param delay 响应延迟当从第二次开始延迟一定毫秒数等待剪贴板可以获取当tryCount小于2时无效
* @param clipboard 剪贴板对象 * @param clipboard 剪贴板对象
*/ */
private ClipboardMonitor(int tryCount, long delay, Clipboard clipboard) { ClipboardMonitor(int tryCount, long delay, Clipboard clipboard) {
this.tryCount = tryCount; this.tryCount = tryCount;
this.delay = delay; this.delay = delay;
this.clipboard = clipboard; this.clipboard = clipboard;

View File

@@ -25,7 +25,7 @@ public enum RejectPolicy {
private RejectedExecutionHandler value; private RejectedExecutionHandler value;
private RejectPolicy(RejectedExecutionHandler handler) { RejectPolicy(RejectedExecutionHandler handler) {
this.value = handler; this.value = handler;
} }

View File

@@ -77,9 +77,7 @@ public class BooleanUtil {
public static boolean toBoolean(String valueStr) { public static boolean toBoolean(String valueStr) {
if (StrUtil.isNotBlank(valueStr)) { if (StrUtil.isNotBlank(valueStr)) {
valueStr = valueStr.trim().toLowerCase(); valueStr = valueStr.trim().toLowerCase();
if (ArrayUtil.contains(TRUE_ARRAY, valueStr)) { return ArrayUtil.contains(TRUE_ARRAY, valueStr);
return true;
}
} }
return false; return false;
} }

View File

@@ -29,7 +29,6 @@ import cn.hutool.core.lang.Singleton;
* 类工具类 <br> * 类工具类 <br>
* *
* @author xiaoleilu * @author xiaoleilu
*
*/ */
public class ClassUtil { public class ClassUtil {
@@ -170,6 +169,7 @@ public class ClassUtil {
} }
// ----------------------------------------------------------------------------------------- Scan classes // ----------------------------------------------------------------------------------------- Scan classes
/** /**
* 扫描指定包路径下所有包含指定注解的类 * 扫描指定包路径下所有包含指定注解的类
* *
@@ -229,6 +229,7 @@ public class ClassUtil {
} }
// ----------------------------------------------------------------------------------------- Method // ----------------------------------------------------------------------------------------- Method
/** /**
* 获得指定类中的Public方法名<br> * 获得指定类中的Public方法名<br>
* 去重重载的方法 * 去重重载的方法
@@ -280,7 +281,7 @@ public class ClassUtil {
* @return 过滤后的方法列表 * @return 过滤后的方法列表
*/ */
public static List<Method> getPublicMethods(Class<?> clazz, String... excludeMethodNames) { public static List<Method> getPublicMethods(Class<?> clazz, String... excludeMethodNames) {
return getPublicMethods(clazz, excludeMethodNames); return ReflectUtil.getPublicMethods(clazz, excludeMethodNames);
} }
/** /**
@@ -344,6 +345,7 @@ public class ClassUtil {
} }
// ----------------------------------------------------------------------------------------- Field // ----------------------------------------------------------------------------------------- Field
/** /**
* 查找指定类中的所有字段包括非public字段 字段不存在则返回<code>null</code> * 查找指定类中的所有字段包括非public字段 字段不存在则返回<code>null</code>
* *
@@ -379,6 +381,7 @@ public class ClassUtil {
} }
// ----------------------------------------------------------------------------------------- Classpath // ----------------------------------------------------------------------------------------- Classpath
/** /**
* 获得ClassPath不解码路径中的特殊字符例如空格和中文 * 获得ClassPath不解码路径中的特殊字符例如空格和中文
* *
@@ -425,7 +428,7 @@ public class ClassUtil {
} catch (IOException e) { } catch (IOException e) {
throw new UtilException(e, "Loading classPath [{}] error!", packagePath); throw new UtilException(e, "Loading classPath [{}] error!", packagePath);
} }
final Set<String> paths = new HashSet<String>(); final Set<String> paths = new HashSet<>();
String path; String path;
while (resources.hasMoreElements()) { while (resources.hasMoreElements()) {
path = resources.nextElement().getPath(); path = resources.nextElement().getPath();
@@ -606,6 +609,7 @@ public class ClassUtil {
} }
// ---------------------------------------------------------------------------------------------------- Invoke start // ---------------------------------------------------------------------------------------------------- Invoke start
/** /**
* 执行方法<br> * 执行方法<br>
* 可执行Private方法也可执行static方法<br> * 可执行Private方法也可执行static方法<br>
@@ -782,18 +786,13 @@ public class ClassUtil {
if (targetType.isPrimitive()) { if (targetType.isPrimitive()) {
// 原始类型 // 原始类型
Class<?> resolvedPrimitive = BasicType.wrapperPrimitiveMap.get(sourceType); Class<?> resolvedPrimitive = BasicType.wrapperPrimitiveMap.get(sourceType);
if (resolvedPrimitive != null && targetType.equals(resolvedPrimitive)) { return targetType.equals(resolvedPrimitive);
return true;
}
} else { } else {
// 包装类型 // 包装类型
Class<?> resolvedWrapper = BasicType.primitiveWrapperMap.get(sourceType); Class<?> resolvedWrapper = BasicType.primitiveWrapperMap.get(sourceType);
if (resolvedWrapper != null && targetType.isAssignableFrom(resolvedWrapper)) { return resolvedWrapper != null && targetType.isAssignableFrom(resolvedWrapper);
return true;
} }
} }
return false;
}
/** /**
* 指定类是否为Public * 指定类是否为Public
@@ -908,7 +907,7 @@ public class ClassUtil {
* @since 3.2.0 * @since 3.2.0
*/ */
public static boolean isEnum(Class<?> clazz) { public static boolean isEnum(Class<?> clazz) {
return null == clazz ? false : clazz.isEnum(); return null != clazz && clazz.isEnum();
} }
/** /**
@@ -930,7 +929,7 @@ public class ClassUtil {
*/ */
public static Class<?> getTypeArgument(Class<?> clazz, int index) { public static Class<?> getTypeArgument(Class<?> clazz, int index) {
final Type argumentType = TypeUtil.getTypeArgument(clazz, index); final Type argumentType = TypeUtil.getTypeArgument(clazz, index);
if (null != argumentType && argumentType instanceof Class) { if (argumentType instanceof Class) {
return (Class<?>) argumentType; return (Class<?>) argumentType;
} }
return null; return null;
@@ -1038,9 +1037,8 @@ public class ClassUtil {
return false; return false;
} }
final String objectPackageName = objectPackage.getName(); final String objectPackageName = objectPackage.getName();
if (objectPackageName.startsWith("java.") || objectPackageName.startsWith("javax.") || clazz.getClassLoader() == null) { return objectPackageName.startsWith("java.") //
return true; || objectPackageName.startsWith("javax.") //
} || clazz.getClassLoader() == null;
return false;
} }
} }

View File

@@ -19,7 +19,7 @@ public class ModifierUtil {
* @author looly * @author looly
* @since 4.0.5 * @since 4.0.5
*/ */
public static enum ModifierType { public enum ModifierType {
/** public修饰符所有类都能访问 */ /** public修饰符所有类都能访问 */
PUBLIC(Modifier.PUBLIC), PUBLIC(Modifier.PUBLIC),
/** private修饰符只能被自己访问和修改 */ /** private修饰符只能被自己访问和修改 */
@@ -51,7 +51,7 @@ public class ModifierUtil {
* 构造 * 构造
* @param modifier 修饰符int表示见{@link Modifier} * @param modifier 修饰符int表示见{@link Modifier}
*/ */
private ModifierType(int modifier) { ModifierType(int modifier) {
this.value = modifier; this.value = modifier;
} }

View File

@@ -60,7 +60,7 @@ public class ReferenceUtil {
* @author looly * @author looly
* *
*/ */
public static enum ReferenceType { public enum ReferenceType {
/** 软引用在GC报告内存不足时会被GC回收 */ /** 软引用在GC报告内存不足时会被GC回收 */
SOFT, SOFT,
/** 弱引用在GC时发现弱引用会回收其对象 */ /** 弱引用在GC时发现弱引用会回收其对象 */
@@ -69,7 +69,7 @@ public class ReferenceUtil {
* 虚引用在GC时发现虚引用对象会将{@link PhantomReference}插入{@link ReferenceQueue}。 <br> * 虚引用在GC时发现虚引用对象会将{@link PhantomReference}插入{@link ReferenceQueue}。 <br>
* 此时对象未被真正回收,要等到{@link ReferenceQueue}被真正处理后才会被回收。 * 此时对象未被真正回收,要等到{@link ReferenceQueue}被真正处理后才会被回收。
*/ */
PHANTOM; PHANTOM
} }
} }

View File

@@ -1,15 +1,11 @@
package cn.hutool.core.convert; package cn.hutool.core.convert;
import java.util.ArrayList; import cn.hutool.core.date.DateUtil;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
import cn.hutool.core.lang.Console;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import cn.hutool.core.date.DateUtil; import java.util.ArrayList;
import java.util.Date;
/** /**
* 类型转换工具单元测试 * 类型转换工具单元测试

View File

@@ -42,8 +42,8 @@ public class ConvertToBeanTest {
person.setSubName("sub名字"); person.setSubName("sub名字");
Map<String, String> map = Convert.toMap(String.class, String.class, person); Map<String, String> map = Convert.toMap(String.class, String.class, person);
Assert.assertEquals(map.get("name"), "测试A11"); Assert.assertEquals("测试A11", map.get("name"));
Assert.assertEquals(map.get("age"), 14); Assert.assertEquals("14", map.get("age"));
Assert.assertEquals("11213232", map.get("openid")); Assert.assertEquals("11213232", map.get("openid"));
} }

View File

@@ -5,7 +5,6 @@ import cn.hutool.core.date.BetweenFormater.Level;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;

View File

@@ -1,13 +1,11 @@
package cn.hutool.core.util; package cn.hutool.core.util;
import java.util.Map;
import cn.hutool.core.lang.Console;
import org.junit.Assert;
import org.junit.Test;
import cn.hutool.core.lang.Editor; import cn.hutool.core.lang.Editor;
import cn.hutool.core.lang.Filter; import cn.hutool.core.lang.Filter;
import org.junit.Assert;
import org.junit.Test;
import java.util.Map;
/** /**
* {@link ArrayUtil} 数组工具单元测试 * {@link ArrayUtil} 数组工具单元测试

View File

@@ -52,10 +52,10 @@ public class EnumUtilTest {
Assert.assertEquals("type1", enumMap.get("TEST1")); Assert.assertEquals("type1", enumMap.get("TEST1"));
} }
public static enum TestEnum{ public enum TestEnum{
TEST1("type1"), TEST2("type2"), TEST3("type3"); TEST1("type1"), TEST2("type2"), TEST3("type3");
private TestEnum(String type) { TestEnum(String type) {
this.type = type; this.type = type;
} }

View File

@@ -13,14 +13,14 @@ public interface TaskListener {
* 定时任务启动时触发 * 定时任务启动时触发
* @param executor {@link TaskExecutor} * @param executor {@link TaskExecutor}
*/ */
public void onStart(TaskExecutor executor); void onStart(TaskExecutor executor);
/** /**
* 任务成功结束时触发 * 任务成功结束时触发
* *
* @param executor {@link TaskExecutor} * @param executor {@link TaskExecutor}
*/ */
public void onSucceeded(TaskExecutor executor); void onSucceeded(TaskExecutor executor);
/** /**
* 任务启动失败时触发 * 任务启动失败时触发
@@ -28,5 +28,5 @@ public interface TaskListener {
* @param executor {@link TaskExecutor} * @param executor {@link TaskExecutor}
* @param exception 异常 * @param exception 异常
*/ */
public void onFailed(TaskExecutor executor, Throwable exception); void onFailed(TaskExecutor executor, Throwable exception);
} }

View File

@@ -165,7 +165,7 @@ public class CronPattern {
boolean eval; boolean eval;
for (int i = 0; i < matcherSize; i++) { for (int i = 0; i < matcherSize; i++) {
eval = (isMatchSecond ? secondMatchers.get(i).match(second) : true) // 匹配秒非秒匹配模式下始终返回true eval = ((false == isMatchSecond) || secondMatchers.get(i).match(second)) // 匹配秒非秒匹配模式下始终返回true
&& minuteMatchers.get(i).match(minute)// 匹配分 && minuteMatchers.get(i).match(minute)// 匹配分
&& hourMatchers.get(i).match(hour)// 匹配时 && hourMatchers.get(i).match(hour)// 匹配时
&& isMatchDayOfMonth(dayOfMonthMatchers.get(i), dayOfMonth, month, calendar.isLeapYear(year))// 匹配日 && isMatchDayOfMonth(dayOfMonthMatchers.get(i), dayOfMonth, month, calendar.isLeapYear(year))// 匹配日
@@ -211,7 +211,7 @@ public class CronPattern {
* @since 4.0.2 * @since 4.0.2
*/ */
private static boolean isMatch(List<ValueMatcher> matchers, int index, int value) { private static boolean isMatch(List<ValueMatcher> matchers, int index, int value) {
return (matchers.size() > index) ? matchers.get(index).match(value) : true; return (matchers.size() <= index) || matchers.get(index).match(value);
} }
/** /**
@@ -253,7 +253,7 @@ public class CronPattern {
} }
// 分 // 分
try { try {
this.minuteMatchers.add(ValueMatcherBuilder.build(parts[0 + offset], MINUTE_VALUE_PARSER)); this.minuteMatchers.add(ValueMatcherBuilder.build(parts[offset], MINUTE_VALUE_PARSER));
} catch (Exception e) { } catch (Exception e) {
throw new CronException(e, "Invalid pattern [{}], parsing 'minute' field error!", pattern); throw new CronException(e, "Invalid pattern [{}], parsing 'minute' field error!", pattern);
} }

View File

@@ -19,19 +19,19 @@ public interface ValueParser {
* @param value String值 * @param value String值
* @return int * @return int
*/ */
public int parse(String value); int parse(String value);
/** /**
* 返回最小值 * 返回最小值
* *
* @return 最小值 * @return 最小值
*/ */
public int getMin(); int getMin();
/** /**
* 返回最大值 * 返回最大值
* *
* @return 最大值 * @return 最大值
*/ */
public int getMax(); int getMax();
} }

View File

@@ -61,7 +61,7 @@ public class InvokeTask implements Task{
@Override @Override
public void execute() { public void execute() {
try { try {
ReflectUtil.invoke(this.obj, this.method, new Object[]{}); ReflectUtil.invoke(this.obj, this.method);
} catch (UtilException e) { } catch (UtilException e) {
throw new CronException(e.getCause()); throw new CronException(e.getCause());
} }

View File

@@ -18,5 +18,5 @@ public interface Task {
* 作业的具体实现需考虑异常情况,默认情况下任务异常在监听中统一监听处理,如果不加入监听,异常会被忽略<br> * 作业的具体实现需考虑异常情况,默认情况下任务异常在监听中统一监听处理,如果不加入监听,异常会被忽略<br>
* 因此最好自行捕获异常后处理 * 因此最好自行捕获异常后处理
*/ */
public void execute(); void execute();
} }

View File

@@ -13,7 +13,7 @@ public enum GlobalBouncyCastleProvider {
private Provider provider; private Provider provider;
private static boolean useBouncyCastle = true; private static boolean useBouncyCastle = true;
private GlobalBouncyCastleProvider() { GlobalBouncyCastleProvider() {
try { try {
this.provider = ProviderFactory.createBouncyCastleProvider(); this.provider = ProviderFactory.createBouncyCastleProvider();
} catch (NoClassDefFoundError e) { } catch (NoClassDefFoundError e) {
@@ -33,7 +33,7 @@ public enum GlobalBouncyCastleProvider {
* 设置是否使用Bouncy Castle库<br> * 设置是否使用Bouncy Castle库<br>
* 如果设置为false表示强制关闭Bouncy Castle而使用JDK * 如果设置为false表示强制关闭Bouncy Castle而使用JDK
* *
* @param isUseBouncyCastle * @param isUseBouncyCastle 是否使用BouncyCastle库
* @since 4.5.2 * @since 4.5.2
*/ */
public static void setUseBouncyCastle(boolean isUseBouncyCastle) { public static void setUseBouncyCastle(boolean isUseBouncyCastle) {

View File

@@ -42,5 +42,5 @@ public enum Mode {
/** /**
* Propagating Cipher Block * Propagating Cipher Block
*/ */
PCBC; PCBC
} }

View File

@@ -23,7 +23,7 @@ public enum AsymmetricAlgorithm {
* 构造 * 构造
* @param value 算法字符表示,区分大小写 * @param value 算法字符表示,区分大小写
*/ */
private AsymmetricAlgorithm(String value) { AsymmetricAlgorithm(String value) {
this.value = value; this.value = value;
} }

View File

@@ -7,5 +7,5 @@ package cn.hutool.crypto.asymmetric;
* *
*/ */
public enum KeyType { public enum KeyType {
PrivateKey, PublicKey; PrivateKey, PublicKey
} }

View File

@@ -40,7 +40,7 @@ public enum SignAlgorithm {
* *
* @param value 算法字符表示,区分大小写 * @param value 算法字符表示,区分大小写
*/ */
private SignAlgorithm(String value) { SignAlgorithm(String value) {
this.value = value; this.value = value;
} }

View File

@@ -40,9 +40,9 @@ public class BCrypt {
private static final int BLOWFISH_NUM_ROUNDS = 16; private static final int BLOWFISH_NUM_ROUNDS = 16;
// Initial contents of key schedule // Initial contents of key schedule
private static final int P_orig[] = { 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, private static final int[] P_orig = {0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7,
0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b}; 0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b};
private static final int S_orig[] = { 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, private static final int[] S_orig = {0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8,
0x71574e69, 0xa458fea3, 0xf4933d7e, 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 0x71574e69, 0xa458fea3, 0xf4933d7e, 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, 0x55ca396a, 0x2aab10b6, 0xb4cc5c34,
0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, 0x3b8f4898, 0x6b4bb9af, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, 0x3b8f4898, 0x6b4bb9af,
@@ -115,20 +115,20 @@ public class BCrypt {
// bcrypt IV: "OrpheanBeholderScryDoubt". The C implementation calls // bcrypt IV: "OrpheanBeholderScryDoubt". The C implementation calls
// this "ciphertext", but it is really plaintext or an IV. We keep // this "ciphertext", but it is really plaintext or an IV. We keep
// the name to make code comparison easier. // the name to make code comparison easier.
static private final int bf_crypt_ciphertext[] = { 0x4f727068, 0x65616e42, 0x65686f6c, 0x64657253, 0x63727944, 0x6f756274 }; static private final int[] bf_crypt_ciphertext = {0x4f727068, 0x65616e42, 0x65686f6c, 0x64657253, 0x63727944, 0x6f756274};
// Table for Base64 encoding // Table for Base64 encoding
static private final char base64_code[] = { '.', '/', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', static private final char[] base64_code = {'.', '/', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b',
'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
// Table for Base64 decoding // Table for Base64 decoding
static private final byte index_64[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, static private final byte[] index_64 = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, 0, 1, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, -1, -1, -1, -1, -1, -1, -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, -1, -1, -1, -1, -1, -1, -1, 0, 1, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, -1, -1, -1, -1, -1, -1, -1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, -1, -1, -1, -1, -1, -1, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, -1, -1, -1, -1, -1}; 25, 26, 27, -1, -1, -1, -1, -1, -1, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, -1, -1, -1, -1, -1};
// Expanded Blowfish key // Expanded Blowfish key
private int P[]; private int[] P;
private int S[]; private int[] S;
/** /**
* Encode a byte array using bcrypt's slightly-modified base64 encoding scheme. Note that this is *not* compatible with the standard MIME-base64 encoding. * Encode a byte array using bcrypt's slightly-modified base64 encoding scheme. Note that this is *not* compatible with the standard MIME-base64 encoding.
@@ -136,11 +136,11 @@ public class BCrypt {
* @param d the byte array to encode * @param d the byte array to encode
* @param len the number of bytes to encode * @param len the number of bytes to encode
* @return base64-encoded string * @return base64-encoded string
* @exception IllegalArgumentException if the length is invalid * @throws IllegalArgumentException if the length is invalid
*/ */
private static String encode_base64(byte d[], int len) throws IllegalArgumentException { private static String encode_base64(byte[] d, int len) throws IllegalArgumentException {
int off = 0; int off = 0;
StringBuffer rs = new StringBuffer(); StringBuilder rs = new StringBuilder();
int c1, c2; int c1, c2;
if (len <= 0 || len > d.length) if (len <= 0 || len > d.length)
@@ -183,17 +183,18 @@ public class BCrypt {
} }
/** /**
* Decode a string encoded using bcrypt's base64 scheme to a byte array. Note that this is *not* compatible with the standard MIME-base64 encoding. * Decode a string encoded using bcrypt's base64 scheme to a byte array.<br>
* Note that this is *not* compatible with the standard MIME-base64 encoding.
* *
* @param s the string to decode * @param s the string to decode
* @param maxolen the maximum number of bytes to decode * @param maxolen the maximum number of bytes to decode
* @return an array containing the decoded bytes * @return an array containing the decoded bytes
* @throws IllegalArgumentException if maxolen is invalid * @throws IllegalArgumentException if maxolen is invalid
*/ */
private static byte[] decode_base64(String s, int maxolen) throws IllegalArgumentException { private static byte[] decodeBase64(String s, int maxolen) throws IllegalArgumentException {
StringBuffer rs = new StringBuffer(); StringBuffer rs = new StringBuffer();
int off = 0, slen = s.length(), olen = 0; int off = 0, slen = s.length(), olen = 0;
byte ret[]; byte[] ret;
byte c1, c2, c3, c4, o; byte c1, c2, c3, c4, o;
if (maxolen <= 0) if (maxolen <= 0)
@@ -236,7 +237,7 @@ public class BCrypt {
* @param lr an array containing the two 32-bit half blocks * @param lr an array containing the two 32-bit half blocks
* @param off the position in the array of the blocks * @param off the position in the array of the blocks
*/ */
private final void encipher(int lr[], int off) { private void encipher(int[] lr, int off) {
int i, n, l = lr[off], r = lr[off + 1]; int i, n, l = lr[off], r = lr[off + 1];
l ^= P[0]; l ^= P[0];
@@ -266,7 +267,7 @@ public class BCrypt {
* @param offp a "pointer" (as a one-entry array) to the current offset into data * @param offp a "pointer" (as a one-entry array) to the current offset into data
* @return the next word of material from data * @return the next word of material from data
*/ */
private static int streamtoword(byte data[], int offp[]) { private static int streamToWord(byte[] data, int[] offp) {
int i; int i;
int word = 0; int word = 0;
int off = offp[0]; int off = offp[0];
@@ -293,14 +294,14 @@ public class BCrypt {
* *
* @param key an array containing the key * @param key an array containing the key
*/ */
private void key(byte key[]) { private void key(byte[] key) {
int i; int i;
int koffp[] = { 0 }; int[] koffp = {0};
int lr[] = { 0, 0 }; int[] lr = {0, 0};
int plen = P.length, slen = S.length; int plen = P.length, slen = S.length;
for (i = 0; i < plen; i++) for (i = 0; i < plen; i++)
P[i] = P[i] ^ streamtoword(key, koffp); P[i] = P[i] ^ streamToWord(key, koffp);
for (i = 0; i < plen; i += 2) { for (i = 0; i < plen; i += 2) {
encipher(lr, 0); encipher(lr, 0);
@@ -321,26 +322,27 @@ public class BCrypt {
* @param data salt information * @param data salt information
* @param key password information * @param key password information
*/ */
private void ekskey(byte data[], byte key[]) { private void ekskey(byte[] data, byte[] key) {
int i; int i;
int koffp[] = { 0 }, doffp[] = { 0 }; int[] koffp = {0};
int lr[] = { 0, 0 }; int[] doffp = {0};
int[] lr = {0, 0};
int plen = P.length, slen = S.length; int plen = P.length, slen = S.length;
for (i = 0; i < plen; i++) for (i = 0; i < plen; i++)
P[i] = P[i] ^ streamtoword(key, koffp); P[i] = P[i] ^ streamToWord(key, koffp);
for (i = 0; i < plen; i += 2) { for (i = 0; i < plen; i += 2) {
lr[0] ^= streamtoword(data, doffp); lr[0] ^= streamToWord(data, doffp);
lr[1] ^= streamtoword(data, doffp); lr[1] ^= streamToWord(data, doffp);
encipher(lr, 0); encipher(lr, 0);
P[i] = lr[0]; P[i] = lr[0];
P[i + 1] = lr[1]; P[i + 1] = lr[1];
} }
for (i = 0; i < slen; i += 2) { for (i = 0; i < slen; i += 2) {
lr[0] ^= streamtoword(data, doffp); lr[0] ^= streamToWord(data, doffp);
lr[1] ^= streamtoword(data, doffp); lr[1] ^= streamToWord(data, doffp);
encipher(lr, 0); encipher(lr, 0);
S[i] = lr[0]; S[i] = lr[0];
S[i + 1] = lr[1]; S[i + 1] = lr[1];
@@ -356,10 +358,10 @@ public class BCrypt {
* @param cdata 加密数据 * @param cdata 加密数据
* @return 加密后的密文 * @return 加密后的密文
*/ */
public byte[] crypt(byte password[], byte salt[], int log_rounds, int cdata[]) { public byte[] crypt(byte[] password, byte[] salt, int log_rounds, int[] cdata) {
int rounds, i, j; int rounds, i, j;
int clen = cdata.length; int clen = cdata.length;
byte ret[]; byte[] ret;
if (log_rounds < 4 || log_rounds > 30) if (log_rounds < 4 || log_rounds > 30)
throw new IllegalArgumentException("Bad number of rounds"); throw new IllegalArgumentException("Bad number of rounds");
@@ -409,9 +411,10 @@ public class BCrypt {
public static String hashpw(String password, String salt) { public static String hashpw(String password, String salt) {
BCrypt bcrypt; BCrypt bcrypt;
String real_salt; String real_salt;
byte saltb[], hashed[]; byte[] saltb;
byte[] hashed;
char minor = (char) 0; char minor = (char) 0;
int rounds, off = 0; int rounds, off;
StringBuilder rs = new StringBuilder(); StringBuilder rs = new StringBuilder();
if (salt.charAt(0) != '$' || salt.charAt(1) != '2') if (salt.charAt(0) != '$' || salt.charAt(1) != '2')
@@ -432,7 +435,7 @@ public class BCrypt {
real_salt = salt.substring(off + 3, off + 25); real_salt = salt.substring(off + 3, off + 25);
byte[] passwordb = (password + (minor >= 'a' ? "\000" : "")).getBytes(CharsetUtil.CHARSET_UTF_8); byte[] passwordb = (password + (minor >= 'a' ? "\000" : "")).getBytes(CharsetUtil.CHARSET_UTF_8);
saltb = decode_base64(real_salt, BCRYPT_SALT_LEN); saltb = decodeBase64(real_salt, BCRYPT_SALT_LEN);
bcrypt = new BCrypt(); bcrypt = new BCrypt();
hashed = bcrypt.crypt(passwordb, saltb, rounds, (int[]) bf_crypt_ciphertext.clone()); hashed = bcrypt.crypt(passwordb, saltb, rounds, (int[]) bf_crypt_ciphertext.clone());
@@ -446,7 +449,7 @@ public class BCrypt {
if (rounds > 30) { if (rounds > 30) {
throw new IllegalArgumentException("rounds exceeds maximum (30)"); throw new IllegalArgumentException("rounds exceeds maximum (30)");
} }
rs.append(Integer.toString(rounds)); rs.append(rounds);
rs.append("$"); rs.append("$");
rs.append(encode_base64(saltb, saltb.length)); rs.append(encode_base64(saltb, saltb.length));
rs.append(encode_base64(hashed, bf_crypt_ciphertext.length * 4 - 1)); rs.append(encode_base64(hashed, bf_crypt_ciphertext.length * 4 - 1));
@@ -462,7 +465,7 @@ public class BCrypt {
*/ */
public static String gensalt(int log_rounds, SecureRandom random) { public static String gensalt(int log_rounds, SecureRandom random) {
final StringBuilder rs = new StringBuilder(); final StringBuilder rs = new StringBuilder();
byte rnd[] = new byte[BCRYPT_SALT_LEN]; byte[] rnd = new byte[BCRYPT_SALT_LEN];
random.nextBytes(rnd); random.nextBytes(rnd);
@@ -472,7 +475,7 @@ public class BCrypt {
if (log_rounds > 30) { if (log_rounds > 30) {
throw new IllegalArgumentException("log_rounds exceeds maximum (30)"); throw new IllegalArgumentException("log_rounds exceeds maximum (30)");
} }
rs.append(Integer.toString(log_rounds)); rs.append(log_rounds);
rs.append("$"); rs.append("$");
rs.append(encode_base64(rnd, rnd.length)); rs.append(encode_base64(rnd, rnd.length));
return rs.toString(); return rs.toString();
@@ -505,8 +508,8 @@ public class BCrypt {
* @return 是否匹配 * @return 是否匹配
*/ */
public static boolean checkpw(String plaintext, String hashed) { public static boolean checkpw(String plaintext, String hashed) {
byte hashed_bytes[]; byte[] hashed_bytes;
byte try_bytes[]; byte[] try_bytes;
String try_pw = hashpw(plaintext, hashed); String try_pw = hashpw(plaintext, hashed);
hashed_bytes = hashed.getBytes(CharsetUtil.CHARSET_UTF_8); hashed_bytes = hashed.getBytes(CharsetUtil.CHARSET_UTF_8);
try_bytes = try_pw.getBytes(CharsetUtil.CHARSET_UTF_8); try_bytes = try_pw.getBytes(CharsetUtil.CHARSET_UTF_8);

View File

@@ -21,7 +21,7 @@ public enum DigestAlgorithm {
* *
* @param value 算法字符串表示 * @param value 算法字符串表示
*/ */
private DigestAlgorithm(String value) { DigestAlgorithm(String value) {
this.value = value; this.value = value;
} }

View File

@@ -28,7 +28,7 @@ public enum SymmetricAlgorithm {
* 构造 * 构造
* @param value 算法的字符串表示,区分大小写 * @param value 算法的字符串表示,区分大小写
*/ */
private SymmetricAlgorithm(String value) { SymmetricAlgorithm(String value) {
this.value = value; this.value = value;
} }

View File

@@ -1,8 +1,5 @@
package cn.hutool.crypto.test; package cn.hutool.crypto.test;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.KeyUtil; import cn.hutool.crypto.KeyUtil;
import cn.hutool.crypto.Mode; import cn.hutool.crypto.Mode;

View File

@@ -1,23 +1,15 @@
package cn.hutool.crypto.test; package cn.hutool.crypto.test;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.RandomUtil;
import org.junit.Assert;
import org.junit.Test;
import cn.hutool.core.util.CharsetUtil; import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.KeyUtil; import cn.hutool.crypto.KeyUtil;
import cn.hutool.crypto.Mode; import cn.hutool.crypto.Mode;
import cn.hutool.crypto.Padding; import cn.hutool.crypto.Padding;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES; import cn.hutool.crypto.symmetric.*;
import cn.hutool.crypto.symmetric.DES; import org.junit.Assert;
import cn.hutool.crypto.symmetric.DESede; import org.junit.Test;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;
import cn.hutool.crypto.symmetric.Vigenere;
/** /**
* 对称加密算法单元测试 * 对称加密算法单元测试

View File

@@ -1,12 +1,5 @@
package cn.hutool.db.dialect.impl; package cn.hutool.db.dialect.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ArrayUtil;
@@ -17,11 +10,11 @@ import cn.hutool.db.Page;
import cn.hutool.db.StatementUtil; import cn.hutool.db.StatementUtil;
import cn.hutool.db.dialect.Dialect; import cn.hutool.db.dialect.Dialect;
import cn.hutool.db.dialect.DialectName; import cn.hutool.db.dialect.DialectName;
import cn.hutool.db.sql.Condition; import cn.hutool.db.sql.*;
import cn.hutool.db.sql.LogicalOperator;
import cn.hutool.db.sql.Query; import java.sql.Connection;
import cn.hutool.db.sql.SqlBuilder; import java.sql.PreparedStatement;
import cn.hutool.db.sql.Wrapper; import java.sql.SQLException;
/** /**
* ANSI SQL 方言 * ANSI SQL 方言

View File

@@ -193,12 +193,9 @@ public abstract class AbstractDSFactory extends DSFactory {
return false; return false;
} }
if (setting == null) { if (setting == null) {
if (other.setting != null) { return other.setting == null;
return false; } else {
} return setting.equals(other.setting);
} else if (!setting.equals(other.setting)) { }
return false;
}
return true;
} }
} }

View File

@@ -14,7 +14,7 @@ public class GlobalDSFactory {
private static volatile DSFactory factory; private static volatile DSFactory factory;
private static Object lock = new Object(); private static Object lock = new Object();
/** /*
* 设置在JVM关闭时关闭所有数据库连接 * 设置在JVM关闭时关闭所有数据库连接
*/ */
static { static {

View File

@@ -28,5 +28,5 @@ public interface RsHandler<T> extends Serializable{
* @return 处理后生成的对象 * @return 处理后生成的对象
* @throws SQLException SQL异常 * @throws SQLException SQL异常
*/ */
public T handle(ResultSet rs) throws SQLException; T handle(ResultSet rs) throws SQLException;
} }

View File

@@ -10,12 +10,12 @@ import java.util.StringTokenizer;
* @author looly * @author looly
*/ */
public class SqlFormatter { public class SqlFormatter {
private static final Set<String> BEGIN_CLAUSES = new HashSet<String>(); private static final Set<String> BEGIN_CLAUSES = new HashSet<>();
private static final Set<String> END_CLAUSES = new HashSet<String>(); private static final Set<String> END_CLAUSES = new HashSet<>();
private static final Set<String> LOGICAL = new HashSet<String>(); private static final Set<String> LOGICAL = new HashSet<>();
private static final Set<String> QUANTIFIERS = new HashSet<String>(); private static final Set<String> QUANTIFIERS = new HashSet<>();
private static final Set<String> DML = new HashSet<String>(); private static final Set<String> DML = new HashSet<>();
private static final Set<String> MISC = new HashSet<String>(); private static final Set<String> MISC = new HashSet<>();
static { static {
BEGIN_CLAUSES.add("left"); BEGIN_CLAUSES.add("left");
@@ -31,7 +31,6 @@ public class SqlFormatter {
END_CLAUSES.add("join"); END_CLAUSES.add("join");
END_CLAUSES.add("from"); END_CLAUSES.add("from");
END_CLAUSES.add("by"); END_CLAUSES.add("by");
END_CLAUSES.add("join");
END_CLAUSES.add("into"); END_CLAUSES.add("into");
END_CLAUSES.add("union"); END_CLAUSES.add("union");
@@ -55,8 +54,8 @@ public class SqlFormatter {
MISC.add("on"); MISC.add("on");
} }
private static String indentString = " "; private static final String indentString = " ";
private static String initial = "\n "; private static final String initial = "\n ";
public static String format(String source) { public static String format(String source) {
return new FormatProcess(source).perform().trim(); return new FormatProcess(source).perform().trim();
@@ -74,8 +73,8 @@ public class SqlFormatter {
boolean afterInsert = false; boolean afterInsert = false;
int inFunction = 0; int inFunction = 0;
int parensSinceSelect = 0; int parensSinceSelect = 0;
private LinkedList<Integer> parenCounts = new LinkedList<Integer>(); private LinkedList<Integer> parenCounts = new LinkedList<>();
private LinkedList<Boolean> afterByOrFromOrSelects = new LinkedList<Boolean>(); private LinkedList<Boolean> afterByOrFromOrSelects = new LinkedList<>();
int indent = 1; int indent = 1;
@@ -141,7 +140,7 @@ public class SqlFormatter {
misc(); misc();
} }
if (!isWhitespace(this.token)) { if (false == isWhitespace(this.token)) {
this.lastToken = this.lcToken; this.lastToken = this.lcToken;
} }
} }
@@ -313,7 +312,7 @@ public class SqlFormatter {
} }
private static boolean isWhitespace(String token) { private static boolean isWhitespace(String token) {
return " \n\r\f\t".indexOf(token) >= 0; return " \n\r\f\t".contains(token);
} }
private void newline() { private void newline() {

View File

@@ -60,7 +60,7 @@ public enum TransactionLevel {
/** 事务级别对应Connection中的常量值 */ /** 事务级别对应Connection中的常量值 */
private int level; private int level;
private TransactionLevel(int level) { TransactionLevel(int level) {
this.level = level; this.level = level;
} }

View File

@@ -13,5 +13,5 @@ public enum FtpMode {
/** 主动模式 */ /** 主动模式 */
Active, Active,
/** 被动模式 */ /** 被动模式 */
Passive; Passive
} }

View File

@@ -16,7 +16,7 @@ public enum GlobalMailAccount {
/** /**
* 构造 * 构造
*/ */
private GlobalMailAccount() { GlobalMailAccount() {
mailAccount = createDefaultAccount(); mailAccount = createDefaultAccount();
} }

View File

@@ -1,14 +1,13 @@
package cn.hutool.extra.mail; package cn.hutool.extra.mail;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.setting.Setting;
import java.io.Serializable; import java.io.Serializable;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.Properties; import java.util.Properties;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.setting.Setting;
/** /**
* 邮件账户对象 * 邮件账户对象
* *

View File

@@ -68,7 +68,7 @@ public class UploadFile {
* 写入后原临时文件会被删除 * 写入后原临时文件会被删除
* @param destPath 目标文件路径 * @param destPath 目标文件路径
* @return 目标文件 * @return 目标文件
* @throws IOException * @throws IOException IO异常
*/ */
public File write(String destPath) throws IOException { public File write(String destPath) throws IOException {
if(data != null || tempFile != null) { if(data != null || tempFile != null) {
@@ -100,12 +100,9 @@ public class UploadFile {
return destination; return destination;
} }
/**
* Returns the content of file upload item.
*/
/** /**
* @return 获得文件字节流 * @return 获得文件字节流
* @throws IOException * @throws IOException IO异常
*/ */
public byte[] getFileContent() throws IOException { public byte[] getFileContent() throws IOException {
assertValid(); assertValid();
@@ -121,7 +118,7 @@ public class UploadFile {
/** /**
* @return 获得文件流 * @return 获得文件流
* @throws IOException * @throws IOException IO异常
*/ */
public InputStream getFileInputStream() throws IOException { public InputStream getFileInputStream() throws IOException {
assertValid(); assertValid();
@@ -179,7 +176,7 @@ public class UploadFile {
* 处理上传表单流,提取出文件 * 处理上传表单流,提取出文件
* *
* @param input 上传表单的流 * @param input 上传表单的流
* @throws IOException * @throws IOException IO异常
*/ */
protected boolean processStream(MultipartRequestInputStream input) throws IOException { protected boolean processStream(MultipartRequestInputStream input) throws IOException {
if (!isAllowedExtension()) { if (!isAllowedExtension()) {
@@ -260,7 +257,7 @@ public class UploadFile {
/** /**
* 断言是否文件流可用 * 断言是否文件流可用
* @throws IOException * @throws IOException IO异常
*/ */
private void assertValid() throws IOException { private void assertValid() throws IOException {
if(! isUploaded()) { if(! isUploaded()) {

View File

@@ -34,7 +34,7 @@ public enum ChannelType {
* *
* @param value 类型值 * @param value 类型值
*/ */
private ChannelType(String value) { ChannelType(String value) {
this.value = value; this.value = value;
} }

View File

@@ -429,12 +429,12 @@ public class Sftp extends AbstractFtp {
* @author looly * @author looly
* *
*/ */
public static enum Mode { public enum Mode {
/** 完全覆盖模式这是JSch的默认文件传输模式即如果目标文件已经存在传输的文件将完全覆盖目标文件产生新的文件。 */ /** 完全覆盖模式这是JSch的默认文件传输模式即如果目标文件已经存在传输的文件将完全覆盖目标文件产生新的文件。 */
OVERWRITE, OVERWRITE,
/** 恢复模式,如果文件已经传输一部分,这时由于网络或其他任何原因导致文件传输中断,如果下一次传输相同的文件,则会从上一次中断的地方续传。 */ /** 恢复模式,如果文件已经传输一部分,这时由于网络或其他任何原因导致文件传输中断,如果下一次传输相同的文件,则会从上一次中断的地方续传。 */
RESUME, RESUME,
/** 追加模式,如果目标文件已存在,传输的文件将在目标文件后追加。 */ /** 追加模式,如果目标文件已存在,传输的文件将在目标文件后追加。 */
APPEND; APPEND
} }
} }

View File

@@ -132,7 +132,7 @@ public class TemplateConfig implements Serializable {
* *
* @author looly * @author looly
*/ */
public static enum ResourceMode { public enum ResourceMode {
/** 从ClassPath加载模板 */ /** 从ClassPath加载模板 */
CLASSPATH, CLASSPATH,
/** 从File目录加载模板 */ /** 从File目录加载模板 */
@@ -142,7 +142,7 @@ public class TemplateConfig implements Serializable {
/** 从模板文本加载模板 */ /** 从模板文本加载模板 */
STRING, STRING,
/** 复合加载模板分别从File、ClassPath、Web-root、String方式尝试查找模板 */ /** 复合加载模板分别从File、ClassPath、Web-root、String方式尝试查找模板 */
COMPOSITE; COMPOSITE
} }
@Override @Override
@@ -185,5 +185,5 @@ public class TemplateConfig implements Serializable {
return false; return false;
} }
return true; return true;
}; }
} }

View File

@@ -24,7 +24,7 @@ public enum ContentType {
TEXT_XML("text/xml"); TEXT_XML("text/xml");
private String value; private String value;
private ContentType(String value) { ContentType(String value) {
this.value = value; this.value = value;
} }

View File

@@ -26,7 +26,7 @@ public enum GlobalHeaders {
/** /**
* 构造 * 构造
*/ */
private GlobalHeaders() { GlobalHeaders() {
putDefault(false); putDefault(false);
} }
@@ -110,7 +110,7 @@ public enum GlobalHeaders {
if (null != name && null != value) { if (null != name && null != value) {
final List<String> values = headers.get(name.trim()); final List<String> values = headers.get(name.trim());
if (isOverride || CollectionUtil.isEmpty(values)) { if (isOverride || CollectionUtil.isEmpty(values)) {
final ArrayList<String> valueList = new ArrayList<String>(); final ArrayList<String> valueList = new ArrayList<>();
valueList.add(value); valueList.add(value);
headers.put(name.trim(), valueList); headers.put(name.trim(), valueList);
} else { } else {

View File

@@ -64,7 +64,7 @@ public enum Header {
LOCATION("Location"); LOCATION("Location");
private String value; private String value;
private Header(String value) { Header(String value) {
this.value = value; this.value = value;
} }

View File

@@ -21,6 +21,7 @@ import javax.net.ssl.SSLSocketFactory;
import cn.hutool.core.codec.Base64; import cn.hutool.core.codec.Base64;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.io.IoUtil; import cn.hutool.core.io.IoUtil;
import cn.hutool.core.io.resource.BytesResource; import cn.hutool.core.io.resource.BytesResource;
import cn.hutool.core.io.resource.FileResource; import cn.hutool.core.io.resource.FileResource;
@@ -811,11 +812,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
* @since 3.3.0 * @since 3.3.0
*/ */
public HttpRequest setMaxRedirectCount(int maxRedirectCount) { public HttpRequest setMaxRedirectCount(int maxRedirectCount) {
if (maxRedirectCount > 0) { this.maxRedirectCount = Math.max(maxRedirectCount, 0);
this.maxRedirectCount = maxRedirectCount;
} else {
this.maxRedirectCount = 0;
}
return this; return this;
} }
@@ -993,7 +990,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
// 自定义Cookie // 自定义Cookie
.setCookie(this.cookie) .setCookie(this.cookie)
// 定义转发 // 定义转发
.setInstanceFollowRedirects(this.maxRedirectCount > 0 ? true : false) .setInstanceFollowRedirects(this.maxRedirectCount > 0)
// 流方式上传数据 // 流方式上传数据
.setChunkedStreamingMode(this.blockSize) .setChunkedStreamingMode(this.blockSize)
// 覆盖默认Header // 覆盖默认Header
@@ -1060,9 +1057,9 @@ public class HttpRequest extends HttpBase<HttpRequest> {
/** /**
* 发送数据流 * 发送数据流
* *
* @throws IOException * @throws IORuntimeException IO异常
*/ */
private void send() throws HttpException { private void send() throws IORuntimeException {
try { try {
if (Method.POST.equals(this.method) || Method.PUT.equals(this.method) || Method.DELETE.equals(this.method) || this.isRest) { if (Method.POST.equals(this.method) || Method.PUT.equals(this.method) || Method.DELETE.equals(this.method) || this.isRest) {
if (CollectionUtil.isEmpty(this.fileForm)) { if (CollectionUtil.isEmpty(this.fileForm)) {
@@ -1076,7 +1073,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
} catch (IOException e) { } catch (IOException e) {
// 异常时关闭连接 // 异常时关闭连接
this.httpConnection.disconnectQuietly(); this.httpConnection.disconnectQuietly();
throw new HttpException(e); throw new IORuntimeException(e);
} }
} }
@@ -1084,7 +1081,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
* 发送普通表单<br> * 发送普通表单<br>
* 发送数据后自动关闭输出流 * 发送数据后自动关闭输出流
* *
* @throws IOException * @throws IOException IO异常
*/ */
private void sendFormUrlEncoded() throws IOException { private void sendFormUrlEncoded() throws IOException {
if (StrUtil.isBlank(this.header(Header.CONTENT_TYPE))) { if (StrUtil.isBlank(this.header(Header.CONTENT_TYPE))) {
@@ -1105,7 +1102,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
* 发送多组件请求(例如包含文件的表单)<br> * 发送多组件请求(例如包含文件的表单)<br>
* 发送数据后自动关闭输出流 * 发送数据后自动关闭输出流
* *
* @throws IOException * @throws IOException IO异常
*/ */
private void sendMultipart() throws IOException { private void sendMultipart() throws IOException {
setMultipart();// 设置表单类型为Multipart setMultipart();// 设置表单类型为Multipart
@@ -1114,8 +1111,6 @@ public class HttpRequest extends HttpBase<HttpRequest> {
writeFileForm(out); writeFileForm(out);
writeForm(out); writeForm(out);
formEnd(out); formEnd(out);
} catch (IOException e) {
throw e;
} }
} }
@@ -1125,9 +1120,8 @@ public class HttpRequest extends HttpBase<HttpRequest> {
* 发送普通表单内容 * 发送普通表单内容
* *
* @param out 输出流 * @param out 输出流
* @throws IOException
*/ */
private void writeForm(OutputStream out) throws IOException { private void writeForm(OutputStream out) {
if (CollectionUtil.isNotEmpty(this.form)) { if (CollectionUtil.isNotEmpty(this.form)) {
StringBuilder builder = StrUtil.builder(); StringBuilder builder = StrUtil.builder();
for (Entry<String, Object> entry : this.form.entrySet()) { for (Entry<String, Object> entry : this.form.entrySet()) {
@@ -1143,9 +1137,8 @@ public class HttpRequest extends HttpBase<HttpRequest> {
* 发送文件对象表单 * 发送文件对象表单
* *
* @param out 输出流 * @param out 输出流
* @throws IOException
*/ */
private void writeFileForm(OutputStream out) throws IOException { private void writeFileForm(OutputStream out) {
for (Entry<String, Resource> entry : this.fileForm.entrySet()) { for (Entry<String, Resource> entry : this.fileForm.entrySet()) {
appendPart(entry.getKey(), entry.getValue(), out); appendPart(entry.getKey(), entry.getValue(), out);
} }
@@ -1191,7 +1184,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
* 上传表单结束 * 上传表单结束
* *
* @param out 输出流 * @param out 输出流
* @throws IOException * @throws IOException IO异常
*/ */
private void formEnd(OutputStream out) throws IOException { private void formEnd(OutputStream out) throws IOException {
out.write(BOUNDARY_END); out.write(BOUNDARY_END);
@@ -1201,7 +1194,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
/** /**
* 设置表单类型为Multipart文件上传 * 设置表单类型为Multipart文件上传
* *
* @return HttpConnection * @return HttpConnection HTTP连接对象
*/ */
private void setMultipart() { private void setMultipart() {
this.httpConnection.header(Header.CONTENT_TYPE, CONTENT_TYPE_MULTIPART_PREFIX + BOUNDARY, true); this.httpConnection.header(Header.CONTENT_TYPE, CONTENT_TYPE_MULTIPART_PREFIX + BOUNDARY, true);
@@ -1215,10 +1208,10 @@ public class HttpRequest extends HttpBase<HttpRequest> {
* @since 3.1.2 * @since 3.1.2
*/ */
private boolean isIgnoreResponseBody() { private boolean isIgnoreResponseBody() {
if (Method.HEAD == this.method || Method.CONNECT == this.method || Method.OPTIONS == this.method || Method.TRACE == this.method) { return Method.HEAD == this.method //
return true; || Method.CONNECT == this.method //
} || Method.OPTIONS == this.method //
return false; || Method.TRACE == this.method;
} }
// ---------------------------------------------------------------- Private method end // ---------------------------------------------------------------- Private method end

View File

@@ -6,5 +6,5 @@ package cn.hutool.http;
* *
*/ */
public enum Method { public enum Method {
GET, POST, HEAD, OPTIONS, PUT, DELETE, TRACE, CONNECT, PATCH; GET, POST, HEAD, OPTIONS, PUT, DELETE, TRACE, CONNECT, PATCH
} }

View File

@@ -5,185 +5,185 @@ package cn.hutool.http;
* @author Looly * @author Looly
* *
*/ */
public interface Status { interface Status {
/** /**
* HTTP Status-Code 200: OK. * HTTP Status-Code 200: OK.
*/ */
public static final int HTTP_OK = 200; int HTTP_OK = 200;
/** /**
* HTTP Status-Code 201: Created. * HTTP Status-Code 201: Created.
*/ */
public static final int HTTP_CREATED = 201; int HTTP_CREATED = 201;
/** /**
* HTTP Status-Code 202: Accepted. * HTTP Status-Code 202: Accepted.
*/ */
public static final int HTTP_ACCEPTED = 202; int HTTP_ACCEPTED = 202;
/** /**
* HTTP Status-Code 203: Non-Authoritative Information. * HTTP Status-Code 203: Non-Authoritative Information.
*/ */
public static final int HTTP_NOT_AUTHORITATIVE = 203; int HTTP_NOT_AUTHORITATIVE = 203;
/** /**
* HTTP Status-Code 204: No Content. * HTTP Status-Code 204: No Content.
*/ */
public static final int HTTP_NO_CONTENT = 204; int HTTP_NO_CONTENT = 204;
/** /**
* HTTP Status-Code 205: Reset Content. * HTTP Status-Code 205: Reset Content.
*/ */
public static final int HTTP_RESET = 205; int HTTP_RESET = 205;
/** /**
* HTTP Status-Code 206: Partial Content. * HTTP Status-Code 206: Partial Content.
*/ */
public static final int HTTP_PARTIAL = 206; int HTTP_PARTIAL = 206;
/* 3XX: relocation/redirect */ /* 3XX: relocation/redirect */
/** /**
* HTTP Status-Code 300: Multiple Choices. * HTTP Status-Code 300: Multiple Choices.
*/ */
public static final int HTTP_MULT_CHOICE = 300; int HTTP_MULT_CHOICE = 300;
/** /**
* HTTP Status-Code 301: Moved Permanently. * HTTP Status-Code 301: Moved Permanently.
*/ */
public static final int HTTP_MOVED_PERM = 301; int HTTP_MOVED_PERM = 301;
/** /**
* HTTP Status-Code 302: Temporary Redirect. * HTTP Status-Code 302: Temporary Redirect.
*/ */
public static final int HTTP_MOVED_TEMP = 302; int HTTP_MOVED_TEMP = 302;
/** /**
* HTTP Status-Code 303: See Other. * HTTP Status-Code 303: See Other.
*/ */
public static final int HTTP_SEE_OTHER = 303; int HTTP_SEE_OTHER = 303;
/** /**
* HTTP Status-Code 304: Not Modified. * HTTP Status-Code 304: Not Modified.
*/ */
public static final int HTTP_NOT_MODIFIED = 304; int HTTP_NOT_MODIFIED = 304;
/** /**
* HTTP Status-Code 305: Use Proxy. * HTTP Status-Code 305: Use Proxy.
*/ */
public static final int HTTP_USE_PROXY = 305; int HTTP_USE_PROXY = 305;
/* 4XX: client error */ /* 4XX: client error */
/** /**
* HTTP Status-Code 400: Bad Request. * HTTP Status-Code 400: Bad Request.
*/ */
public static final int HTTP_BAD_REQUEST = 400; int HTTP_BAD_REQUEST = 400;
/** /**
* HTTP Status-Code 401: Unauthorized. * HTTP Status-Code 401: Unauthorized.
*/ */
public static final int HTTP_UNAUTHORIZED = 401; int HTTP_UNAUTHORIZED = 401;
/** /**
* HTTP Status-Code 402: Payment Required. * HTTP Status-Code 402: Payment Required.
*/ */
public static final int HTTP_PAYMENT_REQUIRED = 402; int HTTP_PAYMENT_REQUIRED = 402;
/** /**
* HTTP Status-Code 403: Forbidden. * HTTP Status-Code 403: Forbidden.
*/ */
public static final int HTTP_FORBIDDEN = 403; int HTTP_FORBIDDEN = 403;
/** /**
* HTTP Status-Code 404: Not Found. * HTTP Status-Code 404: Not Found.
*/ */
public static final int HTTP_NOT_FOUND = 404; int HTTP_NOT_FOUND = 404;
/** /**
* HTTP Status-Code 405: Method Not Allowed. * HTTP Status-Code 405: Method Not Allowed.
*/ */
public static final int HTTP_BAD_METHOD = 405; int HTTP_BAD_METHOD = 405;
/** /**
* HTTP Status-Code 406: Not Acceptable. * HTTP Status-Code 406: Not Acceptable.
*/ */
public static final int HTTP_NOT_ACCEPTABLE = 406; int HTTP_NOT_ACCEPTABLE = 406;
/** /**
* HTTP Status-Code 407: Proxy Authentication Required. * HTTP Status-Code 407: Proxy Authentication Required.
*/ */
public static final int HTTP_PROXY_AUTH = 407; int HTTP_PROXY_AUTH = 407;
/** /**
* HTTP Status-Code 408: Request Time-Out. * HTTP Status-Code 408: Request Time-Out.
*/ */
public static final int HTTP_CLIENT_TIMEOUT = 408; int HTTP_CLIENT_TIMEOUT = 408;
/** /**
* HTTP Status-Code 409: Conflict. * HTTP Status-Code 409: Conflict.
*/ */
public static final int HTTP_CONFLICT = 409; int HTTP_CONFLICT = 409;
/** /**
* HTTP Status-Code 410: Gone. * HTTP Status-Code 410: Gone.
*/ */
public static final int HTTP_GONE = 410; int HTTP_GONE = 410;
/** /**
* HTTP Status-Code 411: Length Required. * HTTP Status-Code 411: Length Required.
*/ */
public static final int HTTP_LENGTH_REQUIRED = 411; int HTTP_LENGTH_REQUIRED = 411;
/** /**
* HTTP Status-Code 412: Precondition Failed. * HTTP Status-Code 412: Precondition Failed.
*/ */
public static final int HTTP_PRECON_FAILED = 412; int HTTP_PRECON_FAILED = 412;
/** /**
* HTTP Status-Code 413: Request Entity Too Large. * HTTP Status-Code 413: Request Entity Too Large.
*/ */
public static final int HTTP_ENTITY_TOO_LARGE = 413; int HTTP_ENTITY_TOO_LARGE = 413;
/** /**
* HTTP Status-Code 414: Request-URI Too Large. * HTTP Status-Code 414: Request-URI Too Large.
*/ */
public static final int HTTP_REQ_TOO_LONG = 414; int HTTP_REQ_TOO_LONG = 414;
/** /**
* HTTP Status-Code 415: Unsupported Media Type. * HTTP Status-Code 415: Unsupported Media Type.
*/ */
public static final int HTTP_UNSUPPORTED_TYPE = 415; int HTTP_UNSUPPORTED_TYPE = 415;
/* 5XX: server error */ /* 5XX: server error */
/** /**
* HTTP Status-Code 500: Internal Server Error. * HTTP Status-Code 500: Internal Server Error.
*/ */
public static final int HTTP_INTERNAL_ERROR = 500; int HTTP_INTERNAL_ERROR = 500;
/** /**
* HTTP Status-Code 501: Not Implemented. * HTTP Status-Code 501: Not Implemented.
*/ */
public static final int HTTP_NOT_IMPLEMENTED = 501; int HTTP_NOT_IMPLEMENTED = 501;
/** /**
* HTTP Status-Code 502: Bad Gateway. * HTTP Status-Code 502: Bad Gateway.
*/ */
public static final int HTTP_BAD_GATEWAY = 502; int HTTP_BAD_GATEWAY = 502;
/** /**
* HTTP Status-Code 503: Service Unavailable. * HTTP Status-Code 503: Service Unavailable.
*/ */
public static final int HTTP_UNAVAILABLE = 503; int HTTP_UNAVAILABLE = 503;
/** /**
* HTTP Status-Code 504: Gateway Timeout. * HTTP Status-Code 504: Gateway Timeout.
*/ */
public static final int HTTP_GATEWAY_TIMEOUT = 504; int HTTP_GATEWAY_TIMEOUT = 504;
/** /**
* HTTP Status-Code 505: HTTP Version Not Supported. * HTTP Status-Code 505: HTTP Version Not Supported.
*/ */
public static final int HTTP_VERSION = 505; int HTTP_VERSION = 505;
} }

View File

@@ -19,7 +19,7 @@ public enum SoapProtocol {
* *
* @param value {@link SOAPConstants} 中的协议版本值 * @param value {@link SOAPConstants} 中的协议版本值
*/ */
private SoapProtocol(String value) { SoapProtocol(String value) {
this.value = value; this.value = value;
} }

View File

@@ -19,7 +19,6 @@ import cn.hutool.core.util.StrUtil;
* 内部JSON工具类仅用于JSON内部使用 * 内部JSON工具类仅用于JSON内部使用
* *
* @author Looly * @author Looly
*
*/ */
final class InternalJSONUtil { final class InternalJSONUtil {
@@ -35,10 +34,10 @@ final class InternalJSONUtil {
* @param indent 缩进空格数 * @param indent 缩进空格数
* @param config 配置项 * @param config 配置项
* @return Writer * @return Writer
* @throws JSONException * @throws JSONException JSON异常
* @throws IOException * @throws IOException IO异常
*/ */
protected static final Writer writeValue(Writer writer, Object value, int indentFactor, int indent, JSONConfig config) throws JSONException, IOException { protected static Writer writeValue(Writer writer, Object value, int indentFactor, int indent, JSONConfig config) throws JSONException, IOException {
if (value == null || value instanceof JSONNull) { if (value == null || value instanceof JSONNull) {
writer.write(JSONNull.NULL.toString()); writer.write(JSONNull.NULL.toString());
} else if (value instanceof JSON) { } else if (value instanceof JSON) {
@@ -71,11 +70,11 @@ final class InternalJSONUtil {
/** /**
* 缩进,使用空格符 * 缩进,使用空格符
* *
* @param writer * @param writer writer
* @param indent * @param indent 随进空格数
* @throws IOException * @throws IOException IO异常
*/ */
protected static final void indent(Writer writer, int indent) throws IOException { protected static void indent(Writer writer, int indent) throws IOException {
for (int i = 0; i < indent; i += 1) { for (int i = 0; i < indent; i += 1) {
writer.write(CharUtil.SPACE); writer.write(CharUtil.SPACE);
} }
@@ -215,10 +214,9 @@ final class InternalJSONUtil {
* @since 4.3.1 * @since 4.3.1
*/ */
protected static boolean defaultIgnoreNullValue(Object obj) { protected static boolean defaultIgnoreNullValue(Object obj) {
if(obj instanceof CharSequence || obj instanceof JSONTokener || obj instanceof Map) { return (false == (obj instanceof CharSequence))//
return false; && (false == (obj instanceof JSONTokener))//
} && (false == (obj instanceof Map));
return true;
} }
/** /**

View File

@@ -34,7 +34,7 @@ public interface JSON extends Cloneable, Serializable{
* @see BeanPath#get(Object) * @see BeanPath#get(Object)
* @since 4.0.6 * @since 4.0.6
*/ */
public Object getByPath(String expression); Object getByPath(String expression);
/** /**
* 设置表达式指定位置或filed对应的值<br> * 设置表达式指定位置或filed对应的值<br>
@@ -84,7 +84,7 @@ public interface JSON extends Cloneable, Serializable{
* @see BeanPath#get(Object) * @see BeanPath#get(Object)
* @since 4.0.6 * @since 4.0.6
*/ */
public <T> T getByPath(String expression, Class<T> resultType); <T> T getByPath(String expression, Class<T> resultType);
/** /**
* 将JSON内容写入Writer无缩进<br> * 将JSON内容写入Writer无缩进<br>
@@ -94,7 +94,7 @@ public interface JSON extends Cloneable, Serializable{
* @return Writer * @return Writer
* @throws JSONException JSON相关异常 * @throws JSONException JSON相关异常
*/ */
public Writer write(Writer writer) throws JSONException; Writer write(Writer writer) throws JSONException;
/** /**
* 将JSON内容写入Writer<br> * 将JSON内容写入Writer<br>
@@ -106,7 +106,7 @@ public interface JSON extends Cloneable, Serializable{
* @return Writer * @return Writer
* @throws JSONException JSON相关异常 * @throws JSONException JSON相关异常
*/ */
public Writer write(Writer writer, int indentFactor, int indent) throws JSONException; Writer write(Writer writer, int indentFactor, int indent) throws JSONException;
/** /**
* 转换为JSON字符串 * 转换为JSON字符串
@@ -115,7 +115,7 @@ public interface JSON extends Cloneable, Serializable{
* @return JSON字符串 * @return JSON字符串
* @throws JSONException JSON相关异常 * @throws JSONException JSON相关异常
*/ */
public String toJSONString(int indentFactor) throws JSONException; String toJSONString(int indentFactor) throws JSONException;
/** /**
* 格式化打印JSON缩进为4个空格 * 格式化打印JSON缩进为4个空格
@@ -124,5 +124,5 @@ public interface JSON extends Cloneable, Serializable{
* @throws JSONException 包含非法数抛出此异常 * @throws JSONException 包含非法数抛出此异常
* @since 3.0.9 * @since 3.0.9
*/ */
public String toStringPretty() throws JSONException; String toStringPretty() throws JSONException;
} }

View File

@@ -82,7 +82,7 @@ public class JSONArray extends JSONGetter<Integer> implements JSON, List<Object>
* @since 4.1.19 * @since 4.1.19
*/ */
public JSONArray(int initialCapacity, JSONConfig config) { public JSONArray(int initialCapacity, JSONConfig config) {
this.rawList = new ArrayList<Object>(initialCapacity); this.rawList = new ArrayList<>(initialCapacity);
this.config = config; this.config = config;
} }
@@ -107,9 +107,7 @@ public class JSONArray extends JSONGetter<Integer> implements JSON, List<Object>
*/ */
public JSONArray(Collection<Object> list) { public JSONArray(Collection<Object> list) {
this(list.size()); this(list.size());
for (Object o : list) { this.addAll(list);
this.add(o);
}
} }
/** /**
@@ -311,13 +309,10 @@ public class JSONArray extends JSONGetter<Integer> implements JSON, List<Object>
} }
final JSONArray other = (JSONArray) obj; final JSONArray other = (JSONArray) obj;
if (rawList == null) { if (rawList == null) {
if (other.rawList != null) { return other.rawList == null;
return false; } else {
return rawList.equals(other.rawList);
} }
} else if (!rawList.equals(other.rawList)) {
return false;
}
return true;
} }
@Override @Override
@@ -382,7 +377,7 @@ public class JSONArray extends JSONGetter<Integer> implements JSON, List<Object>
} }
@Override @Override
public boolean addAll(Collection<? extends Object> c) { public boolean addAll(Collection<?> c) {
if (CollUtil.isEmpty(c)) { if (CollUtil.isEmpty(c)) {
return false; return false;
} }
@@ -393,7 +388,7 @@ public class JSONArray extends JSONGetter<Integer> implements JSON, List<Object>
} }
@Override @Override
public boolean addAll(int index, Collection<? extends Object> c) { public boolean addAll(int index, Collection<?> c) {
if (CollUtil.isEmpty(c)) { if (CollUtil.isEmpty(c)) {
return false; return false;
} }

View File

@@ -441,8 +441,8 @@ public class JSONObject extends JSONGetter<String> implements JSON, Map<String,
} }
@Override @Override
public void putAll(Map<? extends String, ? extends Object> m) { public void putAll(Map<? extends String, ?> m) {
for (Entry<? extends String, ? extends Object> entry : m.entrySet()) { for (Entry<? extends String, ?> entry : m.entrySet()) {
this.put(entry.getKey(), entry.getValue()); this.put(entry.getKey(), entry.getValue());
} }
} }
@@ -565,13 +565,10 @@ public class JSONObject extends JSONGetter<String> implements JSON, Map<String,
} }
final JSONObject other = (JSONObject) obj; final JSONObject other = (JSONObject) obj;
if (rawHashMap == null) { if (rawHashMap == null) {
if (other.rawHashMap != null) { return other.rawHashMap == null;
return false; } else {
return rawHashMap.equals(other.rawHashMap);
} }
} else if (!rawHashMap.equals(other.rawHashMap)) {
return false;
}
return true;
} }
/** /**
@@ -660,7 +657,7 @@ public class JSONObject extends JSONGetter<String> implements JSON, Map<String,
} }
InternalJSONUtil.indent(writer, newIndent); InternalJSONUtil.indent(writer, newIndent);
writer.write(JSONUtil.quote(entry.getKey().toString())); writer.write(JSONUtil.quote(entry.getKey()));
writer.write(CharUtil.COLON); writer.write(CharUtil.COLON);
if (indentFactor > 0) { if (indentFactor > 0) {
// 冒号后的空格 // 冒号后的空格
@@ -682,7 +679,6 @@ public class JSONObject extends JSONGetter<String> implements JSON, Map<String,
* Bean对象转Map * Bean对象转Map
* *
* @param bean Bean对象 * @param bean Bean对象
* @param ignoreNullValue 是否忽略空值
*/ */
private void populateMap(Object bean) { private void populateMap(Object bean) {
final Collection<PropDesc> props = BeanUtil.getBeanDesc(bean.getClass()).getProps(); final Collection<PropDesc> props = BeanUtil.getBeanDesc(bean.getClass()).getProps();
@@ -735,7 +731,7 @@ public class JSONObject extends JSONGetter<String> implements JSON, Map<String,
} }
final JSONSerializer serializer = GlobalSerializeMapping.getSerializer(source.getClass()); final JSONSerializer serializer = GlobalSerializeMapping.getSerializer(source.getClass());
if(null != serializer && serializer instanceof JSONObjectSerializer) { if(serializer instanceof JSONObjectSerializer) {
// 自定义序列化 // 自定义序列化
serializer.serialize(this, source); serializer.serialize(this, source);
} else if (source instanceof Map) { } else if (source instanceof Map) {

View File

@@ -12,9 +12,9 @@ import cn.hutool.core.util.StrUtil;
public class JSONStrFormater { public class JSONStrFormater {
/** 单位缩进字符串。*/ /** 单位缩进字符串。*/
private static String SPACE = " "; private static final String SPACE = " ";
/** 换行符*/ /** 换行符*/
private static char NEW_LINE = StrUtil.C_LF; private static final char NEW_LINE = StrUtil.C_LF;
/** /**
* 返回格式化JSON字符串。 * 返回格式化JSON字符串。
@@ -23,13 +23,13 @@ public class JSONStrFormater {
* @return 格式化的JSON字符串。 * @return 格式化的JSON字符串。
*/ */
public static String format(String json) { public static String format(String json) {
final StringBuffer result = new StringBuffer(); final StringBuilder result = new StringBuilder();
Character wrapChar = null; Character wrapChar = null;
boolean isEscapeMode = false; boolean isEscapeMode = false;
int length = json.length(); int length = json.length();
int number = 0; int number = 0;
char key = 0; char key;
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
key = json.charAt(i); key = json.charAt(i);

View File

@@ -14,5 +14,5 @@ public interface JSONString {
* *
* @return JSON字符串 * @return JSON字符串
*/ */
public String toJSONString(); String toJSONString();
} }

View File

@@ -150,7 +150,7 @@ public final class JSONUtil {
return null; return null;
} }
JSON json = null; JSON json;
if (obj instanceof JSON) { if (obj instanceof JSON) {
json = (JSON) obj; json = (JSON) obj;
} else if (obj instanceof String) { } else if (obj instanceof String) {
@@ -648,9 +648,6 @@ public final class JSONUtil {
if (object instanceof Date || object instanceof Calendar) { if (object instanceof Date || object instanceof Calendar) {
return object; return object;
} }
if (object instanceof Calendar) {
return ((Calendar) object).getTimeInMillis();
}
// 枚举类保存其字符串形式4.0.2新增) // 枚举类保存其字符串形式4.0.2新增)
if (object instanceof Enum) { if (object instanceof Enum) {
return object.toString(); return object.toString();

View File

@@ -79,7 +79,6 @@ public class JSONArrayTest {
List<Exam> list = array.toList(Exam.class); List<Exam> list = array.toList(Exam.class);
Assert.assertFalse(list.isEmpty()); Assert.assertFalse(list.isEmpty());
Assert.assertEquals(Exam.class, list.get(0).getClass()); Assert.assertEquals(Exam.class, list.get(0).getClass());
;
} }
@Test @Test
@@ -123,7 +122,7 @@ public class JSONArrayTest {
JSONArray array = JSONUtil.parseArray(jsonStr); JSONArray array = JSONUtil.parseArray(jsonStr);
Exam[] list = array.toArray(new Exam[0]); Exam[] list = array.toArray(new Exam[0]);
Assert.assertFalse(0 == list.length); Assert.assertNotEquals(0, list.length);
Assert.assertEquals(Exam.class, list[0].getClass()); Assert.assertEquals(Exam.class, list[0].getClass());
} }
@@ -136,7 +135,7 @@ public class JSONArrayTest {
JSONArray ja = JSONUtil.parseArray(json); JSONArray ja = JSONUtil.parseArray(json);
List<KeyBean> list = ja.toList(KeyBean.class); List<KeyBean> list = ja.toList(KeyBean.class);
Assert.assertTrue(null == list.get(0)); Assert.assertNull(list.get(0));
Assert.assertEquals("avalue", list.get(1).getAkey()); Assert.assertEquals("avalue", list.get(1).getAkey());
Assert.assertEquals("bvalue", list.get(1).getBkey()); Assert.assertEquals("bvalue", list.get(1).getBkey());
} }
@@ -175,7 +174,7 @@ public class JSONArrayTest {
return map; return map;
} }
class User { static class User {
private Integer id; private Integer id;
private String name; private String name;

View File

@@ -354,7 +354,7 @@ public class JSONObjectTest {
Assert.assertEquals("defaultBBB", bbb); Assert.assertEquals("defaultBBB", bbb);
} }
public static enum TestEnum { public enum TestEnum {
TYPE_A, TYPE_B TYPE_A, TYPE_B
} }

View File

@@ -17,7 +17,7 @@ public class EnvSettingInfo {
private String hubRemoteUrl; private String hubRemoteUrl;
private String reportFolder = "/report"; private String reportFolder = "/report";
private String screenshotFolder = "/screenshot";; private String screenshotFolder = "/screenshot";
private String elementFolder = "/config/element/"; private String elementFolder = "/config/element/";
private String suiteFolder = "/config/suite/"; private String suiteFolder = "/config/suite/";

View File

@@ -18,7 +18,7 @@ public interface Log extends TraceLog, DebugLog, InfoLog, WarnLog, ErrorLog {
/** /**
* @return 日志对象的Name * @return 日志对象的Name
*/ */
public String getName(); String getName();
/** /**
* 是否开启指定日志 * 是否开启指定日志

View File

@@ -10,18 +10,19 @@ import cn.hutool.log.level.Level;
/** /**
* 利用System.out.println()打印日志 * 利用System.out.println()打印日志
* @author Looly
* *
* @author Looly
*/ */
public class ConsoleLog extends AbstractLog { public class ConsoleLog extends AbstractLog {
private static final long serialVersionUID = -6843151523380063975L; private static final long serialVersionUID = -6843151523380063975L;
private static String logFormat = "[{date}] [{level}] {name}: {msg}"; private static final String logFormat = "[{date}] [{level}] {name}: {msg}";
private static Level currentLevel = Level.DEBUG; private static Level currentLevel = Level.DEBUG;
private String name; private String name;
//------------------------------------------------------------------------- Constructor //------------------------------------------------------------------------- Constructor
/** /**
* 构造 * 构造
* *
@@ -47,6 +48,7 @@ public class ConsoleLog extends AbstractLog {
/** /**
* 设置自定义的日志显示级别 * 设置自定义的日志显示级别
*
* @param customLevel 自定义级别 * @param customLevel 自定义级别
* @since 4.1.10 * @since 4.1.10
*/ */
@@ -65,6 +67,7 @@ public class ConsoleLog extends AbstractLog {
public void trace(String fqcn, Throwable t, String format, Object... arguments) { public void trace(String fqcn, Throwable t, String format, Object... arguments) {
log(fqcn, Level.TRACE, t, format, arguments); log(fqcn, Level.TRACE, t, format, arguments);
} }
//------------------------------------------------------------------------- Debug //------------------------------------------------------------------------- Debug
@Override @Override
public boolean isDebugEnabled() { public boolean isDebugEnabled() {

View File

@@ -14,5 +14,5 @@ public interface CellEditor {
* @param value 单元格值 * @param value 单元格值
* @return 编辑后的对象 * @return 编辑后的对象
*/ */
public Object edit(Cell cell, Object value); Object edit(Cell cell, Object value);
} }

Some files were not shown because too many files have changed in this diff Show More