mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-05 13:17:58 +08:00
int to long
This commit is contained in:
parent
d6e8e64bc5
commit
cc43e39515
@ -6,6 +6,9 @@
|
||||
# 5.5.3 (2020-12-02)
|
||||
|
||||
### 新特性
|
||||
* 【core 】 IdcardUtil增加行政区划83(issue#1277@Github)
|
||||
* 【core 】 multipart中int改为long,解决大文件上传越界问题(issue#I27WZ3@Gitee)
|
||||
|
||||
### Bug修复
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
@ -2,9 +2,9 @@ package cn.hutool.core.net.multipart;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.map.multi.ListValueMap;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
@ -78,10 +78,7 @@ public class MultipartFormData {
|
||||
putFile(header.formFieldName, newFile);
|
||||
} else {
|
||||
// 标准表单项
|
||||
ByteArrayOutputStream fbos = new ByteArrayOutputStream(1024);
|
||||
input.copy(fbos);
|
||||
String value = (charset != null) ? new String(fbos.toByteArray(), charset) : new String(fbos.toByteArray());
|
||||
putParameter(header.formFieldName, value);
|
||||
putParameter(header.formFieldName, IoUtil.read(input, charset));
|
||||
}
|
||||
|
||||
input.skipBytes(1);
|
||||
|
@ -171,7 +171,7 @@ public class MultipartRequestInputStream extends BufferedInputStream {
|
||||
* @return 复制的字节数
|
||||
* @throws IOException 读取异常
|
||||
*/
|
||||
public int copy(OutputStream out, int limit) throws IOException {
|
||||
public int copy(OutputStream out, long limit) throws IOException {
|
||||
int count = 0;
|
||||
while (true) {
|
||||
byte b = readByte();
|
||||
|
@ -7,7 +7,6 @@ import cn.hutool.core.util.StrUtil;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
@ -24,7 +23,7 @@ public class UploadFile {
|
||||
private final UploadFileHeader header;
|
||||
private final UploadSetting setting;
|
||||
|
||||
private int size = -1;
|
||||
private long size = -1;
|
||||
|
||||
// 文件流(小文件位于内存中)
|
||||
private byte[] data;
|
||||
@ -150,7 +149,7 @@ public class UploadFile {
|
||||
/**
|
||||
* @return 上传文件的大小,> 0 表示未上传
|
||||
*/
|
||||
public int size() {
|
||||
public long size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@ -200,13 +199,13 @@ public class UploadFile {
|
||||
|
||||
// 处理硬盘文件
|
||||
tempFile = FileUtil.createTempFile(TMP_FILE_PREFIX, TMP_FILE_SUFFIX, FileUtil.touch(setting.tmpUploadPath), false);
|
||||
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(tempFile));
|
||||
final BufferedOutputStream out = FileUtil.getOutputStream(this.tempFile);
|
||||
if (data != null) {
|
||||
size = data.length;
|
||||
out.write(data);
|
||||
data = null; // not needed anymore
|
||||
}
|
||||
int maxFileSize = setting.maxFileSize;
|
||||
final long maxFileSize = setting.maxFileSize;
|
||||
try {
|
||||
if (maxFileSize == -1) {
|
||||
size += input.copy(out);
|
||||
@ -236,14 +235,14 @@ public class UploadFile {
|
||||
* @return 是否为允许的扩展名
|
||||
*/
|
||||
private boolean isAllowedExtension() {
|
||||
String[] exts = setting.fileExts;
|
||||
final String[] exts = setting.fileExts;
|
||||
boolean isAllow = setting.isAllowFileExts;
|
||||
if (exts == null || exts.length == 0) {
|
||||
// 如果给定扩展名列表为空,当允许扩展名时全部允许,否则全部禁止
|
||||
return isAllow;
|
||||
}
|
||||
|
||||
String fileNameExt = FileUtil.extName(this.getFileName());
|
||||
final String fileNameExt = FileUtil.extName(this.getFileName());
|
||||
for (String fileExtension : setting.fileExts) {
|
||||
if (fileNameExt.equalsIgnoreCase(fileExtension)) {
|
||||
return isAllow;
|
||||
|
@ -31,7 +31,8 @@ public class UploadFileHeader {
|
||||
// ---------------------------------------------------------------- public interface
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if uploaded data are correctly marked as a file. This is true if header contains string 'filename'.
|
||||
* Returns {@code true} if uploaded data are correctly marked as a file.<br>
|
||||
* This is true if header contains string 'filename'.
|
||||
*
|
||||
* @return 是否为文件
|
||||
*/
|
||||
|
@ -9,7 +9,7 @@ package cn.hutool.core.net.multipart;
|
||||
public class UploadSetting {
|
||||
|
||||
/** 最大文件大小,默认无限制 */
|
||||
protected int maxFileSize = -1;
|
||||
protected long maxFileSize = -1;
|
||||
/** 文件保存到内存的边界 */
|
||||
protected int memoryThreshold = 8192;
|
||||
/** 临时文件目录 */
|
||||
@ -26,7 +26,7 @@ public class UploadSetting {
|
||||
/**
|
||||
* @return 获得最大文件大小,-1表示无限制
|
||||
*/
|
||||
public int getMaxFileSize() {
|
||||
public long getMaxFileSize() {
|
||||
return maxFileSize;
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ public class UploadSetting {
|
||||
*
|
||||
* @param maxFileSize 最大文件大小
|
||||
*/
|
||||
public void setMaxFileSize(int maxFileSize) {
|
||||
public void setMaxFileSize(long maxFileSize) {
|
||||
this.maxFileSize = maxFileSize;
|
||||
}
|
||||
|
||||
|
@ -83,6 +83,8 @@ public class IdcardUtil {
|
||||
CITY_CODES.put("71", "台湾");
|
||||
CITY_CODES.put("81", "香港");
|
||||
CITY_CODES.put("82", "澳门");
|
||||
//issue#1277,台湾身份证号码以83开头,但是行政区划为71
|
||||
CITY_CODES.put("83", "台湾");
|
||||
CITY_CODES.put("91", "国外");
|
||||
|
||||
TW_FIRST_CODE.put("A", 10);
|
||||
@ -354,7 +356,7 @@ public class IdcardUtil {
|
||||
sum = sum + Integer.parseInt(String.valueOf(c)) * iflag;
|
||||
iflag--;
|
||||
}
|
||||
if ("A".equals(end.toUpperCase())) {
|
||||
if ("A".equalsIgnoreCase(end)) {
|
||||
sum += 10;
|
||||
} else {
|
||||
sum += Integer.parseInt(end);
|
||||
|
@ -626,7 +626,7 @@ public final class SecureUtil {
|
||||
* 创建HMac对象,调用digest方法可获得hmac值
|
||||
*
|
||||
* @param algorithm {@link HmacAlgorithm}
|
||||
* @param key 密钥,如果为<code>null</code>生成随机密钥
|
||||
* @param key 密钥,如果为{@code null}生成随机密钥
|
||||
* @return {@link HMac}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
@ -638,7 +638,7 @@ public final class SecureUtil {
|
||||
* 创建HMac对象,调用digest方法可获得hmac值
|
||||
*
|
||||
* @param algorithm {@link HmacAlgorithm}
|
||||
* @param key 密钥,如果为<code>null</code>生成随机密钥
|
||||
* @param key 密钥,如果为{@code null}生成随机密钥
|
||||
* @return {@link HMac}
|
||||
* @since 3.0.3
|
||||
*/
|
||||
@ -650,7 +650,7 @@ public final class SecureUtil {
|
||||
* 创建HMac对象,调用digest方法可获得hmac值
|
||||
*
|
||||
* @param algorithm {@link HmacAlgorithm}
|
||||
* @param key 密钥{@link SecretKey},如果为<code>null</code>生成随机密钥
|
||||
* @param key 密钥{@link SecretKey},如果为{@code null}生成随机密钥
|
||||
* @return {@link HMac}
|
||||
* @since 3.0.3
|
||||
*/
|
||||
@ -664,7 +664,7 @@ public final class SecureUtil {
|
||||
* HmacMD5加密:hmacMd5(key).digest(data)<br>
|
||||
* HmacMD5加密并转为16进制字符串:hmacMd5(key).digestHex(data)<br>
|
||||
*
|
||||
* @param key 加密密钥,如果为<code>null</code>生成随机密钥
|
||||
* @param key 加密密钥,如果为{@code null}生成随机密钥
|
||||
* @return {@link HMac}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
@ -678,7 +678,7 @@ public final class SecureUtil {
|
||||
* HmacMD5加密:hmacMd5(key).digest(data)<br>
|
||||
* HmacMD5加密并转为16进制字符串:hmacMd5(key).digestHex(data)<br>
|
||||
*
|
||||
* @param key 加密密钥,如果为<code>null</code>生成随机密钥
|
||||
* @param key 加密密钥,如果为{@code null}生成随机密钥
|
||||
* @return {@link HMac}
|
||||
*/
|
||||
public static HMac hmacMd5(byte[] key) {
|
||||
@ -703,7 +703,7 @@ public final class SecureUtil {
|
||||
* HmacSHA1加密:hmacSha1(key).digest(data)<br>
|
||||
* HmacSHA1加密并转为16进制字符串:hmacSha1(key).digestHex(data)<br>
|
||||
*
|
||||
* @param key 加密密钥,如果为<code>null</code>生成随机密钥
|
||||
* @param key 加密密钥,如果为{@code null}生成随机密钥
|
||||
* @return {@link HMac}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
@ -717,7 +717,7 @@ public final class SecureUtil {
|
||||
* HmacSHA1加密:hmacSha1(key).digest(data)<br>
|
||||
* HmacSHA1加密并转为16进制字符串:hmacSha1(key).digestHex(data)<br>
|
||||
*
|
||||
* @param key 加密密钥,如果为<code>null</code>生成随机密钥
|
||||
* @param key 加密密钥,如果为{@code null}生成随机密钥
|
||||
* @return {@link HMac}
|
||||
*/
|
||||
public static HMac hmacSha1(byte[] key) {
|
||||
|
@ -1,14 +1,5 @@
|
||||
package cn.hutool.crypto.digest;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.Provider;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
@ -19,6 +10,15 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.CryptoException;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.nio.charset.Charset;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.Provider;
|
||||
|
||||
/**
|
||||
* 摘要算法<br>
|
||||
* 注意:此对象实例化后为非线程安全!
|
||||
@ -84,7 +84,7 @@ public class Digester implements Serializable {
|
||||
*
|
||||
* @param algorithm 算法
|
||||
* @param provider 算法提供者,null表示JDK默认,可以引入Bouncy Castle等来提供更多算法支持
|
||||
* @return {@link Digester}
|
||||
* @return Digester
|
||||
* @throws CryptoException Cause by IOException
|
||||
*/
|
||||
public Digester init(String algorithm, Provider provider) {
|
||||
|
Loading…
Reference in New Issue
Block a user