From 138b959cc11dc9a73b0c766030b99ba1180d8650 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期一, 11 十一月 2024 14:32:48 +0800 Subject: [PATCH] 11 --- src/main/java/com/se/simu/helper/FileHelper.java | 169 ------------------------------------------------------- 1 files changed, 2 insertions(+), 167 deletions(-) diff --git a/src/main/java/com/se/simu/helper/FileHelper.java b/src/main/java/com/se/simu/helper/FileHelper.java index a2357e3..6f239fb 100644 --- a/src/main/java/com/se/simu/helper/FileHelper.java +++ b/src/main/java/com/se/simu/helper/FileHelper.java @@ -12,13 +12,8 @@ import java.text.DecimalFormat; import java.util.List; -/** - * 鏂囦欢甯姪绫� - * - * @author WWW - * @date 2024-09-12 - */ @Slf4j +@SuppressWarnings("ALL") public class FileHelper { public final static String POINT = "."; @@ -32,9 +27,6 @@ public static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; - /** - * 鑾峰彇鏂囦欢鍚� - */ public static String getFileName(String file) { int idx = file.lastIndexOf(File.separator); if (idx > -1) { @@ -44,9 +36,6 @@ return ""; } - /** - * 鑾峰彇鏂囦欢鍚嶇О - */ public static String getName(String file) { String fileName = getFileName(file); int idx = fileName.lastIndexOf("."); @@ -57,9 +46,6 @@ return fileName; } - /** - * 鑾峰彇鏂囦欢鎵╁睍鍚� - */ public static String getExtension(File file) { if (file == null) { return null; @@ -75,9 +61,6 @@ return fileName.substring(idx); } - /** - * 鑾峰彇鏂囦欢鎵╁睍鍚� - */ public static String getExtension(String fileName) { if (StringHelper.isEmpty(fileName)) { return ""; @@ -91,96 +74,6 @@ return fileName.substring(idx).toLowerCase(); } - /** - * 鑾峰彇澶氱敤閫斾簰鑱旂綉閭欢鎵╁睍绫诲瀷 - */ - public static String getMime(String ext) { - switch (ext) { - // 鍥剧墖 - case ".tif": - case ".tiff": - return "image/tiff"; - case ".img": - return "application/x-img"; - case ".gif": - return "image/gif"; - case ".jpg": - case ".jpeg": - return "image/jpeg"; - case ".png": - return "image/png"; - // 闊�/瑙嗛 - case ".mp3": - return "audio/mp3"; - case ".mp4": - return "video/mpeg4"; - case ".avi": - return "video/avi"; - case ".mpg": - case ".mpeg": - return "video/mpg"; - case ".wav": - return "audio/wav"; - case ".wma": - return "audio/x-ms-wma"; - case ".swf": - return "application/x-shockwave-flash"; - case ".wmv": - return "video/x-ms-wmv"; - case ".rm": - return "application/vnd.rn-realmedia"; - case ".rmvb": - return "application/vnd.rn-realmedia-vbr"; - // 缃戦〉 - case ".js": - return "application/x-javascript"; - case ".css": - return "text/css"; - case ".asp": - return "text/asp"; - case ".mht": - return "message/rfc822"; - case ".jsp": - case ".htm": - case ".html": - case ".xhtml": - return "text/html"; - case ".xml": - case ".svg": - return "text/xml"; - // 鏂囦欢 - case ".txt": - return "text/plain"; - case ".dbf": - return "application/x-dbf"; - case ".mdb": - return "application/msaccess"; - case ".pdf": - return "application/pdf"; - case ".ppt": - case ".pptx": - return "application/x-ppt"; - case ".doc": - case ".docx": - return "application/msword"; - case ".xls": - case ".xlsx": - return "application/vnd.ms-excel"; - case ".dgn": - return "application/x-dgn"; - case ".dwg": - return "application/x-dwg"; - case ".ext": - return "application/x-msdownload"; - // 榛樿 - default: - return "application/octet-stream"; - } - } - - /** - * 瀛楄妭鍗曚綅鎹㈢畻 - */ public static String formatByte(long byteNumber) { double kbNumber = byteNumber / D1024; if (kbNumber < D1024) { @@ -199,9 +92,6 @@ return new DecimalFormat("#.##TB").format(tbNumber); } - /** - * 鑾峰彇骞虫柟绫� - */ public static String getSquareMeter(double num) { if (num < I1000000) { return new DecimalFormat("#.##骞虫柟绫�").format(num); @@ -212,9 +102,6 @@ return new DecimalFormat("#.##骞虫柟鍗冪背").format(knum); } - /** - * byte杞琈B - */ public static double sizeToMb(long size) { if (size < D1050) { return 0.001; @@ -225,9 +112,6 @@ return Double.parseDouble(str); } - /** - * 3.鑾峰彇鏂囦欢MD5鐮侊紙JDK锛� - */ public static String getMd5ByJdk(String filePath) throws IOException { FileInputStream fileStream = new FileInputStream(filePath); String md5 = DigestUtils.md5Hex(fileStream); @@ -236,9 +120,6 @@ return md5; } - /** - * 2.鑾峰彇蹇�� MD5 鐮� - */ public static String getFastMd5(String filePath) throws IOException { String hash = MD5.asHex(MD5.getHash(new File(filePath))); @@ -248,22 +129,12 @@ return md5.asHex(); } - /** - * 鍒犻櫎鏂囦欢澶� - * - * @param dir 鏂囦欢澶� - */ public static void deleteDir(String dir) { File file = new File(dir); deleteFiles(file); } - /** - * 绾ц仈鍒犻櫎鏂囦欢 - * - * @param file 鏂囦欢 - */ public static void deleteFiles(File file) { if (null == file || !file.exists()) { return; @@ -285,12 +156,6 @@ file.delete(); } - /** - * 鑾峰彇鐩稿璺緞 - * - * @param file 鏂囦欢 - * @return 鐩稿璺緞 - */ public static String getRelativePath(String file) { if (StringHelper.isEmpty(file)) { return null; @@ -302,12 +167,6 @@ return file.substring(start + 1); } - /** - * 鑾峰彇璺緞 - * - * @param file 鏂囦欢 - * @return 鏂囦欢璺緞 - */ public static String getPath(String file) { if (StringHelper.isEmpty(file)) { return null; @@ -318,9 +177,6 @@ return file.substring(0, end); } - /** - * 1.鑾峰彇鏂囦欢鐨凪D5 - */ @SuppressWarnings("unused") public static String getFileMd5(String filePath) { FileInputStream fis = null; @@ -353,31 +209,19 @@ } } - /** - * 瀛楄妭鐮佽浆16杩涘埗 - */ public static String byteToHexString(byte[] tmp) { - // 姣忎釜瀛楄妭鐢� 16 杩涘埗琛ㄧず鐨勮瘽锛屼娇鐢ㄤ袱涓瓧绗︼紝 char[] str = new char[16 * 2]; - // 鎵�浠ヨ〃绀烘垚 16 杩涘埗闇�瑕� 32 涓瓧绗︼紝琛ㄧず杞崲缁撴灉涓搴旂殑瀛楃浣嶇疆 int k = 0; - // 浠庣涓�涓瓧鑺傚紑濮嬶紝瀵� MD5 鐨勬瘡涓�涓瓧鑺� for (int i = 0; i < I16; i++) { - // 杞崲鎴� 16 杩涘埗瀛楃鐨勮浆鎹� byte byte0 = tmp[i]; - // 鍙栧瓧鑺備腑楂� 4 浣嶇殑鏁板瓧杞崲 str[k++] = HEX_DIGITS[byte0 >>> 4 & 0xf]; - // >>> 涓洪�昏緫鍙崇Щ锛屽皢绗﹀彿浣嶄竴璧峰彸绉伙紝 鍙栧瓧鑺備腑浣� 4 浣嶇殑鏁板瓧杞崲 str[k++] = HEX_DIGITS[byte0 & 0xf]; } - // 鎹㈠悗鐨勭粨鏋滆浆鎹负瀛楃涓� + return new String(str); } - /** - * 鑾峰彇瀛楃涓茬殑MD5鐮� - */ public static String getStringMd5(String text) { StringBuilder builder = new StringBuilder(); try { @@ -394,9 +238,6 @@ return builder.toString(); } - /** - * 鏍规嵁璺緞鑾峰彇鏂囦欢 - */ public static void getFilesByPath(List<String> list, String path) { File file = new File(path); if (file.isDirectory()) { @@ -417,12 +258,6 @@ } } - /** - * 澶嶅埗鏂囦欢 - * - * @param src 婧愭枃浠� - * @param dest 鐩綍鏂囦欢 - */ public static void copyFile(File src, File dest) throws IOException { InputStream is = null; OutputStream os = null; -- Gitblit v1.9.3