zhuguifei
2025-04-28 442928123f63ee497d766f9a7a14f0a6ee067e25
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
 
package org.jeecg.modules.doc.component;
 
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import net.sf.sevenzipjbinding.ArchiveFormat;
import net.sf.sevenzipjbinding.IInArchive;
import net.sf.sevenzipjbinding.SevenZip;
import net.sf.sevenzipjbinding.impl.RandomAccessFileInStream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
public class FileOperation {
    private static final Logger log = LoggerFactory.getLogger(FileOperation.class);
    private static Executor executor = Executors.newFixedThreadPool(20);
 
    public FileOperation() {
    }
 
    public static File newFile(String fileUrl) {
        File file = new File(fileUrl);
        return file;
    }
 
    public static boolean deleteFile(File file) {
        if (file == null) {
            return false;
        } else if (!file.exists()) {
            return false;
        } else if (file.isFile()) {
            return file.delete();
        } else {
            File[] var1 = file.listFiles();
            int var2 = var1.length;
 
            for(int var3 = 0; var3 < var2; ++var3) {
                File newfile = var1[var3];
                deleteFile(newfile);
            }
 
            return file.delete();
        }
    }
 
    public static boolean deleteFile(String fileUrl) {
        File file = newFile(fileUrl);
        return deleteFile(file);
    }
 
    public static long getFileSize(String fileUrl) {
        File file = newFile(fileUrl);
        return file.exists() ? file.length() : 0L;
    }
 
    public static long getFileSize(File file) {
        return file == null ? 0L : file.length();
    }
 
    public static boolean mkdir(File file) {
        if (file == null) {
            return false;
        } else {
            return file.exists() ? true : file.mkdirs();
        }
    }
 
    public static boolean mkdir(String fileUrl) {
        if (fileUrl == null) {
            return false;
        } else {
            File file = newFile(fileUrl);
            return file.exists() ? true : file.mkdirs();
        }
    }
 
    public static void copyFile(FileInputStream fileInputStream, FileOutputStream fileOutputStream) throws IOException {
        try {
            byte[] buf = new byte[4096];
 
            for(int len = fileInputStream.read(buf); len != -1; len = fileInputStream.read(buf)) {
                fileOutputStream.write(buf, 0, len);
            }
        } finally {
            if (fileInputStream != null) {
                try {
                    fileInputStream.close();
                } catch (IOException var12) {
                    var12.printStackTrace();
                }
            }
 
            if (fileOutputStream != null) {
                try {
                    fileOutputStream.close();
                } catch (IOException var11) {
                    var11.printStackTrace();
                }
            }
 
        }
 
    }
 
    public static void copyFile(File src, File dest) throws IOException {
        FileInputStream in = new FileInputStream(src);
        FileOutputStream out = new FileOutputStream(dest);
        copyFile(in, out);
    }
 
    public static void copyFile(String srcUrl, String destUrl) throws IOException {
        if (srcUrl != null && destUrl != null) {
            File srcFile = newFile(srcUrl);
            File descFile = newFile(destUrl);
            copyFile(srcFile, descFile);
        }
    }
 
    public static List<String> unzip(File sourceFile, String destDirPath) throws Exception {
        RandomAccessFile randomAccessFile = new RandomAccessFile(sourceFile, "r");
        IInArchive archive = SevenZip.openInArchive((ArchiveFormat)null, new RandomAccessFileInStream(randomAccessFile));
        int[] in = new int[archive.getNumberOfItems()];
 
        for(int i = 0; i < in.length; in[i] = i++) {
        }
 
        archive.extract(in, false, new ExtractCallback(archive, destDirPath));
        File destFile = new File(destDirPath);
        Collection<File> files = FileUtils.listFilesAndDirs(destFile, new IOFileFilter() {
            public boolean accept(File file) {
                return true;
            }
 
            public boolean accept(File file, String s) {
                return true;
            }
        }, new IOFileFilter() {
            public boolean accept(File file) {
                return true;
            }
 
            public boolean accept(File file, String s) {
                return true;
            }
        });
        Set<String> set = new HashSet();
        files.forEach((o) -> {
            String path = o.getAbsolutePath().replace(destFile.getAbsolutePath(), "").replace("\\", "/");
            if (StringUtils.isNotEmpty(path)) {
                set.add(path);
            }
 
        });
        List<String> res = new ArrayList(set);
        return res;
    }
 
    public static void saveDataToFile(String filePath, String fileName, String data) {
        BufferedWriter writer = null;
        new File(filePath);
        if (!filePath.endsWith(File.separator)) {
            filePath = filePath + File.separator;
        }
 
        File file = new File(filePath + fileName);
        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException var18) {
                var18.printStackTrace();
            }
        }
 
        try {
            writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, false), "UTF-8"));
            writer.write(data);
        } catch (IOException var16) {
            var16.printStackTrace();
        } finally {
            try {
                if (writer != null) {
                    writer.close();
                }
            } catch (IOException var15) {
                var15.printStackTrace();
            }
 
        }
 
        System.out.println("文件写入成功!");
    }
}