mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
fix code
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
package cn.hutool.aop.aspects;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import cn.hutool.core.date.TimeInterval;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* 通过日志打印方法的执行时间的切面
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
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.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
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实现的动态代理切面
|
||||
*
|
||||
|
||||
@@ -16,7 +16,7 @@ public interface BloomFilter extends Serializable{
|
||||
* @param str 字符串
|
||||
* @return 判断一个字符串是否bitMap中存在
|
||||
*/
|
||||
public boolean contains(String str);
|
||||
boolean contains(String str);
|
||||
|
||||
/**
|
||||
* 在boolean的bitMap中增加一个字符串<br>
|
||||
@@ -25,5 +25,5 @@ public interface BloomFilter extends Serializable{
|
||||
* @param str 字符串
|
||||
* @return 是否加入成功,如果存在就返回<code>false</code> .如果不存在返回<code>true</code>
|
||||
*/
|
||||
public boolean add(String str);
|
||||
boolean add(String str);
|
||||
}
|
||||
@@ -8,22 +8,22 @@ package cn.hutool.bloomfilter.bitMap;
|
||||
*/
|
||||
public interface BitMap{
|
||||
|
||||
public final int MACHINE32 = 32;
|
||||
public final int MACHINE64 = 64;
|
||||
int MACHINE32 = 32;
|
||||
int MACHINE64 = 64;
|
||||
|
||||
/**
|
||||
* 加入值
|
||||
*
|
||||
* @param i 值
|
||||
*/
|
||||
public void add(long i);
|
||||
void add(long i);
|
||||
|
||||
/**
|
||||
* 检查是否包含值
|
||||
*
|
||||
* @param i 值
|
||||
*/
|
||||
public boolean contains(long i);
|
||||
boolean contains(long i);
|
||||
|
||||
/**
|
||||
* 移除值
|
||||
|
||||
@@ -30,7 +30,7 @@ public enum GlobalPruneTimer {
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
private GlobalPruneTimer() {
|
||||
GlobalPruneTimer() {
|
||||
create();
|
||||
}
|
||||
|
||||
|
||||
@@ -44,10 +44,8 @@ public class CacheObj<K, V> implements Serializable{
|
||||
boolean isExpired() {
|
||||
if(this.ttl > 0) {
|
||||
final long expiredTime = this.lastAccess + this.ttl;
|
||||
if(expiredTime > 0 && expiredTime < System.currentTimeMillis()) {
|
||||
// expiredTime > 0 杜绝Long类型溢出变负数问题,当当前时间超过过期时间,表示过期
|
||||
return true;
|
||||
}
|
||||
return expiredTime > 0 && expiredTime < System.currentTimeMillis();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ public class ShearCaptcha extends AbstractCaptcha {
|
||||
* 干扰线
|
||||
*
|
||||
* @param g {@link Graphics}
|
||||
* @param x1x1
|
||||
* @param x1 x1
|
||||
* @param y1 y1
|
||||
* @param x2 x2
|
||||
* @param y2 y2
|
||||
@@ -183,8 +183,8 @@ public class ShearCaptcha extends AbstractCaptcha {
|
||||
int dy = (int) ddy;
|
||||
|
||||
// Now we can compute the corner points...
|
||||
int xPoints[] = new int[4];
|
||||
int yPoints[] = new int[4];
|
||||
int[] xPoints = new int[4];
|
||||
int[] yPoints = new int[4];
|
||||
|
||||
xPoints[0] = x1 + dx;
|
||||
yPoints[0] = y1 + dy;
|
||||
|
||||
@@ -14,7 +14,7 @@ public interface CodeGenerator extends Serializable{
|
||||
*
|
||||
* @return 验证码
|
||||
*/
|
||||
public String generate();
|
||||
String generate();
|
||||
|
||||
/**
|
||||
* 验证用户输入的字符串是否与生成的验证码匹配<br>
|
||||
@@ -24,5 +24,5 @@ public interface CodeGenerator extends Serializable{
|
||||
* @param userInputCode 用户输入的验证码
|
||||
* @return 是否验证通过
|
||||
*/
|
||||
public boolean verify(String code, String userInputCode);
|
||||
boolean verify(String code, String userInputCode);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public interface ValueProvider<T>{
|
||||
* @param valueType 被注入的值得类型
|
||||
* @return 对应参数名的值
|
||||
*/
|
||||
public Object value(T key, Type valueType);
|
||||
Object value(T key, Type valueType);
|
||||
|
||||
/**
|
||||
* 是否包含指定KEY,如果不包含则忽略注入<br>
|
||||
@@ -32,5 +32,5 @@ public interface ValueProvider<T>{
|
||||
* @param key Bean对象中参数名
|
||||
* @return 是否包含指定KEY
|
||||
*/
|
||||
public boolean containsKey(T key);
|
||||
boolean containsKey(T key);
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
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
|
||||
*/
|
||||
|
||||
@@ -21,11 +21,12 @@ public class BCD {
|
||||
asc = "0" + asc;
|
||||
len = asc.length();
|
||||
}
|
||||
byte abt[] = new byte[len];
|
||||
byte[] abt;
|
||||
if (len >= 2) {
|
||||
len >>= 1;
|
||||
}
|
||||
byte bbt[] = new byte[len];
|
||||
byte[] bbt;
|
||||
bbt = new byte[len];
|
||||
abt = asc.getBytes();
|
||||
int j;
|
||||
int k;
|
||||
@@ -82,7 +83,8 @@ public class BCD {
|
||||
* @return ASCII字符串
|
||||
*/
|
||||
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++) {
|
||||
val = (char) (((bytes[i] & 0xf0) >> 4) & 0x0f);
|
||||
|
||||
@@ -129,7 +129,7 @@ public class Base62Codec implements Serializable{
|
||||
* @return 计算结果
|
||||
*/
|
||||
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 ByteArrayOutputStream out = new ByteArrayOutputStream(estimatedLength);
|
||||
|
||||
@@ -2,7 +2,6 @@ package cn.hutool.core.collection;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,6 +17,6 @@ public interface Converter<T> {
|
||||
* @return 转换后的值
|
||||
* @throws IllegalArgumentException 无法确定目标类型,且默认值为{@code null},无法确定类型
|
||||
*/
|
||||
public T convert(Object value, T defaultValue) throws IllegalArgumentException;
|
||||
T convert(Object value, T defaultValue) throws IllegalArgumentException;
|
||||
|
||||
}
|
||||
@@ -75,7 +75,7 @@ public class BetweenFormater implements Serializable{
|
||||
}
|
||||
if(isLevelCountValid(levelCount) && 0 != millisecond && level >= Level.MILLSECOND.ordinal()){
|
||||
sb.append(millisecond).append(Level.MILLSECOND.name);
|
||||
levelCount++;
|
||||
// levelCount++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ public class BetweenFormater implements Serializable{
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
public static enum Level {
|
||||
public enum Level {
|
||||
|
||||
/** 天 */
|
||||
DAY("天"),
|
||||
@@ -143,7 +143,7 @@ public class BetweenFormater implements Serializable{
|
||||
* 构造
|
||||
* @param name 级别名称
|
||||
*/
|
||||
private Level(String name) {
|
||||
Level(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ public enum DateField {
|
||||
// ---------------------------------------------------------------
|
||||
private int value;
|
||||
|
||||
private DateField(int value) {
|
||||
DateField(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ public class DateModifier {
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public static enum ModifyType {
|
||||
public enum ModifyType {
|
||||
/**
|
||||
* 取指定日期短的起始值.
|
||||
*/
|
||||
|
||||
@@ -32,7 +32,7 @@ public class DateUtil {
|
||||
/**
|
||||
* java.util.Date EEE MMM zzz 缩写数组
|
||||
*/
|
||||
private final static String wtb[] = { //
|
||||
private final static String[] wtb = { //
|
||||
"sun", "mon", "tue", "wed", "thu", "fri", "sat", // 星期
|
||||
"jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec", //
|
||||
"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) {
|
||||
if (startDate == null || endDate == null) {
|
||||
return new LinkedHashSet<String>(0);
|
||||
return new LinkedHashSet<>(0);
|
||||
}
|
||||
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(2, 3)), 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(format.substring(7, 8));
|
||||
builder.append(format, 7, 8);
|
||||
builder.append(Convert.numberToChinese(Integer.parseInt(format.substring(8, 10)), false));
|
||||
builder.append(format.substring(10));
|
||||
format = builder.toString().replace('零', '〇');
|
||||
@@ -1888,7 +1888,7 @@ public class DateUtil {
|
||||
* @param 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();
|
||||
|
||||
// 日期部分("\"、"/"、"."、"年"、"月"都替换为"-")
|
||||
String datePart = dateAndTime.get(0).replaceAll("[\\/.年月]", "-");
|
||||
String datePart = dateAndTime.get(0).replaceAll("[/.年月]", "-");
|
||||
datePart = StrUtil.removeSuffix(datePart, "日");
|
||||
builder.append(datePart);
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ public enum Month {
|
||||
// ---------------------------------------------------------------
|
||||
private int value;
|
||||
|
||||
private Month(int value) {
|
||||
Month(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public enum Quarter {
|
||||
// ---------------------------------------------------------------
|
||||
private int value;
|
||||
|
||||
private Quarter(int value) {
|
||||
Quarter(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public enum Season {
|
||||
// ---------------------------------------------------------------
|
||||
private int value;
|
||||
|
||||
private Season(int value) {
|
||||
Season(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public enum Week {
|
||||
*
|
||||
* @param value 星期对应{@link Calendar} 中的Week值
|
||||
*/
|
||||
private Week(int value) {
|
||||
Week(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ public interface OptBasicTypeGetter<K> {
|
||||
* @param defaultValue 默认值
|
||||
* @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类型值
|
||||
|
||||
@@ -389,8 +389,8 @@ public class ImgUtil {
|
||||
|
||||
try {
|
||||
if (srcWidth > destWidth && srcHeight > destHeight) {
|
||||
int cols = 0; // 切片横向数量
|
||||
int rows = 0; // 切片纵向数量
|
||||
int cols; // 切片横向数量
|
||||
int rows; // 切片纵向数量
|
||||
// 计算切片的横向和纵向数量
|
||||
if (srcWidth % destWidth == 0) {
|
||||
cols = srcWidth / destWidth;
|
||||
@@ -1772,7 +1772,7 @@ public class ImgUtil {
|
||||
return Color.LIGHT_GRAY;
|
||||
} else if ("GRAY".equals(colorName)) {
|
||||
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;
|
||||
} else if ("RED".equals(colorName)) {
|
||||
return Color.RED;
|
||||
|
||||
@@ -31,7 +31,7 @@ public enum ScaleType {
|
||||
* @see Image#SCALE_REPLICATE
|
||||
* @see Image#SCALE_AREA_AVERAGING
|
||||
*/
|
||||
private ScaleType(int value) {
|
||||
ScaleType(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ public class BOMInputStream extends InputStream {
|
||||
return;
|
||||
}
|
||||
|
||||
byte bom[] = new byte[BOM_SIZE];
|
||||
byte[] bom = new byte[BOM_SIZE];
|
||||
int n, unread;
|
||||
n = in.read(bom, 0, bom.length);
|
||||
|
||||
|
||||
@@ -19,10 +19,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
* @author Looly
|
||||
*
|
||||
*/
|
||||
public final class FileTypeUtil {
|
||||
|
||||
private FileTypeUtil() {
|
||||
};
|
||||
public class FileTypeUtil {
|
||||
|
||||
private static final Map<String, String> fileTypeMap;
|
||||
|
||||
@@ -42,7 +39,6 @@ public final class FileTypeUtil {
|
||||
fileTypeMap.put("38425053000100000000", "psd"); // Photoshop (psd)
|
||||
fileTypeMap.put("46726f6d3a203d3f6762", "eml"); // Email [Outlook Express 6] (eml)
|
||||
fileTypeMap.put("d0cf11e0a1b11ae10000", "doc"); // MS Excel 注意:word、msi 和 excel的文件头一样
|
||||
fileTypeMap.put("d0cf11e0a1b11ae10000", "vsd"); // Visio 绘图
|
||||
fileTypeMap.put("5374616E64617264204A", "mdb"); // MS Access (mdb)
|
||||
fileTypeMap.put("252150532D41646F6265", "ps");
|
||||
fileTypeMap.put("255044462d312e", "pdf"); // Adobe Acrobat (pdf)
|
||||
@@ -70,7 +66,6 @@ public final class FileTypeUtil {
|
||||
fileTypeMap.put("cafebabe0000002e0041", "class");// bat文件
|
||||
fileTypeMap.put("49545346030000006000", "chm");// bat文件
|
||||
fileTypeMap.put("04000000010000001300", "mxp");// bat文件
|
||||
fileTypeMap.put("d0cf11e0a1b11ae10000", "wps");// WPS文字wps、表格et、演示dps都是一样的
|
||||
fileTypeMap.put("6431303a637265617465", "torrent");
|
||||
fileTypeMap.put("6D6F6F76", "mov"); // Quicktime (mov)
|
||||
fileTypeMap.put("FF575043", "wpd"); // WordPerfect (wpd)
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.zip.CRC32;
|
||||
import java.util.zip.CheckedInputStream;
|
||||
import java.util.zip.Checksum;
|
||||
@@ -170,7 +171,7 @@ public class IoUtil {
|
||||
}
|
||||
long size = 0;
|
||||
try {
|
||||
for (int readSize = -1; (readSize = in.read(buffer)) != EOF;) {
|
||||
for (int readSize; (readSize = in.read(buffer)) != EOF;) {
|
||||
out.write(buffer, 0, readSize);
|
||||
size += readSize;
|
||||
out.flush();
|
||||
@@ -314,7 +315,7 @@ public class IoUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
InputStreamReader reader = null;
|
||||
InputStreamReader reader;
|
||||
if (null == charset) {
|
||||
reader = new InputStreamReader(in);
|
||||
} else {
|
||||
@@ -605,7 +606,7 @@ public class IoUtil {
|
||||
if (in == null) {
|
||||
throw new IllegalArgumentException("The InputStream must not be null");
|
||||
}
|
||||
ObjectInputStream ois = null;
|
||||
ObjectInputStream ois;
|
||||
try {
|
||||
ois = new ObjectInputStream(in);
|
||||
@SuppressWarnings("unchecked") // may fail with CCE if serialised form is incorrect
|
||||
@@ -717,7 +718,7 @@ public class IoUtil {
|
||||
|
||||
// 从返回的内容中读取所需内容
|
||||
final BufferedReader bReader = getReader(reader);
|
||||
String line = null;
|
||||
String line;
|
||||
try {
|
||||
while ((line = bReader.readLine()) != null) {
|
||||
lineHandler.handle(line);
|
||||
@@ -1092,11 +1093,11 @@ public class IoUtil {
|
||||
try {
|
||||
String line1 = br1.readLine();
|
||||
String line2 = br2.readLine();
|
||||
while (line1 != null && line2 != null && line1.equals(line2)) {
|
||||
while (line1 != null && line1.equals(line2)) {
|
||||
line1 = br1.readLine();
|
||||
line2 = br2.readLine();
|
||||
}
|
||||
return line1 == null ? line2 == null ? true : false : line1.equals(line2);
|
||||
return Objects.equals(line1, line2);
|
||||
} catch (IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -10,16 +10,16 @@ public interface StreamProgress {
|
||||
/**
|
||||
* 开始
|
||||
*/
|
||||
public void start();
|
||||
void start();
|
||||
|
||||
/**
|
||||
* 进行中
|
||||
* @param progressSize 已经进行的大小
|
||||
*/
|
||||
public void progress(long progressSize);
|
||||
void progress(long progressSize);
|
||||
|
||||
/**
|
||||
* 结束
|
||||
*/
|
||||
public void finish();
|
||||
void finish();
|
||||
}
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
final String files[] = src.list();
|
||||
final String[] files = src.list();
|
||||
File srcFile;
|
||||
File destFile;
|
||||
for (String file : files) {
|
||||
|
||||
@@ -14,6 +14,6 @@ public enum FileMode {
|
||||
/** 打开以便读取和写入。相对于 "rw","rws" 还要求对“文件的内容”或“元数据”的每个更新都同步写入到基础存储设备。 */
|
||||
rws,
|
||||
/** 打开以便读取和写入,相对于 "rw","rwd" 还要求对“文件的内容”的每个更新都同步写入到基础存储设备。 */
|
||||
rwd;
|
||||
rwd
|
||||
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ public class FileReader extends FileWrapper {
|
||||
*/
|
||||
public <T> T read(ReaderHandler<T> readerHandler) throws IORuntimeException {
|
||||
BufferedReader reader = null;
|
||||
T result = null;
|
||||
T result;
|
||||
try {
|
||||
reader = FileUtil.getReader(this.file, charset);
|
||||
result = readerHandler.handle(reader);
|
||||
@@ -274,7 +274,7 @@ public class FileReader extends FileWrapper {
|
||||
* @param <T> Reader处理返回结果类型
|
||||
*/
|
||||
public interface ReaderHandler<T> {
|
||||
public T handle(BufferedReader reader) throws IOException;
|
||||
T handle(BufferedReader reader) throws IOException;
|
||||
}
|
||||
// -------------------------------------------------------------------------- Interface end
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ public enum LineSeparator {
|
||||
|
||||
private String value;
|
||||
|
||||
private LineSeparator(String lineSeparator) {
|
||||
LineSeparator(String lineSeparator) {
|
||||
this.value = lineSeparator;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public class NoResourceException extends IORuntimeException {
|
||||
*/
|
||||
public boolean causeInstanceOf(Class<? extends Throwable> clazz) {
|
||||
Throwable cause = this.getCause();
|
||||
if (null != cause && clazz.isInstance(cause)) {
|
||||
if (clazz.isInstance(cause)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -13,7 +13,7 @@ public interface Watcher {
|
||||
* @param event 事件
|
||||
* @param currentPath 事件发生的当前Path路径
|
||||
*/
|
||||
public void onCreate(WatchEvent<?> event, Path currentPath);
|
||||
void onCreate(WatchEvent<?> event, Path currentPath);
|
||||
|
||||
/**
|
||||
* 文件修改时执行的方法<br>
|
||||
@@ -21,19 +21,19 @@ public interface Watcher {
|
||||
* @param event 事件
|
||||
* @param currentPath 事件发生的当前Path路径
|
||||
*/
|
||||
public void onModify(WatchEvent<?> event, Path currentPath);
|
||||
void onModify(WatchEvent<?> event, Path currentPath);
|
||||
|
||||
/**
|
||||
* 文件删除时执行的方法
|
||||
* @param event 事件
|
||||
* @param currentPath 事件发生的当前Path路径
|
||||
*/
|
||||
public void onDelete(WatchEvent<?> event, Path currentPath);
|
||||
void onDelete(WatchEvent<?> event, Path currentPath);
|
||||
|
||||
/**
|
||||
* 事件丢失或出错时执行的方法
|
||||
* @param event 事件
|
||||
* @param currentPath 事件发生的当前Path路径
|
||||
*/
|
||||
public void onOverflow(WatchEvent<?> event, Path currentPath);
|
||||
void onOverflow(WatchEvent<?> event, Path currentPath);
|
||||
}
|
||||
|
||||
@@ -108,6 +108,6 @@ public class ConsistentHash<T> implements Serializable{
|
||||
*
|
||||
*/
|
||||
public interface HashFunc {
|
||||
public Integer hash(Object key);
|
||||
Integer hash(Object key);
|
||||
}
|
||||
}
|
||||
@@ -19,5 +19,5 @@ public interface Editor<T> {
|
||||
* @param t 被过滤的对象
|
||||
* @return 修改后的对象,如果被过滤返回<code>null</code>
|
||||
*/
|
||||
public T edit(T t);
|
||||
T edit(T t);
|
||||
}
|
||||
|
||||
@@ -12,5 +12,5 @@ public interface Matcher<T>{
|
||||
* @param t 对象
|
||||
* @return 是否匹配
|
||||
*/
|
||||
public boolean match(T t);
|
||||
boolean match(T t);
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ public class Range<T> implements Iterable<T>, Iterator<T>, Serializable {
|
||||
*
|
||||
* @param <T> 需要增加步进的对象
|
||||
*/
|
||||
public static interface Steper<T> {
|
||||
public interface Steper<T> {
|
||||
/**
|
||||
* 增加步进<br>
|
||||
* 增加步进后的返回值如果为{@code null}则表示步进结束<br>
|
||||
|
||||
@@ -17,5 +17,5 @@ public interface Replacer<T> {
|
||||
* @param t 被替换的对象
|
||||
* @return 替代后的对象
|
||||
*/
|
||||
public T replace(T t);
|
||||
T replace(T t);
|
||||
}
|
||||
|
||||
@@ -55,16 +55,16 @@ public class NetUtil {
|
||||
* @return IP V4 地址
|
||||
*/
|
||||
public static String longToIpv4(long longIP) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
final StringBuilder sb = StrUtil.builder();
|
||||
// 直接右移24位
|
||||
sb.append(String.valueOf(longIP >>> 24));
|
||||
sb.append((longIP >>> 24));
|
||||
sb.append(".");
|
||||
// 将高8位置0,然后右移16位
|
||||
sb.append(String.valueOf((longIP & 0x00FFFFFF) >>> 16));
|
||||
sb.append(((longIP & 0x00FFFFFF) >>> 16));
|
||||
sb.append(".");
|
||||
sb.append(String.valueOf((longIP & 0x0000FFFF) >>> 8));
|
||||
sb.append(((longIP & 0x0000FFFF) >>> 8));
|
||||
sb.append(".");
|
||||
sb.append(String.valueOf(longIP & 0x000000FF));
|
||||
sb.append((longIP & 0x000000FF));
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ public class NetUtil {
|
||||
* @return 是否为内网IP
|
||||
*/
|
||||
public static boolean isInnerIP(String ipAddress) {
|
||||
boolean isInnerIp = false;
|
||||
boolean isInnerIp;
|
||||
long ipNum = NetUtil.ipv4ToLong(ipAddress);
|
||||
|
||||
long aBegin = NetUtil.ipv4ToLong("10.0.0.0");
|
||||
@@ -241,7 +241,7 @@ public class NetUtil {
|
||||
* @return 隐藏部分后的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;
|
||||
}
|
||||
|
||||
String destHost = null;
|
||||
int port = 0;
|
||||
String destHost;
|
||||
int port;
|
||||
int index = host.indexOf(":");
|
||||
if (index != -1) {
|
||||
// host:port形式
|
||||
@@ -304,7 +304,7 @@ public class NetUtil {
|
||||
* @since 3.0.1
|
||||
*/
|
||||
public static Collection<NetworkInterface> getNetworkInterfaces() {
|
||||
Enumeration<NetworkInterface> networkInterfaces = null;
|
||||
Enumeration<NetworkInterface> networkInterfaces;
|
||||
try {
|
||||
networkInterfaces = NetworkInterface.getNetworkInterfaces();
|
||||
} catch (SocketException e) {
|
||||
@@ -386,7 +386,7 @@ public class NetUtil {
|
||||
* @since 4.5.17
|
||||
*/
|
||||
public static LinkedHashSet<InetAddress> localAddressList(Filter<InetAddress> addressFilter) {
|
||||
Enumeration<NetworkInterface> networkInterfaces = null;
|
||||
Enumeration<NetworkInterface> networkInterfaces;
|
||||
try {
|
||||
networkInterfaces = NetworkInterface.getNetworkInterfaces();
|
||||
} catch (SocketException e) {
|
||||
@@ -460,8 +460,7 @@ public class NetUtil {
|
||||
});
|
||||
|
||||
if (CollUtil.isNotEmpty(localAddressList)) {
|
||||
InetAddress address = CollUtil.get(localAddressList, 0);
|
||||
return address;
|
||||
return CollUtil.get(localAddressList, 0);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -568,7 +567,7 @@ public class NetUtil {
|
||||
* @param host Server主机
|
||||
* @param port Server端口
|
||||
* @param data 数据
|
||||
* @throws IOException IO异常
|
||||
* @throws IORuntimeException IO异常
|
||||
* @since 3.3.0
|
||||
*/
|
||||
public static void netCat(String host, int port, byte[] data) throws IORuntimeException {
|
||||
|
||||
@@ -39,7 +39,7 @@ public enum ClipboardMonitor implements ClipboardOwner, Runnable, Closeable {
|
||||
/**
|
||||
* 构造,尝试获取剪贴板内容的次数为10,第二次之后延迟100毫秒
|
||||
*/
|
||||
private ClipboardMonitor() {
|
||||
ClipboardMonitor() {
|
||||
this(DEFAULT_TRY_COUNT, DEFAULT_DELAY);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public enum ClipboardMonitor implements ClipboardOwner, Runnable, Closeable {
|
||||
* @param tryCount 尝试获取剪贴板内容的次数
|
||||
* @param delay 响应延迟,当从第二次开始,延迟一定毫秒数等待剪贴板可以获取,当tryCount小于2时无效
|
||||
*/
|
||||
private ClipboardMonitor(int tryCount, long delay) {
|
||||
ClipboardMonitor(int tryCount, long delay) {
|
||||
this(tryCount, delay, ClipboardUtil.getClipboard());
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public enum ClipboardMonitor implements ClipboardOwner, Runnable, Closeable {
|
||||
* @param delay 响应延迟,当从第二次开始,延迟一定毫秒数等待剪贴板可以获取,当tryCount小于2时无效
|
||||
* @param clipboard 剪贴板对象
|
||||
*/
|
||||
private ClipboardMonitor(int tryCount, long delay, Clipboard clipboard) {
|
||||
ClipboardMonitor(int tryCount, long delay, Clipboard clipboard) {
|
||||
this.tryCount = tryCount;
|
||||
this.delay = delay;
|
||||
this.clipboard = clipboard;
|
||||
|
||||
@@ -25,7 +25,7 @@ public enum RejectPolicy {
|
||||
|
||||
private RejectedExecutionHandler value;
|
||||
|
||||
private RejectPolicy(RejectedExecutionHandler handler) {
|
||||
RejectPolicy(RejectedExecutionHandler handler) {
|
||||
this.value = handler;
|
||||
}
|
||||
|
||||
|
||||
@@ -77,9 +77,7 @@ public class BooleanUtil {
|
||||
public static boolean toBoolean(String valueStr) {
|
||||
if (StrUtil.isNotBlank(valueStr)) {
|
||||
valueStr = valueStr.trim().toLowerCase();
|
||||
if (ArrayUtil.contains(TRUE_ARRAY, valueStr)) {
|
||||
return true;
|
||||
}
|
||||
return ArrayUtil.contains(TRUE_ARRAY, valueStr);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ import cn.hutool.core.lang.Singleton;
|
||||
* 类工具类 <br>
|
||||
*
|
||||
* @author xiaoleilu
|
||||
*
|
||||
*/
|
||||
public class ClassUtil {
|
||||
|
||||
@@ -170,6 +169,7 @@ public class ClassUtil {
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------- Scan classes
|
||||
|
||||
/**
|
||||
* 扫描指定包路径下所有包含指定注解的类
|
||||
*
|
||||
@@ -229,6 +229,7 @@ public class ClassUtil {
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------- Method
|
||||
|
||||
/**
|
||||
* 获得指定类中的Public方法名<br>
|
||||
* 去重重载的方法
|
||||
@@ -280,7 +281,7 @@ public class ClassUtil {
|
||||
* @return 过滤后的方法列表
|
||||
*/
|
||||
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
|
||||
|
||||
/**
|
||||
* 查找指定类中的所有字段(包括非public字段), 字段不存在则返回<code>null</code>
|
||||
*
|
||||
@@ -379,6 +381,7 @@ public class ClassUtil {
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------- Classpath
|
||||
|
||||
/**
|
||||
* 获得ClassPath,不解码路径中的特殊字符(例如空格和中文)
|
||||
*
|
||||
@@ -425,7 +428,7 @@ public class ClassUtil {
|
||||
} catch (IOException e) {
|
||||
throw new UtilException(e, "Loading classPath [{}] error!", packagePath);
|
||||
}
|
||||
final Set<String> paths = new HashSet<String>();
|
||||
final Set<String> paths = new HashSet<>();
|
||||
String path;
|
||||
while (resources.hasMoreElements()) {
|
||||
path = resources.nextElement().getPath();
|
||||
@@ -606,6 +609,7 @@ public class ClassUtil {
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------------- Invoke start
|
||||
|
||||
/**
|
||||
* 执行方法<br>
|
||||
* 可执行Private方法,也可执行static方法<br>
|
||||
@@ -782,18 +786,13 @@ public class ClassUtil {
|
||||
if (targetType.isPrimitive()) {
|
||||
// 原始类型
|
||||
Class<?> resolvedPrimitive = BasicType.wrapperPrimitiveMap.get(sourceType);
|
||||
if (resolvedPrimitive != null && targetType.equals(resolvedPrimitive)) {
|
||||
return true;
|
||||
}
|
||||
return targetType.equals(resolvedPrimitive);
|
||||
} else {
|
||||
// 包装类型
|
||||
Class<?> resolvedWrapper = BasicType.primitiveWrapperMap.get(sourceType);
|
||||
if (resolvedWrapper != null && targetType.isAssignableFrom(resolvedWrapper)) {
|
||||
return true;
|
||||
return resolvedWrapper != null && targetType.isAssignableFrom(resolvedWrapper);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定类是否为Public
|
||||
@@ -908,7 +907,7 @@ public class ClassUtil {
|
||||
* @since 3.2.0
|
||||
*/
|
||||
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) {
|
||||
final Type argumentType = TypeUtil.getTypeArgument(clazz, index);
|
||||
if (null != argumentType && argumentType instanceof Class) {
|
||||
if (argumentType instanceof Class) {
|
||||
return (Class<?>) argumentType;
|
||||
}
|
||||
return null;
|
||||
@@ -1034,13 +1033,12 @@ public class ClassUtil {
|
||||
*/
|
||||
public static boolean isJdkClass(Class<?> clazz) {
|
||||
final Package objectPackage = clazz.getPackage();
|
||||
if(null == objectPackage) {
|
||||
if (null == objectPackage) {
|
||||
return false;
|
||||
}
|
||||
final String objectPackageName = objectPackage.getName();
|
||||
if (objectPackageName.startsWith("java.") || objectPackageName.startsWith("javax.") || clazz.getClassLoader() == null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return objectPackageName.startsWith("java.") //
|
||||
|| objectPackageName.startsWith("javax.") //
|
||||
|| clazz.getClassLoader() == null;
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ public class ModifierUtil {
|
||||
* @author looly
|
||||
* @since 4.0.5
|
||||
*/
|
||||
public static enum ModifierType {
|
||||
public enum ModifierType {
|
||||
/** public修饰符,所有类都能访问 */
|
||||
PUBLIC(Modifier.PUBLIC),
|
||||
/** private修饰符,只能被自己访问和修改 */
|
||||
@@ -51,7 +51,7 @@ public class ModifierUtil {
|
||||
* 构造
|
||||
* @param modifier 修饰符int表示,见{@link Modifier}
|
||||
*/
|
||||
private ModifierType(int modifier) {
|
||||
ModifierType(int modifier) {
|
||||
this.value = modifier;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public class ReferenceUtil {
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public static enum ReferenceType {
|
||||
public enum ReferenceType {
|
||||
/** 软引用,在GC报告内存不足时会被GC回收 */
|
||||
SOFT,
|
||||
/** 弱引用,在GC时发现弱引用会回收其对象 */
|
||||
@@ -69,7 +69,7 @@ public class ReferenceUtil {
|
||||
* 虚引用,在GC时发现虚引用对象,会将{@link PhantomReference}插入{@link ReferenceQueue}。 <br>
|
||||
* 此时对象未被真正回收,要等到{@link ReferenceQueue}被真正处理后才会被回收。
|
||||
*/
|
||||
PHANTOM;
|
||||
PHANTOM
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
package cn.hutool.core.convert;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 类型转换工具单元测试
|
||||
|
||||
@@ -42,8 +42,8 @@ public class ConvertToBeanTest {
|
||||
person.setSubName("sub名字");
|
||||
|
||||
Map<String, String> map = Convert.toMap(String.class, String.class, person);
|
||||
Assert.assertEquals(map.get("name"), "测试A11");
|
||||
Assert.assertEquals(map.get("age"), 14);
|
||||
Assert.assertEquals("测试A11", map.get("name"));
|
||||
Assert.assertEquals("14", map.get("age"));
|
||||
Assert.assertEquals("11213232", map.get("openid"));
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import cn.hutool.core.date.BetweenFormater.Level;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
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.Filter;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* {@link ArrayUtil} 数组工具单元测试
|
||||
|
||||
@@ -52,10 +52,10 @@ public class EnumUtilTest {
|
||||
Assert.assertEquals("type1", enumMap.get("TEST1"));
|
||||
}
|
||||
|
||||
public static enum TestEnum{
|
||||
public enum TestEnum{
|
||||
TEST1("type1"), TEST2("type2"), TEST3("type3");
|
||||
|
||||
private TestEnum(String type) {
|
||||
TestEnum(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,14 +13,14 @@ public interface TaskListener {
|
||||
* 定时任务启动时触发
|
||||
* @param executor {@link TaskExecutor}
|
||||
*/
|
||||
public void onStart(TaskExecutor executor);
|
||||
void onStart(TaskExecutor executor);
|
||||
|
||||
/**
|
||||
* 任务成功结束时触发
|
||||
*
|
||||
* @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 exception 异常
|
||||
*/
|
||||
public void onFailed(TaskExecutor executor, Throwable exception);
|
||||
void onFailed(TaskExecutor executor, Throwable exception);
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ public class CronPattern {
|
||||
|
||||
boolean eval;
|
||||
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)// 匹配分
|
||||
&& hourMatchers.get(i).match(hour)// 匹配时
|
||||
&& isMatchDayOfMonth(dayOfMonthMatchers.get(i), dayOfMonth, month, calendar.isLeapYear(year))// 匹配日
|
||||
@@ -211,7 +211,7 @@ public class CronPattern {
|
||||
* @since 4.0.2
|
||||
*/
|
||||
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 {
|
||||
this.minuteMatchers.add(ValueMatcherBuilder.build(parts[0 + offset], MINUTE_VALUE_PARSER));
|
||||
this.minuteMatchers.add(ValueMatcherBuilder.build(parts[offset], MINUTE_VALUE_PARSER));
|
||||
} catch (Exception e) {
|
||||
throw new CronException(e, "Invalid pattern [{}], parsing 'minute' field error!", pattern);
|
||||
}
|
||||
|
||||
@@ -19,19 +19,19 @@ public interface ValueParser {
|
||||
* @param value String值
|
||||
* @return int
|
||||
*/
|
||||
public int parse(String value);
|
||||
int parse(String value);
|
||||
|
||||
/**
|
||||
* 返回最小值
|
||||
*
|
||||
* @return 最小值
|
||||
*/
|
||||
public int getMin();
|
||||
int getMin();
|
||||
|
||||
/**
|
||||
* 返回最大值
|
||||
*
|
||||
* @return 最大值
|
||||
*/
|
||||
public int getMax();
|
||||
int getMax();
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class InvokeTask implements Task{
|
||||
@Override
|
||||
public void execute() {
|
||||
try {
|
||||
ReflectUtil.invoke(this.obj, this.method, new Object[]{});
|
||||
ReflectUtil.invoke(this.obj, this.method);
|
||||
} catch (UtilException e) {
|
||||
throw new CronException(e.getCause());
|
||||
}
|
||||
|
||||
@@ -18,5 +18,5 @@ public interface Task {
|
||||
* 作业的具体实现需考虑异常情况,默认情况下任务异常在监听中统一监听处理,如果不加入监听,异常会被忽略<br>
|
||||
* 因此最好自行捕获异常后处理
|
||||
*/
|
||||
public void execute();
|
||||
void execute();
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public enum GlobalBouncyCastleProvider {
|
||||
private Provider provider;
|
||||
private static boolean useBouncyCastle = true;
|
||||
|
||||
private GlobalBouncyCastleProvider() {
|
||||
GlobalBouncyCastleProvider() {
|
||||
try {
|
||||
this.provider = ProviderFactory.createBouncyCastleProvider();
|
||||
} catch (NoClassDefFoundError e) {
|
||||
@@ -33,7 +33,7 @@ public enum GlobalBouncyCastleProvider {
|
||||
* 设置是否使用Bouncy Castle库<br>
|
||||
* 如果设置为false,表示强制关闭Bouncy Castle而使用JDK
|
||||
*
|
||||
* @param isUseBouncyCastle
|
||||
* @param isUseBouncyCastle 是否使用BouncyCastle库
|
||||
* @since 4.5.2
|
||||
*/
|
||||
public static void setUseBouncyCastle(boolean isUseBouncyCastle) {
|
||||
|
||||
@@ -42,5 +42,5 @@ public enum Mode {
|
||||
/**
|
||||
* Propagating Cipher Block
|
||||
*/
|
||||
PCBC;
|
||||
PCBC
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public enum AsymmetricAlgorithm {
|
||||
* 构造
|
||||
* @param value 算法字符表示,区分大小写
|
||||
*/
|
||||
private AsymmetricAlgorithm(String value) {
|
||||
AsymmetricAlgorithm(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,5 +7,5 @@ package cn.hutool.crypto.asymmetric;
|
||||
*
|
||||
*/
|
||||
public enum KeyType {
|
||||
PrivateKey, PublicKey;
|
||||
PrivateKey, PublicKey
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public enum SignAlgorithm {
|
||||
*
|
||||
* @param value 算法字符表示,区分大小写
|
||||
*/
|
||||
private SignAlgorithm(String value) {
|
||||
SignAlgorithm(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,21 +12,21 @@ import cn.hutool.core.util.CharsetUtil;
|
||||
* 使用方法如下:
|
||||
* <p>
|
||||
* <code>
|
||||
* String pw_hash = BCrypt.hashpw(plain_password, BCrypt.gensalt()); <br />
|
||||
* </code>
|
||||
* String pw_hash = BCrypt.hashpw(plain_password, BCrypt.gensalt()); <br />
|
||||
* </code>
|
||||
* <p>
|
||||
* 使用checkpw方法检查被加密的字符串是否与原始字符串匹配:
|
||||
* <p>
|
||||
* <code>
|
||||
* BCrypt.checkpw(candidate_password, stored_hash);
|
||||
* </code>
|
||||
* BCrypt.checkpw(candidate_password, stored_hash);
|
||||
* </code>
|
||||
* <p>
|
||||
* gensalt方法提供了可选参数 (log_rounds) 来定义加盐多少,也决定了加密的复杂度:
|
||||
* <p>
|
||||
* <code>
|
||||
* String strong_salt = BCrypt.gensalt(10)<br />
|
||||
* String stronger_salt = BCrypt.gensalt(12)<br />
|
||||
* </code>
|
||||
* String strong_salt = BCrypt.gensalt(10)<br />
|
||||
* String stronger_salt = BCrypt.gensalt(12)<br />
|
||||
* </code>
|
||||
*
|
||||
* @author Damien Miller
|
||||
* @since 4.1.1
|
||||
@@ -40,9 +40,9 @@ public class BCrypt {
|
||||
private static final int BLOWFISH_NUM_ROUNDS = 16;
|
||||
|
||||
// Initial contents of key schedule
|
||||
private static final int P_orig[] = { 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7,
|
||||
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[] P_orig = {0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7,
|
||||
0xc97c50dd, 0x3f84d5b5, 0xb5470917, 0x9216d5d9, 0x8979fb1b};
|
||||
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,
|
||||
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,
|
||||
@@ -110,25 +110,25 @@ public class BCrypt {
|
||||
0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
|
||||
0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, 0x53113ec0, 0x1640e3d3, 0x38abbd60,
|
||||
0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, 0x90d4f869, 0xa65cdea0,
|
||||
0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6 };
|
||||
0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6};
|
||||
|
||||
// bcrypt IV: "OrpheanBeholderScryDoubt". The C implementation calls
|
||||
// this "ciphertext", but it is really plaintext or an IV. We keep
|
||||
// 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
|
||||
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' };
|
||||
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'};
|
||||
|
||||
// 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,
|
||||
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
|
||||
private int P[];
|
||||
private int S[];
|
||||
private int[] P;
|
||||
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.
|
||||
@@ -136,11 +136,11 @@ public class BCrypt {
|
||||
* @param d the byte array to encode
|
||||
* @param len the number of bytes to encode
|
||||
* @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;
|
||||
StringBuffer rs = new StringBuffer();
|
||||
StringBuilder rs = new StringBuilder();
|
||||
int c1, c2;
|
||||
|
||||
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 maxolen the maximum number of bytes to decode
|
||||
* @return an array containing the decoded bytes
|
||||
* @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();
|
||||
int off = 0, slen = s.length(), olen = 0;
|
||||
byte ret[];
|
||||
byte[] ret;
|
||||
byte c1, c2, c3, c4, o;
|
||||
|
||||
if (maxolen <= 0)
|
||||
@@ -236,11 +237,11 @@ public class BCrypt {
|
||||
* @param lr an array containing the two 32-bit half 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];
|
||||
|
||||
l ^= P[0];
|
||||
for (i = 0; i <= BLOWFISH_NUM_ROUNDS - 2;) {
|
||||
for (i = 0; i <= BLOWFISH_NUM_ROUNDS - 2; ) {
|
||||
// Feistel substitution on left word
|
||||
n = S[(l >> 24) & 0xff];
|
||||
n += S[0x100 | ((l >> 16) & 0xff)];
|
||||
@@ -266,7 +267,7 @@ public class BCrypt {
|
||||
* @param offp a "pointer" (as a one-entry array) to the current offset into 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 word = 0;
|
||||
int off = offp[0];
|
||||
@@ -293,14 +294,14 @@ public class BCrypt {
|
||||
*
|
||||
* @param key an array containing the key
|
||||
*/
|
||||
private void key(byte key[]) {
|
||||
private void key(byte[] key) {
|
||||
int i;
|
||||
int koffp[] = { 0 };
|
||||
int lr[] = { 0, 0 };
|
||||
int[] koffp = {0};
|
||||
int[] lr = {0, 0};
|
||||
int plen = P.length, slen = S.length;
|
||||
|
||||
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) {
|
||||
encipher(lr, 0);
|
||||
@@ -321,26 +322,27 @@ public class BCrypt {
|
||||
* @param data salt information
|
||||
* @param key password information
|
||||
*/
|
||||
private void ekskey(byte data[], byte key[]) {
|
||||
private void ekskey(byte[] data, byte[] key) {
|
||||
int i;
|
||||
int koffp[] = { 0 }, doffp[] = { 0 };
|
||||
int lr[] = { 0, 0 };
|
||||
int[] koffp = {0};
|
||||
int[] doffp = {0};
|
||||
int[] lr = {0, 0};
|
||||
int plen = P.length, slen = S.length;
|
||||
|
||||
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) {
|
||||
lr[0] ^= streamtoword(data, doffp);
|
||||
lr[1] ^= streamtoword(data, doffp);
|
||||
lr[0] ^= streamToWord(data, doffp);
|
||||
lr[1] ^= streamToWord(data, doffp);
|
||||
encipher(lr, 0);
|
||||
P[i] = lr[0];
|
||||
P[i + 1] = lr[1];
|
||||
}
|
||||
|
||||
for (i = 0; i < slen; i += 2) {
|
||||
lr[0] ^= streamtoword(data, doffp);
|
||||
lr[1] ^= streamtoword(data, doffp);
|
||||
lr[0] ^= streamToWord(data, doffp);
|
||||
lr[1] ^= streamToWord(data, doffp);
|
||||
encipher(lr, 0);
|
||||
S[i] = lr[0];
|
||||
S[i + 1] = lr[1];
|
||||
@@ -356,10 +358,10 @@ public class BCrypt {
|
||||
* @param cdata 加密数据
|
||||
* @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 clen = cdata.length;
|
||||
byte ret[];
|
||||
byte[] ret;
|
||||
|
||||
if (log_rounds < 4 || log_rounds > 30)
|
||||
throw new IllegalArgumentException("Bad number of rounds");
|
||||
@@ -409,9 +411,10 @@ public class BCrypt {
|
||||
public static String hashpw(String password, String salt) {
|
||||
BCrypt bcrypt;
|
||||
String real_salt;
|
||||
byte saltb[], hashed[];
|
||||
byte[] saltb;
|
||||
byte[] hashed;
|
||||
char minor = (char) 0;
|
||||
int rounds, off = 0;
|
||||
int rounds, off;
|
||||
StringBuilder rs = new StringBuilder();
|
||||
|
||||
if (salt.charAt(0) != '$' || salt.charAt(1) != '2')
|
||||
@@ -432,7 +435,7 @@ public class BCrypt {
|
||||
|
||||
real_salt = salt.substring(off + 3, off + 25);
|
||||
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();
|
||||
hashed = bcrypt.crypt(passwordb, saltb, rounds, (int[]) bf_crypt_ciphertext.clone());
|
||||
@@ -446,7 +449,7 @@ public class BCrypt {
|
||||
if (rounds > 30) {
|
||||
throw new IllegalArgumentException("rounds exceeds maximum (30)");
|
||||
}
|
||||
rs.append(Integer.toString(rounds));
|
||||
rs.append(rounds);
|
||||
rs.append("$");
|
||||
rs.append(encode_base64(saltb, saltb.length));
|
||||
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) {
|
||||
final StringBuilder rs = new StringBuilder();
|
||||
byte rnd[] = new byte[BCRYPT_SALT_LEN];
|
||||
byte[] rnd = new byte[BCRYPT_SALT_LEN];
|
||||
|
||||
random.nextBytes(rnd);
|
||||
|
||||
@@ -472,7 +475,7 @@ public class BCrypt {
|
||||
if (log_rounds > 30) {
|
||||
throw new IllegalArgumentException("log_rounds exceeds maximum (30)");
|
||||
}
|
||||
rs.append(Integer.toString(log_rounds));
|
||||
rs.append(log_rounds);
|
||||
rs.append("$");
|
||||
rs.append(encode_base64(rnd, rnd.length));
|
||||
return rs.toString();
|
||||
@@ -505,8 +508,8 @@ public class BCrypt {
|
||||
* @return 是否匹配
|
||||
*/
|
||||
public static boolean checkpw(String plaintext, String hashed) {
|
||||
byte hashed_bytes[];
|
||||
byte try_bytes[];
|
||||
byte[] hashed_bytes;
|
||||
byte[] try_bytes;
|
||||
String try_pw = hashpw(plaintext, hashed);
|
||||
hashed_bytes = hashed.getBytes(CharsetUtil.CHARSET_UTF_8);
|
||||
try_bytes = try_pw.getBytes(CharsetUtil.CHARSET_UTF_8);
|
||||
|
||||
@@ -21,7 +21,7 @@ public enum DigestAlgorithm {
|
||||
*
|
||||
* @param value 算法字符串表示
|
||||
*/
|
||||
private DigestAlgorithm(String value) {
|
||||
DigestAlgorithm(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public enum SymmetricAlgorithm {
|
||||
* 构造
|
||||
* @param value 算法的字符串表示,区分大小写
|
||||
*/
|
||||
private SymmetricAlgorithm(String value) {
|
||||
SymmetricAlgorithm(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
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.crypto.KeyUtil;
|
||||
import cn.hutool.crypto.Mode;
|
||||
|
||||
@@ -1,23 +1,15 @@
|
||||
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.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.KeyUtil;
|
||||
import cn.hutool.crypto.Mode;
|
||||
import cn.hutool.crypto.Padding;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.crypto.symmetric.AES;
|
||||
import cn.hutool.crypto.symmetric.DES;
|
||||
import cn.hutool.crypto.symmetric.DESede;
|
||||
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
|
||||
import cn.hutool.crypto.symmetric.SymmetricCrypto;
|
||||
import cn.hutool.crypto.symmetric.Vigenere;
|
||||
import cn.hutool.crypto.symmetric.*;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* 对称加密算法单元测试
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
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.lang.Assert;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
@@ -17,11 +10,11 @@ import cn.hutool.db.Page;
|
||||
import cn.hutool.db.StatementUtil;
|
||||
import cn.hutool.db.dialect.Dialect;
|
||||
import cn.hutool.db.dialect.DialectName;
|
||||
import cn.hutool.db.sql.Condition;
|
||||
import cn.hutool.db.sql.LogicalOperator;
|
||||
import cn.hutool.db.sql.Query;
|
||||
import cn.hutool.db.sql.SqlBuilder;
|
||||
import cn.hutool.db.sql.Wrapper;
|
||||
import cn.hutool.db.sql.*;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* ANSI SQL 方言
|
||||
|
||||
@@ -193,12 +193,9 @@ public abstract class AbstractDSFactory extends DSFactory {
|
||||
return false;
|
||||
}
|
||||
if (setting == null) {
|
||||
if (other.setting != null) {
|
||||
return false;
|
||||
return other.setting == null;
|
||||
} else {
|
||||
return setting.equals(other.setting);
|
||||
}
|
||||
} else if (!setting.equals(other.setting)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public class GlobalDSFactory {
|
||||
private static volatile DSFactory factory;
|
||||
private static Object lock = new Object();
|
||||
|
||||
/**
|
||||
/*
|
||||
* 设置在JVM关闭时关闭所有数据库连接
|
||||
*/
|
||||
static {
|
||||
|
||||
@@ -28,5 +28,5 @@ public interface RsHandler<T> extends Serializable{
|
||||
* @return 处理后生成的对象
|
||||
* @throws SQLException SQL异常
|
||||
*/
|
||||
public T handle(ResultSet rs) throws SQLException;
|
||||
T handle(ResultSet rs) throws SQLException;
|
||||
}
|
||||
|
||||
@@ -10,12 +10,12 @@ import java.util.StringTokenizer;
|
||||
* @author looly
|
||||
*/
|
||||
public class SqlFormatter {
|
||||
private static final Set<String> BEGIN_CLAUSES = new HashSet<String>();
|
||||
private static final Set<String> END_CLAUSES = new HashSet<String>();
|
||||
private static final Set<String> LOGICAL = new HashSet<String>();
|
||||
private static final Set<String> QUANTIFIERS = new HashSet<String>();
|
||||
private static final Set<String> DML = new HashSet<String>();
|
||||
private static final Set<String> MISC = new HashSet<String>();
|
||||
private static final Set<String> BEGIN_CLAUSES = new HashSet<>();
|
||||
private static final Set<String> END_CLAUSES = new HashSet<>();
|
||||
private static final Set<String> LOGICAL = new HashSet<>();
|
||||
private static final Set<String> QUANTIFIERS = new HashSet<>();
|
||||
private static final Set<String> DML = new HashSet<>();
|
||||
private static final Set<String> MISC = new HashSet<>();
|
||||
|
||||
static {
|
||||
BEGIN_CLAUSES.add("left");
|
||||
@@ -31,7 +31,6 @@ public class SqlFormatter {
|
||||
END_CLAUSES.add("join");
|
||||
END_CLAUSES.add("from");
|
||||
END_CLAUSES.add("by");
|
||||
END_CLAUSES.add("join");
|
||||
END_CLAUSES.add("into");
|
||||
END_CLAUSES.add("union");
|
||||
|
||||
@@ -55,8 +54,8 @@ public class SqlFormatter {
|
||||
MISC.add("on");
|
||||
}
|
||||
|
||||
private static String indentString = " ";
|
||||
private static String initial = "\n ";
|
||||
private static final String indentString = " ";
|
||||
private static final String initial = "\n ";
|
||||
|
||||
public static String format(String source) {
|
||||
return new FormatProcess(source).perform().trim();
|
||||
@@ -74,8 +73,8 @@ public class SqlFormatter {
|
||||
boolean afterInsert = false;
|
||||
int inFunction = 0;
|
||||
int parensSinceSelect = 0;
|
||||
private LinkedList<Integer> parenCounts = new LinkedList<Integer>();
|
||||
private LinkedList<Boolean> afterByOrFromOrSelects = new LinkedList<Boolean>();
|
||||
private LinkedList<Integer> parenCounts = new LinkedList<>();
|
||||
private LinkedList<Boolean> afterByOrFromOrSelects = new LinkedList<>();
|
||||
|
||||
int indent = 1;
|
||||
|
||||
@@ -141,7 +140,7 @@ public class SqlFormatter {
|
||||
misc();
|
||||
}
|
||||
|
||||
if (!isWhitespace(this.token)) {
|
||||
if (false == isWhitespace(this.token)) {
|
||||
this.lastToken = this.lcToken;
|
||||
}
|
||||
}
|
||||
@@ -313,7 +312,7 @@ public class SqlFormatter {
|
||||
}
|
||||
|
||||
private static boolean isWhitespace(String token) {
|
||||
return " \n\r\f\t".indexOf(token) >= 0;
|
||||
return " \n\r\f\t".contains(token);
|
||||
}
|
||||
|
||||
private void newline() {
|
||||
|
||||
@@ -60,7 +60,7 @@ public enum TransactionLevel {
|
||||
/** 事务级别,对应Connection中的常量值 */
|
||||
private int level;
|
||||
|
||||
private TransactionLevel(int level) {
|
||||
TransactionLevel(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,5 +13,5 @@ public enum FtpMode {
|
||||
/** 主动模式 */
|
||||
Active,
|
||||
/** 被动模式 */
|
||||
Passive;
|
||||
Passive
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public enum GlobalMailAccount {
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
private GlobalMailAccount() {
|
||||
GlobalMailAccount() {
|
||||
mailAccount = createDefaultAccount();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
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.nio.charset.Charset;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 邮件账户对象
|
||||
*
|
||||
|
||||
@@ -68,7 +68,7 @@ public class UploadFile {
|
||||
* 写入后原临时文件会被删除
|
||||
* @param destPath 目标文件路径
|
||||
* @return 目标文件
|
||||
* @throws IOException
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
public File write(String destPath) throws IOException {
|
||||
if(data != null || tempFile != null) {
|
||||
@@ -100,12 +100,9 @@ public class UploadFile {
|
||||
return destination;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content of file upload item.
|
||||
*/
|
||||
/**
|
||||
* @return 获得文件字节流
|
||||
* @throws IOException
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
public byte[] getFileContent() throws IOException {
|
||||
assertValid();
|
||||
@@ -121,7 +118,7 @@ public class UploadFile {
|
||||
|
||||
/**
|
||||
* @return 获得文件流
|
||||
* @throws IOException
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
public InputStream getFileInputStream() throws IOException {
|
||||
assertValid();
|
||||
@@ -179,7 +176,7 @@ public class UploadFile {
|
||||
* 处理上传表单流,提取出文件
|
||||
*
|
||||
* @param input 上传表单的流
|
||||
* @throws IOException
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
protected boolean processStream(MultipartRequestInputStream input) throws IOException {
|
||||
if (!isAllowedExtension()) {
|
||||
@@ -260,7 +257,7 @@ public class UploadFile {
|
||||
|
||||
/**
|
||||
* 断言是否文件流可用
|
||||
* @throws IOException
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
private void assertValid() throws IOException {
|
||||
if(! isUploaded()) {
|
||||
|
||||
@@ -34,7 +34,7 @@ public enum ChannelType {
|
||||
*
|
||||
* @param value 类型值
|
||||
*/
|
||||
private ChannelType(String value) {
|
||||
ChannelType(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -429,12 +429,12 @@ public class Sftp extends AbstractFtp {
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public static enum Mode {
|
||||
public enum Mode {
|
||||
/** 完全覆盖模式,这是JSch的默认文件传输模式,即如果目标文件已经存在,传输的文件将完全覆盖目标文件,产生新的文件。 */
|
||||
OVERWRITE,
|
||||
/** 恢复模式,如果文件已经传输一部分,这时由于网络或其他任何原因导致文件传输中断,如果下一次传输相同的文件,则会从上一次中断的地方续传。 */
|
||||
RESUME,
|
||||
/** 追加模式,如果目标文件已存在,传输的文件将在目标文件后追加。 */
|
||||
APPEND;
|
||||
APPEND
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ public class TemplateConfig implements Serializable {
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
public static enum ResourceMode {
|
||||
public enum ResourceMode {
|
||||
/** 从ClassPath加载模板 */
|
||||
CLASSPATH,
|
||||
/** 从File目录加载模板 */
|
||||
@@ -142,7 +142,7 @@ public class TemplateConfig implements Serializable {
|
||||
/** 从模板文本加载模板 */
|
||||
STRING,
|
||||
/** 复合加载模板(分别从File、ClassPath、Web-root、String方式尝试查找模板) */
|
||||
COMPOSITE;
|
||||
COMPOSITE
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -185,5 +185,5 @@ public class TemplateConfig implements Serializable {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public enum ContentType {
|
||||
TEXT_XML("text/xml");
|
||||
|
||||
private String value;
|
||||
private ContentType(String value) {
|
||||
ContentType(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public enum GlobalHeaders {
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
private GlobalHeaders() {
|
||||
GlobalHeaders() {
|
||||
putDefault(false);
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ public enum GlobalHeaders {
|
||||
if (null != name && null != value) {
|
||||
final List<String> values = headers.get(name.trim());
|
||||
if (isOverride || CollectionUtil.isEmpty(values)) {
|
||||
final ArrayList<String> valueList = new ArrayList<String>();
|
||||
final ArrayList<String> valueList = new ArrayList<>();
|
||||
valueList.add(value);
|
||||
headers.put(name.trim(), valueList);
|
||||
} else {
|
||||
|
||||
@@ -64,7 +64,7 @@ public enum Header {
|
||||
LOCATION("Location");
|
||||
|
||||
private String value;
|
||||
private Header(String value) {
|
||||
Header(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import javax.net.ssl.SSLSocketFactory;
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.resource.BytesResource;
|
||||
import cn.hutool.core.io.resource.FileResource;
|
||||
@@ -811,11 +812,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* @since 3.3.0
|
||||
*/
|
||||
public HttpRequest setMaxRedirectCount(int maxRedirectCount) {
|
||||
if (maxRedirectCount > 0) {
|
||||
this.maxRedirectCount = maxRedirectCount;
|
||||
} else {
|
||||
this.maxRedirectCount = 0;
|
||||
}
|
||||
this.maxRedirectCount = Math.max(maxRedirectCount, 0);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -993,7 +990,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
// 自定义Cookie
|
||||
.setCookie(this.cookie)
|
||||
// 定义转发
|
||||
.setInstanceFollowRedirects(this.maxRedirectCount > 0 ? true : false)
|
||||
.setInstanceFollowRedirects(this.maxRedirectCount > 0)
|
||||
// 流方式上传数据
|
||||
.setChunkedStreamingMode(this.blockSize)
|
||||
// 覆盖默认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 {
|
||||
if (Method.POST.equals(this.method) || Method.PUT.equals(this.method) || Method.DELETE.equals(this.method) || this.isRest) {
|
||||
if (CollectionUtil.isEmpty(this.fileForm)) {
|
||||
@@ -1076,7 +1073,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
} catch (IOException e) {
|
||||
// 异常时关闭连接
|
||||
this.httpConnection.disconnectQuietly();
|
||||
throw new HttpException(e);
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1084,7 +1081,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* 发送普通表单<br>
|
||||
* 发送数据后自动关闭输出流
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
private void sendFormUrlEncoded() throws IOException {
|
||||
if (StrUtil.isBlank(this.header(Header.CONTENT_TYPE))) {
|
||||
@@ -1105,7 +1102,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* 发送多组件请求(例如包含文件的表单)<br>
|
||||
* 发送数据后自动关闭输出流
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
private void sendMultipart() throws IOException {
|
||||
setMultipart();// 设置表单类型为Multipart
|
||||
@@ -1114,8 +1111,6 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
writeFileForm(out);
|
||||
writeForm(out);
|
||||
formEnd(out);
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1125,9 +1120,8 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* 发送普通表单内容
|
||||
*
|
||||
* @param out 输出流
|
||||
* @throws IOException
|
||||
*/
|
||||
private void writeForm(OutputStream out) throws IOException {
|
||||
private void writeForm(OutputStream out) {
|
||||
if (CollectionUtil.isNotEmpty(this.form)) {
|
||||
StringBuilder builder = StrUtil.builder();
|
||||
for (Entry<String, Object> entry : this.form.entrySet()) {
|
||||
@@ -1143,9 +1137,8 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* 发送文件对象表单
|
||||
*
|
||||
* @param out 输出流
|
||||
* @throws IOException
|
||||
*/
|
||||
private void writeFileForm(OutputStream out) throws IOException {
|
||||
private void writeFileForm(OutputStream out) {
|
||||
for (Entry<String, Resource> entry : this.fileForm.entrySet()) {
|
||||
appendPart(entry.getKey(), entry.getValue(), out);
|
||||
}
|
||||
@@ -1191,7 +1184,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
* 上传表单结束
|
||||
*
|
||||
* @param out 输出流
|
||||
* @throws IOException
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
private void formEnd(OutputStream out) throws IOException {
|
||||
out.write(BOUNDARY_END);
|
||||
@@ -1201,7 +1194,7 @@ public class HttpRequest extends HttpBase<HttpRequest> {
|
||||
/**
|
||||
* 设置表单类型为Multipart(文件上传)
|
||||
*
|
||||
* @return HttpConnection
|
||||
* @return HttpConnection HTTP连接对象
|
||||
*/
|
||||
private void setMultipart() {
|
||||
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
|
||||
*/
|
||||
private boolean isIgnoreResponseBody() {
|
||||
if (Method.HEAD == this.method || Method.CONNECT == this.method || Method.OPTIONS == this.method || Method.TRACE == this.method) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return Method.HEAD == this.method //
|
||||
|| Method.CONNECT == this.method //
|
||||
|| Method.OPTIONS == this.method //
|
||||
|| Method.TRACE == this.method;
|
||||
}
|
||||
// ---------------------------------------------------------------- Private method end
|
||||
|
||||
|
||||
@@ -6,5 +6,5 @@ package cn.hutool.http;
|
||||
*
|
||||
*/
|
||||
public enum Method {
|
||||
GET, POST, HEAD, OPTIONS, PUT, DELETE, TRACE, CONNECT, PATCH;
|
||||
GET, POST, HEAD, OPTIONS, PUT, DELETE, TRACE, CONNECT, PATCH
|
||||
}
|
||||
|
||||
@@ -5,185 +5,185 @@ package cn.hutool.http;
|
||||
* @author Looly
|
||||
*
|
||||
*/
|
||||
public interface Status {
|
||||
interface Status {
|
||||
/**
|
||||
* HTTP Status-Code 200: OK.
|
||||
*/
|
||||
public static final int HTTP_OK = 200;
|
||||
int HTTP_OK = 200;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 201: Created.
|
||||
*/
|
||||
public static final int HTTP_CREATED = 201;
|
||||
int HTTP_CREATED = 201;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 202: Accepted.
|
||||
*/
|
||||
public static final int HTTP_ACCEPTED = 202;
|
||||
int HTTP_ACCEPTED = 202;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public static final int HTTP_NO_CONTENT = 204;
|
||||
int HTTP_NO_CONTENT = 204;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 205: Reset Content.
|
||||
*/
|
||||
public static final int HTTP_RESET = 205;
|
||||
int HTTP_RESET = 205;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 206: Partial Content.
|
||||
*/
|
||||
public static final int HTTP_PARTIAL = 206;
|
||||
int HTTP_PARTIAL = 206;
|
||||
|
||||
/* 3XX: relocation/redirect */
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public static final int HTTP_MOVED_PERM = 301;
|
||||
int HTTP_MOVED_PERM = 301;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public static final int HTTP_SEE_OTHER = 303;
|
||||
int HTTP_SEE_OTHER = 303;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public static final int HTTP_USE_PROXY = 305;
|
||||
int HTTP_USE_PROXY = 305;
|
||||
|
||||
/* 4XX: client error */
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 400: Bad Request.
|
||||
*/
|
||||
public static final int HTTP_BAD_REQUEST = 400;
|
||||
int HTTP_BAD_REQUEST = 400;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 401: Unauthorized.
|
||||
*/
|
||||
public static final int HTTP_UNAUTHORIZED = 401;
|
||||
int HTTP_UNAUTHORIZED = 401;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 402: Payment Required.
|
||||
*/
|
||||
public static final int HTTP_PAYMENT_REQUIRED = 402;
|
||||
int HTTP_PAYMENT_REQUIRED = 402;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 403: Forbidden.
|
||||
*/
|
||||
public static final int HTTP_FORBIDDEN = 403;
|
||||
int HTTP_FORBIDDEN = 403;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public static final int HTTP_BAD_METHOD = 405;
|
||||
int HTTP_BAD_METHOD = 405;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public static final int HTTP_PROXY_AUTH = 407;
|
||||
int HTTP_PROXY_AUTH = 407;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public static final int HTTP_CONFLICT = 409;
|
||||
int HTTP_CONFLICT = 409;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 410: Gone.
|
||||
*/
|
||||
public static final int HTTP_GONE = 410;
|
||||
int HTTP_GONE = 410;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public static final int HTTP_PRECON_FAILED = 412;
|
||||
int HTTP_PRECON_FAILED = 412;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public static final int HTTP_REQ_TOO_LONG = 414;
|
||||
int HTTP_REQ_TOO_LONG = 414;
|
||||
|
||||
/**
|
||||
* HTTP Status-Code 415: Unsupported Media Type.
|
||||
*/
|
||||
public static final int HTTP_UNSUPPORTED_TYPE = 415;
|
||||
int HTTP_UNSUPPORTED_TYPE = 415;
|
||||
|
||||
/* 5XX: 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.
|
||||
*/
|
||||
public static final int HTTP_NOT_IMPLEMENTED = 501;
|
||||
int HTTP_NOT_IMPLEMENTED = 501;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public static final int HTTP_UNAVAILABLE = 503;
|
||||
int HTTP_UNAVAILABLE = 503;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public static final int HTTP_VERSION = 505;
|
||||
int HTTP_VERSION = 505;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public enum SoapProtocol {
|
||||
*
|
||||
* @param value {@link SOAPConstants} 中的协议版本值
|
||||
*/
|
||||
private SoapProtocol(String value) {
|
||||
SoapProtocol(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ import cn.hutool.core.util.StrUtil;
|
||||
* 内部JSON工具类,仅用于JSON内部使用
|
||||
*
|
||||
* @author Looly
|
||||
*
|
||||
*/
|
||||
final class InternalJSONUtil {
|
||||
|
||||
@@ -35,10 +34,10 @@ final class InternalJSONUtil {
|
||||
* @param indent 缩进空格数
|
||||
* @param config 配置项
|
||||
* @return Writer
|
||||
* @throws JSONException
|
||||
* @throws IOException
|
||||
* @throws JSONException JSON异常
|
||||
* @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) {
|
||||
writer.write(JSONNull.NULL.toString());
|
||||
} else if (value instanceof JSON) {
|
||||
@@ -71,11 +70,11 @@ final class InternalJSONUtil {
|
||||
/**
|
||||
* 缩进,使用空格符
|
||||
*
|
||||
* @param writer
|
||||
* @param indent
|
||||
* @throws IOException
|
||||
* @param writer writer
|
||||
* @param indent 随进空格数
|
||||
* @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) {
|
||||
writer.write(CharUtil.SPACE);
|
||||
}
|
||||
@@ -215,10 +214,9 @@ final class InternalJSONUtil {
|
||||
* @since 4.3.1
|
||||
*/
|
||||
protected static boolean defaultIgnoreNullValue(Object obj) {
|
||||
if(obj instanceof CharSequence || obj instanceof JSONTokener || obj instanceof Map) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return (false == (obj instanceof CharSequence))//
|
||||
&& (false == (obj instanceof JSONTokener))//
|
||||
&& (false == (obj instanceof Map));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -230,12 +228,12 @@ final class InternalJSONUtil {
|
||||
*/
|
||||
private static String formatDate(Object dateObj, String format) {
|
||||
if (StrUtil.isNotBlank(format)) {
|
||||
final Date date = (dateObj instanceof Date) ? (Date)dateObj : ((Calendar)dateObj).getTime();
|
||||
final Date date = (dateObj instanceof Date) ? (Date) dateObj : ((Calendar) dateObj).getTime();
|
||||
//用户定义了日期格式
|
||||
return JSONUtil.quote(DateUtil.format(date, format));
|
||||
}
|
||||
|
||||
//默认使用时间戳
|
||||
return String.valueOf((dateObj instanceof Date) ? ((Date)dateObj).getTime() : ((Calendar)dateObj).getTimeInMillis());
|
||||
return String.valueOf((dateObj instanceof Date) ? ((Date) dateObj).getTime() : ((Calendar) dateObj).getTimeInMillis());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public interface JSON extends Cloneable, Serializable{
|
||||
* @see BeanPath#get(Object)
|
||||
* @since 4.0.6
|
||||
*/
|
||||
public Object getByPath(String expression);
|
||||
Object getByPath(String expression);
|
||||
|
||||
/**
|
||||
* 设置表达式指定位置(或filed对应)的值<br>
|
||||
@@ -84,7 +84,7 @@ public interface JSON extends Cloneable, Serializable{
|
||||
* @see BeanPath#get(Object)
|
||||
* @since 4.0.6
|
||||
*/
|
||||
public <T> T getByPath(String expression, Class<T> resultType);
|
||||
<T> T getByPath(String expression, Class<T> resultType);
|
||||
|
||||
/**
|
||||
* 将JSON内容写入Writer,无缩进<br>
|
||||
@@ -94,7 +94,7 @@ public interface JSON extends Cloneable, Serializable{
|
||||
* @return Writer
|
||||
* @throws JSONException JSON相关异常
|
||||
*/
|
||||
public Writer write(Writer writer) throws JSONException;
|
||||
Writer write(Writer writer) throws JSONException;
|
||||
|
||||
/**
|
||||
* 将JSON内容写入Writer<br>
|
||||
@@ -106,7 +106,7 @@ public interface JSON extends Cloneable, Serializable{
|
||||
* @return Writer
|
||||
* @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字符串
|
||||
@@ -115,7 +115,7 @@ public interface JSON extends Cloneable, Serializable{
|
||||
* @return JSON字符串
|
||||
* @throws JSONException JSON相关异常
|
||||
*/
|
||||
public String toJSONString(int indentFactor) throws JSONException;
|
||||
String toJSONString(int indentFactor) throws JSONException;
|
||||
|
||||
/**
|
||||
* 格式化打印JSON,缩进为4个空格
|
||||
@@ -124,5 +124,5 @@ public interface JSON extends Cloneable, Serializable{
|
||||
* @throws JSONException 包含非法数抛出此异常
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public String toStringPretty() throws JSONException;
|
||||
String toStringPretty() throws JSONException;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public class JSONArray extends JSONGetter<Integer> implements JSON, List<Object>
|
||||
* @since 4.1.19
|
||||
*/
|
||||
public JSONArray(int initialCapacity, JSONConfig config) {
|
||||
this.rawList = new ArrayList<Object>(initialCapacity);
|
||||
this.rawList = new ArrayList<>(initialCapacity);
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@@ -107,9 +107,7 @@ public class JSONArray extends JSONGetter<Integer> implements JSON, List<Object>
|
||||
*/
|
||||
public JSONArray(Collection<Object> list) {
|
||||
this(list.size());
|
||||
for (Object o : list) {
|
||||
this.add(o);
|
||||
}
|
||||
this.addAll(list);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -311,13 +309,10 @@ public class JSONArray extends JSONGetter<Integer> implements JSON, List<Object>
|
||||
}
|
||||
final JSONArray other = (JSONArray) obj;
|
||||
if (rawList == null) {
|
||||
if (other.rawList != null) {
|
||||
return false;
|
||||
return other.rawList == null;
|
||||
} else {
|
||||
return rawList.equals(other.rawList);
|
||||
}
|
||||
} else if (!rawList.equals(other.rawList)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -382,7 +377,7 @@ public class JSONArray extends JSONGetter<Integer> implements JSON, List<Object>
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends Object> c) {
|
||||
public boolean addAll(Collection<?> c) {
|
||||
if (CollUtil.isEmpty(c)) {
|
||||
return false;
|
||||
}
|
||||
@@ -393,7 +388,7 @@ public class JSONArray extends JSONGetter<Integer> implements JSON, List<Object>
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(int index, Collection<? extends Object> c) {
|
||||
public boolean addAll(int index, Collection<?> c) {
|
||||
if (CollUtil.isEmpty(c)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -441,8 +441,8 @@ public class JSONObject extends JSONGetter<String> implements JSON, Map<String,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(Map<? extends String, ? extends Object> m) {
|
||||
for (Entry<? extends String, ? extends Object> entry : m.entrySet()) {
|
||||
public void putAll(Map<? extends String, ?> m) {
|
||||
for (Entry<? extends String, ?> entry : m.entrySet()) {
|
||||
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;
|
||||
if (rawHashMap == null) {
|
||||
if (other.rawHashMap != null) {
|
||||
return false;
|
||||
return other.rawHashMap == null;
|
||||
} 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);
|
||||
writer.write(JSONUtil.quote(entry.getKey().toString()));
|
||||
writer.write(JSONUtil.quote(entry.getKey()));
|
||||
writer.write(CharUtil.COLON);
|
||||
if (indentFactor > 0) {
|
||||
// 冒号后的空格
|
||||
@@ -682,7 +679,6 @@ public class JSONObject extends JSONGetter<String> implements JSON, Map<String,
|
||||
* Bean对象转Map
|
||||
*
|
||||
* @param bean Bean对象
|
||||
* @param ignoreNullValue 是否忽略空值
|
||||
*/
|
||||
private void populateMap(Object bean) {
|
||||
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());
|
||||
if(null != serializer && serializer instanceof JSONObjectSerializer) {
|
||||
if(serializer instanceof JSONObjectSerializer) {
|
||||
// 自定义序列化
|
||||
serializer.serialize(this, source);
|
||||
} else if (source instanceof Map) {
|
||||
|
||||
@@ -12,9 +12,9 @@ import cn.hutool.core.util.StrUtil;
|
||||
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字符串。
|
||||
@@ -23,13 +23,13 @@ public class JSONStrFormater {
|
||||
* @return 格式化的JSON字符串。
|
||||
*/
|
||||
public static String format(String json) {
|
||||
final StringBuffer result = new StringBuffer();
|
||||
final StringBuilder result = new StringBuilder();
|
||||
|
||||
Character wrapChar = null;
|
||||
boolean isEscapeMode = false;
|
||||
int length = json.length();
|
||||
int number = 0;
|
||||
char key = 0;
|
||||
char key;
|
||||
for (int i = 0; i < length; i++) {
|
||||
key = json.charAt(i);
|
||||
|
||||
|
||||
@@ -14,5 +14,5 @@ public interface JSONString {
|
||||
*
|
||||
* @return JSON字符串
|
||||
*/
|
||||
public String toJSONString();
|
||||
String toJSONString();
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ public final class JSONUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
JSON json = null;
|
||||
JSON json;
|
||||
if (obj instanceof JSON) {
|
||||
json = (JSON) obj;
|
||||
} else if (obj instanceof String) {
|
||||
@@ -648,9 +648,6 @@ public final class JSONUtil {
|
||||
if (object instanceof Date || object instanceof Calendar) {
|
||||
return object;
|
||||
}
|
||||
if (object instanceof Calendar) {
|
||||
return ((Calendar) object).getTimeInMillis();
|
||||
}
|
||||
// 枚举类保存其字符串形式(4.0.2新增)
|
||||
if (object instanceof Enum) {
|
||||
return object.toString();
|
||||
|
||||
@@ -79,7 +79,6 @@ public class JSONArrayTest {
|
||||
List<Exam> list = array.toList(Exam.class);
|
||||
Assert.assertFalse(list.isEmpty());
|
||||
Assert.assertEquals(Exam.class, list.get(0).getClass());
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -123,7 +122,7 @@ public class JSONArrayTest {
|
||||
JSONArray array = JSONUtil.parseArray(jsonStr);
|
||||
|
||||
Exam[] list = array.toArray(new Exam[0]);
|
||||
Assert.assertFalse(0 == list.length);
|
||||
Assert.assertNotEquals(0, list.length);
|
||||
Assert.assertEquals(Exam.class, list[0].getClass());
|
||||
}
|
||||
|
||||
@@ -136,7 +135,7 @@ public class JSONArrayTest {
|
||||
JSONArray ja = JSONUtil.parseArray(json);
|
||||
|
||||
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("bvalue", list.get(1).getBkey());
|
||||
}
|
||||
@@ -175,7 +174,7 @@ public class JSONArrayTest {
|
||||
return map;
|
||||
}
|
||||
|
||||
class User {
|
||||
static class User {
|
||||
private Integer id;
|
||||
private String name;
|
||||
|
||||
|
||||
@@ -354,7 +354,7 @@ public class JSONObjectTest {
|
||||
Assert.assertEquals("defaultBBB", bbb);
|
||||
}
|
||||
|
||||
public static enum TestEnum {
|
||||
public enum TestEnum {
|
||||
TYPE_A, TYPE_B
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public class EnvSettingInfo {
|
||||
private String hubRemoteUrl;
|
||||
|
||||
private String reportFolder = "/report";
|
||||
private String screenshotFolder = "/screenshot";;
|
||||
private String screenshotFolder = "/screenshot";
|
||||
|
||||
private String elementFolder = "/config/element/";
|
||||
private String suiteFolder = "/config/suite/";
|
||||
|
||||
@@ -18,7 +18,7 @@ public interface Log extends TraceLog, DebugLog, InfoLog, WarnLog, ErrorLog {
|
||||
/**
|
||||
* @return 日志对象的Name
|
||||
*/
|
||||
public String getName();
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* 是否开启指定日志
|
||||
|
||||
@@ -10,18 +10,19 @@ import cn.hutool.log.level.Level;
|
||||
|
||||
/**
|
||||
* 利用System.out.println()打印日志
|
||||
* @author Looly
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
public class ConsoleLog extends AbstractLog {
|
||||
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 String name;
|
||||
|
||||
//------------------------------------------------------------------------- Constructor
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
@@ -47,6 +48,7 @@ public class ConsoleLog extends AbstractLog {
|
||||
|
||||
/**
|
||||
* 设置自定义的日志显示级别
|
||||
*
|
||||
* @param customLevel 自定义级别
|
||||
* @since 4.1.10
|
||||
*/
|
||||
@@ -65,6 +67,7 @@ public class ConsoleLog extends AbstractLog {
|
||||
public void trace(String fqcn, Throwable t, String format, Object... arguments) {
|
||||
log(fqcn, Level.TRACE, t, format, arguments);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------- Debug
|
||||
@Override
|
||||
public boolean isDebugEnabled() {
|
||||
@@ -113,7 +116,7 @@ public class ConsoleLog extends AbstractLog {
|
||||
@Override
|
||||
public void log(String fqcn, Level level, Throwable t, String format, Object... arguments) {
|
||||
// fqcn 无效
|
||||
if(false == isEnabled(level)){
|
||||
if (false == isEnabled(level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -126,9 +129,9 @@ public class ConsoleLog extends AbstractLog {
|
||||
final String logMsg = StrUtil.format(logFormat, dict);
|
||||
|
||||
//WARN以上级别打印至System.err
|
||||
if(level.ordinal() >= Level.WARN.ordinal()){
|
||||
if (level.ordinal() >= Level.WARN.ordinal()) {
|
||||
Console.error(t, logMsg);
|
||||
}else{
|
||||
} else {
|
||||
Console.log(t, logMsg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,5 +14,5 @@ public interface CellEditor {
|
||||
* @param value 单元格值
|
||||
* @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
Reference in New Issue
Block a user