mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
eec404f875
commit
106ea5a759
@ -6,8 +6,11 @@
|
||||
## 5.0.7
|
||||
|
||||
### 新特性
|
||||
* 【core 】 解决NumberUtil导致的ambiguous问题(issue#630@Github)
|
||||
* 【core 】 BeanUtil.isEmpty()忽略字段支持,增加isNotEmpty(issue#629@Github)
|
||||
|
||||
### Bug修复
|
||||
* 【extra】 修复SFTP.upload上传失败的问题
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -292,7 +292,7 @@ public class BeanUtil {
|
||||
/**
|
||||
* 解析Bean中的属性值
|
||||
*
|
||||
* @param <T> 属性值类型
|
||||
* @param <T> 属性值类型
|
||||
* @param bean Bean对象,支持Map、List、Collection、Array
|
||||
* @param expression 表达式,例如:person.friend[5].name
|
||||
* @return Bean属性值
|
||||
@ -676,17 +676,31 @@ public class BeanUtil {
|
||||
return bean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断Bean是否为非空对象,非空对象表示本身不为<code>null</code>或者含有非<code>null</code>属性的对象
|
||||
*
|
||||
* @param bean Bean对象
|
||||
* @param ignoreFiledNames 忽略检查的字段名
|
||||
* @return 是否为空,<code>true</code> - 空 / <code>false</code> - 非空
|
||||
* @since 5.0.7
|
||||
*/
|
||||
public static boolean isNotEmpty(Object bean, String... ignoreFiledNames) {
|
||||
return false == isEmpty(bean, ignoreFiledNames);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断Bean是否为空对象,空对象表示本身为<code>null</code>或者所有属性都为<code>null</code>
|
||||
*
|
||||
* @param bean Bean对象
|
||||
* @param bean Bean对象
|
||||
* @param ignoreFiledNames 忽略检查的字段名
|
||||
* @return 是否为空,<code>true</code> - 空 / <code>false</code> - 非空
|
||||
* @since 4.1.10
|
||||
*/
|
||||
public static boolean isEmpty(Object bean) {
|
||||
public static boolean isEmpty(Object bean, String... ignoreFiledNames) {
|
||||
if (null != bean) {
|
||||
for (Field field : ReflectUtil.getFields(bean.getClass())) {
|
||||
if (null != ReflectUtil.getFieldValue(bean, field)) {
|
||||
if ((false == ArrayUtil.contains(ignoreFiledNames, field.getName()))
|
||||
&& null != ReflectUtil.getFieldValue(bean, field)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -698,16 +712,18 @@ public class BeanUtil {
|
||||
* 判断Bean是否包含值为<code>null</code>的属性<br>
|
||||
* 对象本身为<code>null</code>也返回true
|
||||
*
|
||||
* @param bean Bean对象
|
||||
* @param bean Bean对象
|
||||
* @param ignoreFiledNames 忽略检查的字段名
|
||||
* @return 是否包含值为<code>null</code>的属性,<code>true</code> - 包含 / <code>false</code> - 不包含
|
||||
* @since 4.1.10
|
||||
*/
|
||||
public static boolean hasNullField(Object bean) {
|
||||
public static boolean hasNullField(Object bean, String... ignoreFiledNames) {
|
||||
if (null == bean) {
|
||||
return true;
|
||||
}
|
||||
for (Field field : ReflectUtil.getFields(bean.getClass())) {
|
||||
if (null == ReflectUtil.getFieldValue(bean, field)) {
|
||||
if ((false == ArrayUtil.contains(ignoreFiledNames, field.getName()))//
|
||||
&& null == ReflectUtil.getFieldValue(bean, field)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -477,7 +477,7 @@ public class ArrayUtil {
|
||||
* @return 新数组
|
||||
* @since 4.0.8
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({"unchecked", "SuspiciousSystemArraycopy"})
|
||||
public static <T> Object insert(Object array, int index, T... newElements) {
|
||||
if (isEmpty(newElements)) {
|
||||
return array;
|
||||
@ -541,6 +541,7 @@ public class ArrayUtil {
|
||||
final int length = length(array);
|
||||
final Object newArray = Array.newInstance(array.getClass().getComponentType(), newSize);
|
||||
if (newSize > 0 && isNotEmpty(array)) {
|
||||
//noinspection SuspiciousSystemArraycopy
|
||||
System.arraycopy(array, 0, newArray, 0, Math.min(length, newSize));
|
||||
}
|
||||
return newArray;
|
||||
@ -656,6 +657,7 @@ public class ArrayUtil {
|
||||
* @since 3.0.6
|
||||
*/
|
||||
public static Object copy(Object src, int srcPos, Object dest, int destPos, int length) {
|
||||
//noinspection SuspiciousSystemArraycopy
|
||||
System.arraycopy(src, srcPos, dest, destPos, length);
|
||||
return dest;
|
||||
}
|
||||
@ -671,6 +673,7 @@ public class ArrayUtil {
|
||||
* @since 3.0.6
|
||||
*/
|
||||
public static Object copy(Object src, Object dest, int length) {
|
||||
//noinspection SuspiciousSystemArraycopy
|
||||
System.arraycopy(src, 0, dest, 0, length);
|
||||
return dest;
|
||||
}
|
||||
@ -1477,7 +1480,7 @@ public class ArrayUtil {
|
||||
|
||||
final Integer[] array = new Integer[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
array[i] = Integer.valueOf(values[i]);
|
||||
array[i] = values[i];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
@ -1499,7 +1502,7 @@ public class ArrayUtil {
|
||||
|
||||
final int[] array = new int[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
array[i] = values[i].intValue();
|
||||
array[i] = values[i];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
@ -1521,7 +1524,7 @@ public class ArrayUtil {
|
||||
|
||||
final Long[] array = new Long[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
array[i] = Long.valueOf(values[i]);
|
||||
array[i] = values[i];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
@ -1543,7 +1546,7 @@ public class ArrayUtil {
|
||||
|
||||
final long[] array = new long[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
array[i] = values[i].longValue();
|
||||
array[i] = values[i];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
@ -1565,7 +1568,7 @@ public class ArrayUtil {
|
||||
|
||||
final Character[] array = new Character[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
array[i] = Character.valueOf(values[i]);
|
||||
array[i] = values[i];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
@ -1587,7 +1590,7 @@ public class ArrayUtil {
|
||||
|
||||
char[] array = new char[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
array[i] = values[i].charValue();
|
||||
array[i] = values[i];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
@ -1609,7 +1612,7 @@ public class ArrayUtil {
|
||||
|
||||
final Byte[] array = new Byte[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
array[i] = Byte.valueOf(values[i]);
|
||||
array[i] = values[i];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
@ -1631,7 +1634,7 @@ public class ArrayUtil {
|
||||
|
||||
final byte[] array = new byte[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
array[i] = values[i].byteValue();
|
||||
array[i] = ObjectUtil.defaultIfNull(values[i], (byte)0);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
@ -1653,7 +1656,7 @@ public class ArrayUtil {
|
||||
|
||||
final Short[] array = new Short[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
array[i] = Short.valueOf(values[i]);
|
||||
array[i] = values[i];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
@ -1675,7 +1678,7 @@ public class ArrayUtil {
|
||||
|
||||
final short[] array = new short[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
array[i] = values[i].shortValue();
|
||||
array[i] = ObjectUtil.defaultIfNull(values[i], (short)0);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
@ -1697,7 +1700,7 @@ public class ArrayUtil {
|
||||
|
||||
final Float[] array = new Float[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
array[i] = Float.valueOf(values[i]);
|
||||
array[i] = values[i];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
@ -1719,7 +1722,7 @@ public class ArrayUtil {
|
||||
|
||||
final float[] array = new float[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
array[i] = values[i].floatValue();
|
||||
array[i] = ObjectUtil.defaultIfNull(values[i], 0F);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
@ -1741,7 +1744,7 @@ public class ArrayUtil {
|
||||
|
||||
final Double[] array = new Double[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
array[i] = Double.valueOf(values[i]);
|
||||
array[i] = values[i];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
@ -1763,7 +1766,7 @@ public class ArrayUtil {
|
||||
|
||||
final double[] array = new double[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
array[i] = values[i].doubleValue();
|
||||
array[i] = ObjectUtil.defaultIfNull(values[i], 0D);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
@ -1785,7 +1788,7 @@ public class ArrayUtil {
|
||||
|
||||
final Boolean[] array = new Boolean[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
array[i] = Boolean.valueOf(values[i]);
|
||||
array[i] = values[i];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
@ -1807,7 +1810,7 @@ public class ArrayUtil {
|
||||
|
||||
final boolean[] array = new boolean[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
array[i] = values[i].booleanValue();
|
||||
array[i] = ObjectUtil.defaultIfNull(values[i], false);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
@ -2841,6 +2844,7 @@ public class ArrayUtil {
|
||||
* @throws IllegalArgumentException 参数对象不为数组对象
|
||||
* @since 3.0.8
|
||||
*/
|
||||
@SuppressWarnings("SuspiciousSystemArraycopy")
|
||||
public static Object remove(Object array, int index) throws IllegalArgumentException {
|
||||
if (null == array) {
|
||||
return null;
|
||||
@ -3339,9 +3343,9 @@ public class ArrayUtil {
|
||||
throw new IllegalArgumentException("Number array must not empty !");
|
||||
}
|
||||
T min = numberArray[0];
|
||||
for (int i = 0; i < numberArray.length; i++) {
|
||||
if (ObjectUtil.compare(min, numberArray[i]) > 0) {
|
||||
min = numberArray[i];
|
||||
for (T t : numberArray) {
|
||||
if (ObjectUtil.compare(min, t) > 0) {
|
||||
min = t;
|
||||
}
|
||||
}
|
||||
return min;
|
||||
@ -3359,7 +3363,7 @@ public class ArrayUtil {
|
||||
throw new IllegalArgumentException("Number array must not empty !");
|
||||
}
|
||||
long min = numberArray[0];
|
||||
for (int i = 0; i < numberArray.length; i++) {
|
||||
for (int i = 1; i < numberArray.length; i++) {
|
||||
if (min > numberArray[i]) {
|
||||
min = numberArray[i];
|
||||
}
|
||||
@ -3379,7 +3383,7 @@ public class ArrayUtil {
|
||||
throw new IllegalArgumentException("Number array must not empty !");
|
||||
}
|
||||
int min = numberArray[0];
|
||||
for (int i = 0; i < numberArray.length; i++) {
|
||||
for (int i = 1; i < numberArray.length; i++) {
|
||||
if (min > numberArray[i]) {
|
||||
min = numberArray[i];
|
||||
}
|
||||
@ -3399,7 +3403,7 @@ public class ArrayUtil {
|
||||
throw new IllegalArgumentException("Number array must not empty !");
|
||||
}
|
||||
short min = numberArray[0];
|
||||
for (int i = 0; i < numberArray.length; i++) {
|
||||
for (int i = 1; i < numberArray.length; i++) {
|
||||
if (min > numberArray[i]) {
|
||||
min = numberArray[i];
|
||||
}
|
||||
@ -3419,7 +3423,7 @@ public class ArrayUtil {
|
||||
throw new IllegalArgumentException("Number array must not empty !");
|
||||
}
|
||||
char min = numberArray[0];
|
||||
for (int i = 0; i < numberArray.length; i++) {
|
||||
for (int i = 1; i < numberArray.length; i++) {
|
||||
if (min > numberArray[i]) {
|
||||
min = numberArray[i];
|
||||
}
|
||||
@ -3439,7 +3443,7 @@ public class ArrayUtil {
|
||||
throw new IllegalArgumentException("Number array must not empty !");
|
||||
}
|
||||
byte min = numberArray[0];
|
||||
for (int i = 0; i < numberArray.length; i++) {
|
||||
for (int i = 1; i < numberArray.length; i++) {
|
||||
if (min > numberArray[i]) {
|
||||
min = numberArray[i];
|
||||
}
|
||||
@ -3459,7 +3463,7 @@ public class ArrayUtil {
|
||||
throw new IllegalArgumentException("Number array must not empty !");
|
||||
}
|
||||
double min = numberArray[0];
|
||||
for (int i = 0; i < numberArray.length; i++) {
|
||||
for (int i = 1; i < numberArray.length; i++) {
|
||||
if (min > numberArray[i]) {
|
||||
min = numberArray[i];
|
||||
}
|
||||
@ -3479,7 +3483,7 @@ public class ArrayUtil {
|
||||
throw new IllegalArgumentException("Number array must not empty !");
|
||||
}
|
||||
float min = numberArray[0];
|
||||
for (int i = 0; i < numberArray.length; i++) {
|
||||
for (int i = 1; i < numberArray.length; i++) {
|
||||
if (min > numberArray[i]) {
|
||||
min = numberArray[i];
|
||||
}
|
||||
@ -3500,7 +3504,7 @@ public class ArrayUtil {
|
||||
throw new IllegalArgumentException("Number array must not empty !");
|
||||
}
|
||||
T max = numberArray[0];
|
||||
for (int i = 0; i < numberArray.length; i++) {
|
||||
for (int i = 1; i < numberArray.length; i++) {
|
||||
if (ObjectUtil.compare(max, numberArray[i]) < 0) {
|
||||
max = numberArray[i];
|
||||
}
|
||||
@ -3520,7 +3524,7 @@ public class ArrayUtil {
|
||||
throw new IllegalArgumentException("Number array must not empty !");
|
||||
}
|
||||
long max = numberArray[0];
|
||||
for (int i = 0; i < numberArray.length; i++) {
|
||||
for (int i = 1; i < numberArray.length; i++) {
|
||||
if (max < numberArray[i]) {
|
||||
max = numberArray[i];
|
||||
}
|
||||
@ -3540,7 +3544,7 @@ public class ArrayUtil {
|
||||
throw new IllegalArgumentException("Number array must not empty !");
|
||||
}
|
||||
int max = numberArray[0];
|
||||
for (int i = 0; i < numberArray.length; i++) {
|
||||
for (int i = 1; i < numberArray.length; i++) {
|
||||
if (max < numberArray[i]) {
|
||||
max = numberArray[i];
|
||||
}
|
||||
@ -3560,7 +3564,7 @@ public class ArrayUtil {
|
||||
throw new IllegalArgumentException("Number array must not empty !");
|
||||
}
|
||||
short max = numberArray[0];
|
||||
for (int i = 0; i < numberArray.length; i++) {
|
||||
for (int i = 1; i < numberArray.length; i++) {
|
||||
if (max < numberArray[i]) {
|
||||
max = numberArray[i];
|
||||
}
|
||||
@ -3580,7 +3584,7 @@ public class ArrayUtil {
|
||||
throw new IllegalArgumentException("Number array must not empty !");
|
||||
}
|
||||
char max = numberArray[0];
|
||||
for (int i = 0; i < numberArray.length; i++) {
|
||||
for (int i = 1; i < numberArray.length; i++) {
|
||||
if (max < numberArray[i]) {
|
||||
max = numberArray[i];
|
||||
}
|
||||
@ -3600,7 +3604,7 @@ public class ArrayUtil {
|
||||
throw new IllegalArgumentException("Number array must not empty !");
|
||||
}
|
||||
byte max = numberArray[0];
|
||||
for (int i = 0; i < numberArray.length; i++) {
|
||||
for (int i = 1; i < numberArray.length; i++) {
|
||||
if (max < numberArray[i]) {
|
||||
max = numberArray[i];
|
||||
}
|
||||
@ -3620,7 +3624,7 @@ public class ArrayUtil {
|
||||
throw new IllegalArgumentException("Number array must not empty !");
|
||||
}
|
||||
double max = numberArray[0];
|
||||
for (int i = 0; i < numberArray.length; i++) {
|
||||
for (int i = 1; i < numberArray.length; i++) {
|
||||
if (max < numberArray[i]) {
|
||||
max = numberArray[i];
|
||||
}
|
||||
@ -3640,7 +3644,7 @@ public class ArrayUtil {
|
||||
throw new IllegalArgumentException("Number array must not empty !");
|
||||
}
|
||||
float max = numberArray[0];
|
||||
for (int i = 0; i < numberArray.length; i++) {
|
||||
for (int i = 1; i < numberArray.length; i++) {
|
||||
if (max < numberArray[i]) {
|
||||
max = numberArray[i];
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import cn.hutool.core.lang.Validator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 身份证相关工具类<br>
|
||||
@ -323,10 +324,10 @@ public class IdcardUtil {
|
||||
final char[] chars = mid.toCharArray();
|
||||
int iflag = 8;
|
||||
for (char c : chars) {
|
||||
sum += Integer.valueOf(String.valueOf(c)) * iflag;
|
||||
sum += Integer.parseInt(String.valueOf(c)) * iflag;
|
||||
iflag--;
|
||||
}
|
||||
return (sum % 10 == 0 ? 0 : (10 - sum % 10)) == Integer.valueOf(end);
|
||||
return (sum % 10 == 0 ? 0 : (10 - sum % 10)) == Integer.parseInt(end);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -360,7 +361,7 @@ public class IdcardUtil {
|
||||
char[] chars = mid.toCharArray();
|
||||
int iflag = 7;
|
||||
for (char c : chars) {
|
||||
sum = sum + Integer.valueOf(String.valueOf(c)) * iflag;
|
||||
sum = sum + Integer.parseInt(String.valueOf(c)) * iflag;
|
||||
iflag--;
|
||||
}
|
||||
if ("A".equals(end.toUpperCase())) {
|
||||
@ -389,13 +390,15 @@ public class IdcardUtil {
|
||||
* @return 生日(yyyyMMdd)
|
||||
*/
|
||||
public static String getBirth(String idCard) {
|
||||
Assert.notBlank(idCard, "id card must be not blank!");
|
||||
final int len = idCard.length();
|
||||
if (len < CHINA_ID_MIN_LENGTH) {
|
||||
return null;
|
||||
} else if (len == CHINA_ID_MIN_LENGTH) {
|
||||
idCard = convert15To18(idCard);
|
||||
}
|
||||
return idCard.substring(6, 14);
|
||||
|
||||
return Objects.requireNonNull(idCard).substring(6, 14);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -444,7 +447,7 @@ public class IdcardUtil {
|
||||
} else if (len == CHINA_ID_MIN_LENGTH) {
|
||||
idCard = convert15To18(idCard);
|
||||
}
|
||||
return Short.valueOf(idCard.substring(6, 10));
|
||||
return Short.valueOf(Objects.requireNonNull(idCard).substring(6, 10));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -460,7 +463,7 @@ public class IdcardUtil {
|
||||
} else if (len == CHINA_ID_MIN_LENGTH) {
|
||||
idCard = convert15To18(idCard);
|
||||
}
|
||||
return Short.valueOf(idCard.substring(10, 12));
|
||||
return Short.valueOf(Objects.requireNonNull(idCard).substring(10, 12));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -476,7 +479,7 @@ public class IdcardUtil {
|
||||
} else if (len == CHINA_ID_MIN_LENGTH) {
|
||||
idCard = convert15To18(idCard);
|
||||
}
|
||||
return Short.valueOf(idCard.substring(12, 14));
|
||||
return Short.valueOf(Objects.requireNonNull(idCard).substring(12, 14));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -495,7 +498,7 @@ public class IdcardUtil {
|
||||
if (len == CHINA_ID_MIN_LENGTH) {
|
||||
idCard = convert15To18(idCard);
|
||||
}
|
||||
char sCardChar = idCard.charAt(16);
|
||||
char sCardChar = Objects.requireNonNull(idCard).charAt(16);
|
||||
return (sCardChar % 2 != 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
@ -586,7 +589,7 @@ public class IdcardUtil {
|
||||
int iSum = 0;
|
||||
if (power.length == iArr.length) {
|
||||
for (int i = 0; i < iArr.length; i++) {
|
||||
iSum += Integer.valueOf(String.valueOf(iArr[i])) * power[i];
|
||||
iSum += Integer.parseInt(String.valueOf(iArr[i])) * power[i];
|
||||
}
|
||||
}
|
||||
return iSum;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -184,6 +184,7 @@ public class ObjectUtil {
|
||||
* @return 是否为null
|
||||
*/
|
||||
public static boolean isNull(Object obj) {
|
||||
//noinspection ConstantConditions
|
||||
return null == obj || obj.equals(null);
|
||||
}
|
||||
|
||||
@ -194,6 +195,7 @@ public class ObjectUtil {
|
||||
* @return 是否为null
|
||||
*/
|
||||
public static boolean isNotNull(Object obj) {
|
||||
//noinspection ConstantConditions
|
||||
return null != obj && false == obj.equals(null);
|
||||
}
|
||||
|
||||
|
@ -191,13 +191,13 @@ public class NumberUtilTest {
|
||||
|
||||
@Test
|
||||
public void maxTest() {
|
||||
int max = NumberUtil.max(new int[]{5,4,3,6,1});
|
||||
int max = NumberUtil.max(5,4,3,6,1);
|
||||
Assert.assertEquals(6, max);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void minTest() {
|
||||
int min = NumberUtil.min(new int[]{5,4,3,6,1});
|
||||
int min = NumberUtil.min(5,4,3,6,1);
|
||||
Assert.assertEquals(1, min);
|
||||
}
|
||||
|
||||
|
@ -133,13 +133,14 @@ public abstract class AbstractFtp implements Closeable {
|
||||
}
|
||||
|
||||
/**
|
||||
* 将本地文件上传到目标服务器,目标文件名为destPath,若destPath为目录,则目标文件名将与srcFilePath文件名相同。覆盖模式
|
||||
* 将本地文件上传到目标服务器,目标文件名为destPath,若destPath为目录,则目标文件名将与file文件名相同。
|
||||
* 覆盖模式
|
||||
*
|
||||
* @param srcFilePath 本地文件路径
|
||||
* @param destFile 目标文件
|
||||
* @param destPath 服务端路径,可以为{@code null} 或者相对路径或绝对路径
|
||||
* @param file 需要上传的文件
|
||||
* @return 是否成功
|
||||
*/
|
||||
public abstract boolean upload(String srcFilePath, File destFile);
|
||||
public abstract boolean upload(String destPath, File file);
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
|
@ -364,14 +364,14 @@ public class Ftp extends AbstractFtp {
|
||||
* 3. path为绝对路径则上传到此路径
|
||||
* </pre>
|
||||
*
|
||||
* @param path 服务端路径,可以为{@code null} 或者相对路径或绝对路径
|
||||
* @param destPath 服务端路径,可以为{@code null} 或者相对路径或绝对路径
|
||||
* @param file 文件
|
||||
* @return 是否上传成功
|
||||
*/
|
||||
@Override
|
||||
public boolean upload(String path, File file) {
|
||||
public boolean upload(String destPath, File file) {
|
||||
Assert.notNull(file, "file to upload is null !");
|
||||
return upload(path, file.getName(), file);
|
||||
return upload(destPath, file.getName(), file);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -238,9 +238,6 @@ public class JschUtil {
|
||||
*/
|
||||
public static int openAndBindPortToLocal(Connector sshConn, String remoteHost, int remotePort) throws JschRuntimeException {
|
||||
final Session session = openSession(sshConn.getHost(), sshConn.getPort(), sshConn.getUser(), sshConn.getPassword());
|
||||
if (session == null) {
|
||||
throw new JschRuntimeException("Error to create SSH Session!");
|
||||
}
|
||||
final int localPort = generateLocalPort();
|
||||
bindPort(session, remoteHost, remotePort, localPort);
|
||||
return localPort;
|
||||
@ -359,7 +356,7 @@ public class JschUtil {
|
||||
if (null == charset) {
|
||||
charset = CharsetUtil.CHARSET_UTF_8;
|
||||
}
|
||||
ChannelExec channel = (ChannelExec) openChannel(session, ChannelType.EXEC);
|
||||
final ChannelExec channel = (ChannelExec) openChannel(session, ChannelType.EXEC);
|
||||
channel.setCommand(StrUtil.bytes(cmd, charset));
|
||||
channel.setInputStream(null);
|
||||
channel.setErrStream(errStream);
|
||||
|
@ -1,12 +1,9 @@
|
||||
package cn.hutool.extra.ssh;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Filter;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.ftp.AbstractFtp;
|
||||
import com.jcraft.jsch.ChannelSftp;
|
||||
import com.jcraft.jsch.ChannelSftp.LsEntry;
|
||||
import com.jcraft.jsch.ChannelSftp.LsEntrySelector;
|
||||
@ -14,10 +11,11 @@ import com.jcraft.jsch.Session;
|
||||
import com.jcraft.jsch.SftpException;
|
||||
import com.jcraft.jsch.SftpProgressMonitor;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Filter;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.ftp.AbstractFtp;
|
||||
import java.io.File;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* SFTP是Secure File Transfer Protocol的缩写,安全文件传送协议。可以为传输文件提供一种安全的加密方法。<br>
|
||||
@ -336,8 +334,8 @@ public class Sftp extends AbstractFtp {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean upload(String srcFilePath, File destFile) {
|
||||
put(srcFilePath, FileUtil.getAbsolutePath(destFile));
|
||||
public boolean upload(String destPath, File file) {
|
||||
put(FileUtil.getAbsolutePath(file), destPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,8 @@ public class RuntimeInfo implements Serializable{
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得JVM最大可用内存
|
||||
* @return 最大可用内存
|
||||
* 获得JVM最大内存
|
||||
* @return 最大内存
|
||||
*/
|
||||
public final long getMaxMemory(){
|
||||
return currentRuntime.maxMemory();
|
||||
|
Loading…
x
Reference in New Issue
Block a user