mirror of
https://github.com/wahyd4/Martian.git
synced 2026-08-09 05:16:21 +10:00
update version
This commit is contained in:
@@ -45,4 +45,21 @@ public class SerializableUtil {
|
||||
throw new Exception("将二进制流反序列化成参数,出现异常",e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将二进制流反序列化成对象
|
||||
* @param inputStream 对象
|
||||
* @param cls 类型
|
||||
* @param <T> 对象
|
||||
* @return 对象
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
public static <T> T deSerialization(InputStream inputStream,Class<T> cls) throws Exception {
|
||||
try {
|
||||
ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
|
||||
return (T)objectInputStream.readObject();
|
||||
} catch (Exception e){
|
||||
throw new Exception("将二进制流反序列化成参数,出现异常",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +84,13 @@ public class BuildParams {
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 给参数赋值
|
||||
* @param field 字段
|
||||
* @param obj 对象
|
||||
* @param marsFileUpLoadMap 文件
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
private static void putMarsFileUploads(Field field, Object obj, Map<String,MarsFileUpLoad> marsFileUpLoadMap) throws Exception{
|
||||
MarsFileUpLoad[] marsFileUpLoads = new MarsFileUpLoad[marsFileUpLoadMap.size()];
|
||||
int index = 0;
|
||||
@@ -94,6 +101,13 @@ public class BuildParams {
|
||||
field.set(obj, marsFileUpLoads);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给参数赋值
|
||||
* @param field 字段
|
||||
* @param obj 对象
|
||||
* @param valList 数据
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
private static void putAttr(Field field, Object obj, String[] valList) throws Exception{
|
||||
String fieldTypeName = field.getType().getSimpleName().toUpperCase();
|
||||
String valStr = valList[0];
|
||||
|
||||
@@ -13,7 +13,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* 接收netty服务
|
||||
* 接收tomcat服务
|
||||
* @author yuye
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package com.mars.netty.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.mars.core.util.ConfigUtil;
|
||||
import com.mars.server.server.request.model.MarsFileUpLoad;
|
||||
import org.apache.tomcat.util.http.fileupload.FileItem;
|
||||
import org.apache.tomcat.util.http.fileupload.FileItemFactory;
|
||||
import org.apache.tomcat.util.http.fileupload.disk.DiskFileItemFactory;
|
||||
import org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload;
|
||||
import org.apache.tomcat.util.http.fileupload.servlet.ServletRequestContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
@@ -14,6 +18,8 @@ import java.util.Map;
|
||||
|
||||
public class FileUpLoad {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(FileUpLoad.class);
|
||||
|
||||
/**
|
||||
* 默认单个文件2M
|
||||
*/
|
||||
@@ -24,6 +30,12 @@ public class FileUpLoad {
|
||||
*/
|
||||
private static int sizeMax = 10*1024*1024;
|
||||
|
||||
/**
|
||||
* 获取文件Map
|
||||
* @param request 请求
|
||||
* @return 返回
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
public static Map<String, MarsFileUpLoad> getFiles(HttpServletRequest request) throws Exception {
|
||||
try {
|
||||
if(!ServletFileUpload.isMultipartContent(request)) {
|
||||
@@ -51,7 +63,14 @@ public class FileUpLoad {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件列表
|
||||
* @param request 请求
|
||||
* @return 返回
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
public static List<FileItem> getFileItem(HttpServletRequest request) throws Exception {
|
||||
init();
|
||||
|
||||
FileItemFactory factory = new DiskFileItemFactory();
|
||||
ServletFileUpload fileUpload = new ServletFileUpload(factory);
|
||||
@@ -62,4 +81,27 @@ public class FileUpLoad {
|
||||
|
||||
return fileItemList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
private static void init(){
|
||||
try {
|
||||
JSONObject config = ConfigUtil.getConfig();
|
||||
JSONObject fileUpload = config.getJSONObject("fileUpload");
|
||||
if(fileUpload != null){
|
||||
Integer configFileSizeMax = fileUpload.getInteger("fileSizeMax");
|
||||
Integer configSizeMax = fileUpload.getInteger("sizeMax");
|
||||
|
||||
if(configFileSizeMax != null && configFileSizeMax > 0){
|
||||
fileSizeMax = configFileSizeMax;
|
||||
}
|
||||
if(configSizeMax != null && configSizeMax > 0){
|
||||
sizeMax = configSizeMax;
|
||||
}
|
||||
}
|
||||
} catch (Exception e){
|
||||
logger.error("设置文件大小限制参数异常",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user