package com.qianwen.core.boot.file; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; import java.util.Hashtable; import java.util.List; import com.qianwen.core.tool.utils.StringUtil; import org.springframework.web.multipart.MultipartFile; /* loaded from: blade-core-boot-9.3.0.0-SNAPSHOT.jar:org/springblade/core/boot/file/BladeFileUtil.class */ public class BladeFileUtil { private static final String IS_DIR = "is_dir"; private static final String FILE_NAME = "filename"; private static final String FILE_SIZE = "filesize"; private static final HashMap EXT_MAP = new HashMap<>(); private static final String[] FILE_TYPES = {"gif", "jpg", "jpeg", "png", "bmp"}; static { EXT_MAP.put("image", ".gif,.jpg,.jpeg,.png,.bmp,.JPG,.JPEG,.PNG"); EXT_MAP.put("flash", ".swf,.flv"); EXT_MAP.put("media", ".swf,.flv,.mp3,.mp4,.wav,.wma,.wmv,.mid,.avi,.mpg,.asf,.rm,.rmvb"); EXT_MAP.put("file", ".doc,.docx,.xls,.xlsx,.ppt,.htm,.html,.txt,.zip,.rar,.gz,.bz2"); EXT_MAP.put("allfile", ".gif,.jpg,.jpeg,.png,.bmp,.swf,.flv,.mp3,.mp4,.wav,.wma,.wmv,.mid,.avi,.mpg,.asf,.rm,.rmvb,.doc,.docx,.xls,.xlsx,.ppt,.htm,.html,.txt,.zip,.rar,.gz,.bz2"); } public static String getFileExt(String fileName) { return fileName.substring(fileName.lastIndexOf(".")); } public static boolean testExt(String dir, String fileName) { String fileExt = getFileExt(fileName); String ext = EXT_MAP.get(dir); return StringUtil.isNotBlank(ext) && (ext.contains(fileExt.toLowerCase()) || ext.contains(fileExt.toUpperCase())); } /* loaded from: blade-core-boot-9.3.0.0-SNAPSHOT.jar:org/springblade/core/boot/file/BladeFileUtil$FileSort.class */ public enum FileSort { size, type, name; public static FileSort of(String sort) { try { return valueOf(sort); } catch (Exception e) { return name; } } } /* loaded from: blade-core-boot-9.3.0.0-SNAPSHOT.jar:org/springblade/core/boot/file/BladeFileUtil$NameComparator.class */ public static class NameComparator implements Comparator { @Override // java.util.Comparator public int compare(Object a, Object b) { Hashtable hashA = (Hashtable) a; Hashtable hashB = (Hashtable) b; if (((Boolean) hashA.get(BladeFileUtil.IS_DIR)).booleanValue() && !((Boolean) hashB.get(BladeFileUtil.IS_DIR)).booleanValue()) { return -1; } if (!((Boolean) hashA.get(BladeFileUtil.IS_DIR)).booleanValue() && ((Boolean) hashB.get(BladeFileUtil.IS_DIR)).booleanValue()) { return 1; } return ((String) hashA.get(BladeFileUtil.FILE_NAME)).compareTo((String) hashB.get(BladeFileUtil.FILE_NAME)); } } /* loaded from: blade-core-boot-9.3.0.0-SNAPSHOT.jar:org/springblade/core/boot/file/BladeFileUtil$SizeComparator.class */ public static class SizeComparator implements Comparator { @Override // java.util.Comparator public int compare(Object a, Object b) { Hashtable hashA = (Hashtable) a; Hashtable hashB = (Hashtable) b; if (((Boolean) hashA.get(BladeFileUtil.IS_DIR)).booleanValue() && !((Boolean) hashB.get(BladeFileUtil.IS_DIR)).booleanValue()) { return -1; } if ((!((Boolean) hashA.get(BladeFileUtil.IS_DIR)).booleanValue() && ((Boolean) hashB.get(BladeFileUtil.IS_DIR)).booleanValue()) || ((Long) hashA.get(BladeFileUtil.FILE_SIZE)).longValue() > ((Long) hashB.get(BladeFileUtil.FILE_SIZE)).longValue()) { return 1; } if (((Long) hashA.get(BladeFileUtil.FILE_SIZE)).longValue() < ((Long) hashB.get(BladeFileUtil.FILE_SIZE)).longValue()) { return -1; } return 0; } } /* loaded from: blade-core-boot-9.3.0.0-SNAPSHOT.jar:org/springblade/core/boot/file/BladeFileUtil$TypeComparator.class */ public static class TypeComparator implements Comparator { @Override // java.util.Comparator public int compare(Object a, Object b) { Hashtable hashA = (Hashtable) a; Hashtable hashB = (Hashtable) b; if (((Boolean) hashA.get(BladeFileUtil.IS_DIR)).booleanValue() && !((Boolean) hashB.get(BladeFileUtil.IS_DIR)).booleanValue()) { return -1; } if (!((Boolean) hashA.get(BladeFileUtil.IS_DIR)).booleanValue() && ((Boolean) hashB.get(BladeFileUtil.IS_DIR)).booleanValue()) { return 1; } return ((String) hashA.get("filetype")).compareTo((String) hashB.get("filetype")); } } public static String formatUrl(String url) { return url.replaceAll("\\\\", "/"); } public static LocalFile getFile(MultipartFile file) { return getFile(file, "image", null, null); } public static LocalFile getFile(MultipartFile file, String dir) { return getFile(file, dir, null, null); } public static LocalFile getFile(MultipartFile file, String dir, String path, String virtualPath) { return new LocalFile(file, dir, path, virtualPath); } public static List getFiles(List files) { return getFiles(files, "image", null, null); } public static List getFiles(List files, String dir) { return getFiles(files, dir, null, null); } public static List getFiles(List files, String dir, String path, String virtualPath) { List list = new ArrayList<>(); for (MultipartFile file : files) { list.add(new LocalFile(file, dir, path, virtualPath)); } return list; } }