yangys
2024-04-04 ed4a5236bab800094be4a8378f5098eebe3de6ac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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<String, String> 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<LocalFile> getFiles(List<MultipartFile> files) {
        return getFiles(files, "image", null, null);
    }
 
    public static List<LocalFile> getFiles(List<MultipartFile> files, String dir) {
        return getFiles(files, dir, null, null);
    }
 
    public static List<LocalFile> getFiles(List<MultipartFile> files, String dir, String path, String virtualPath) {
        List<LocalFile> list = new ArrayList<>();
        for (MultipartFile file : files) {
            list.add(new LocalFile(file, dir, path, virtualPath));
        }
        return list;
    }
}