Merge remote-tracking branch 'origin/master'

# Conflicts:
#	eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java
pull/174/head
jyao 2019-10-29 09:48:29 +08:00
commit 5916cb2f50
1 changed files with 22 additions and 31 deletions

View File

@ -7,7 +7,6 @@ import cn.hutool.poi.excel.BigExcelWriter;
import cn.hutool.poi.excel.ExcelUtil; import cn.hutool.poi.excel.ExcelUtil;
import me.zhengjie.exception.BadRequestException; import me.zhengjie.exception.BadRequestException;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.activation.MimetypesFileTypeMap; import javax.activation.MimetypesFileTypeMap;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -20,7 +19,6 @@ import java.util.Map;
/** /**
* File hutool * File hutool
*
* @author Zheng Jie * @author Zheng Jie
* @date 2018-12-27 * @date 2018-12-27
*/ */
@ -46,7 +44,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
/** /**
* MultipartFileFile * MultipartFileFile
*
* @param multipartFile * @param multipartFile
* @return * @return
*/ */
@ -69,7 +66,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
/** /**
* *
*
* @param files * @param files
*/ */
public static void deleteFile(File... files) { public static void deleteFile(File... files) {
@ -82,7 +78,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
/** /**
* *
*
* @param filename * @param filename
* @return * @return
*/ */
@ -98,7 +93,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
/** /**
* Java * Java
*
* @param filename * @param filename
* @return * @return
*/ */
@ -114,7 +108,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
/** /**
* *
*
* @param size * @param size
* @return * @return
*/ */
@ -137,14 +130,13 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
/** /**
* inputStream File * inputStream File
*
* @param ins * @param ins
* @param name * @param name
* @return * @return
* @throws Exception * @throws Exception
*/ */
public static File inputStreamToFile(InputStream ins, String name) throws Exception{ public static File inputStreamToFile(InputStream ins, String name) throws Exception{
File file = new File(System.getProperty("java.io.tmpdir") + name); File file = new File(System.getProperty("java.io.tmpdir") + File.separator + name);
if (file.exists()) { if (file.exists()) {
return file; return file;
} }
@ -174,12 +166,13 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
String nowStr = "-" + format.format(date); String nowStr = "-" + format.format(date);
try { try {
String fileName = name + nowStr + "." + suffix; String fileName = name + nowStr + "." + suffix;
String path = filePath + File.separator + fileName; String path = filePath + fileName;
File dest = new File(path).getCanonicalFile(); File dest = new File(path);
// 检测是否存在目录 // 检测是否存在目录
if (!dest.getParentFile().exists()) { if (!dest.getParentFile().exists()) {
dest.getParentFile().mkdirs();// 新建文件夹 dest.getParentFile().mkdirs();// 新建文件夹
} }
String d = dest.getPath();
file.transferTo(dest);// 文件写入 file.transferTo(dest);// 文件写入
return dest; return dest;
} catch (Exception e) { } catch (Exception e) {
@ -201,7 +194,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
/** /**
* excel * excel
*
* @param list * @param list
* @return * @return
* @throws Exception * @throws Exception
@ -244,7 +236,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
String mimeType = new MimetypesFileTypeMap().getContentType("." + type); String mimeType = new MimetypesFileTypeMap().getContentType("." + type);
return mimeType.split("\\/")[0]; return mimeType.split("\\/")[0];
} }
public static void checkSize(long maxSize, long size) { public static void checkSize(long maxSize, long size) {
if(size > (maxSize * 1024 * 1024)){ if(size > (maxSize * 1024 * 1024)){
throw new BadRequestException("文件超出规定大小"); throw new BadRequestException("文件超出规定大小");