From 2f55cebbad3dea187a5f91d16ec80a9677dab699 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期三, 13 十一月 2024 11:16:53 +0800 Subject: [PATCH] 1 --- src/main/java/com/yssh/utils/WebUtils.java | 37 ------------------------------------- 1 files changed, 0 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/yssh/utils/WebUtils.java b/src/main/java/com/yssh/utils/WebUtils.java index b5f8bff..1f74189 100644 --- a/src/main/java/com/yssh/utils/WebUtils.java +++ b/src/main/java/com/yssh/utils/WebUtils.java @@ -6,25 +6,9 @@ import java.net.URLEncoder; import java.util.Date; -/** - * Web宸ュ叿绫� - * @author WWW - * @date 2023-08-09 - */ public class WebUtils { - /** - * 瀛楃鐐� - */ public final static String POINT = "."; - /** - * 涓嬭浇鏂囦欢 - * - * @param file 鏂囦欢 - * @param fileName 鏂囦欢鍚� - * @param res 鍝嶅簲 - * @throws Exception 寮傚父 - */ public static void download(String file, String fileName, boolean inline, HttpServletResponse res) throws Exception { if (StringUtils.isEmpty(fileName)) { fileName = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, new Date()); @@ -32,37 +16,27 @@ fileName = URLEncoder.encode(fileName, "UTF-8").replace("+", "%20"); String dispose = inline ? "inline" : "attachment"; - // 璁剧疆鍝嶅簲澶翠腑鏂囦欢鐨勪笅杞芥柟寮忎负闄勪欢鏂瑰紡锛屼互鍙婅缃枃浠跺悕 res.setHeader("Content-Disposition", dispose + "; filename*=UTF-8''" + fileName); - // 璁剧疆鍝嶅簲澶寸殑缂栫爜鏍煎紡涓� UTF-8 res.setCharacterEncoding("UTF-8"); - // 閫氳繃response瀵硅薄璁剧疆鍝嶅簲鏁版嵁鏍煎紡(濡傦細"text/plain; charset=utf-8") String ext = getExtension(file); String mime = getMime(ext); res.setContentType(mime); - // 閫氳繃response瀵硅薄锛岃幏鍙栧埌杈撳嚭娴� ServletOutputStream outputStream = res.getOutputStream(); - // 瀹氫箟杈撳叆娴侊紝閫氳繃杈撳叆娴佽鍙栨枃浠跺唴瀹� FileInputStream fileInputStream = new FileInputStream(file); int len = 0; byte[] bytes = new byte[1024]; while ((len = fileInputStream.read(bytes)) != -1) { - // 閫氳繃杈撳叆娴佽鍙栨枃浠舵暟鎹紝鐒跺悗閫氳繃涓婅堪鐨勮緭鍑烘祦鍐欏洖娴忚鍣� outputStream.write(bytes, 0, len); outputStream.flush(); } - // 鍏抽棴璧勬簮 fileInputStream.close(); outputStream.close(); } - /** - * 鑾峰彇鏂囦欢鎵╁睍鍚� - */ public static String getExtension(String fileName) { if (StringUtils.isEmpty(fileName)) { return ""; @@ -76,15 +50,8 @@ return fileName.substring(idx).toLowerCase(); } - /** - * 鑾峰彇澶氱敤閫斾簰鑱旂綉閭欢鎵╁睍绫诲瀷 - * - * @param ext 鏂囦欢鎵╁睍鍚� - * @return MIME - */ public static String getMime(String ext) { switch (ext) { - // 鍥剧墖 case ".tif": case ".tiff": return "image/tiff"; @@ -97,7 +64,6 @@ return "image/jpeg"; case ".png": return "image/png"; - // 闊�/瑙嗛 case ".mp3": return "audio/mp3"; case ".mp4": @@ -119,7 +85,6 @@ return "application/vnd.rn-realmedia"; case ".rmvb": return "application/vnd.rn-realmedia-vbr"; - // 缃戦〉 case ".js": return "application/x-javascript"; case ".css": @@ -136,7 +101,6 @@ case ".xml": case ".svg": return "text/xml"; - // 鏂囦欢 case ".txt": return "text/plain"; case ".dbf": @@ -160,7 +124,6 @@ return "application/x-dwg"; case ".ext": return "application/x-msdownload"; - // 榛樿 default: return "application/octet-stream"; } -- Gitblit v1.9.3