UploadUtils.java
1022 字节
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
package com.framework.util;
import java.io.File;
import java.util.Timer;
import java.util.TimerTask;
import org.apache.commons.lang3.StringUtils;
public class UploadUtils {
private static Timer timer = new Timer(true);
public static void uploadFile(String newFilePath) {
if (StringUtils.isNotEmpty(newFilePath)) {
String newPath = PropertiesLoader.get("UPLOAD_PATH") + newFilePath;
File newFile = new File(newPath);
// 判断是图片
if (FileUtils.isImageFile(newPath)) {
genImage(newFile);
}
}
}
private static void genImage(File ori) {
try {
timer.schedule(new ImageProcessTask(ori), 1000);
} catch (IllegalStateException e) {
synchronized (timer) {
timer = new Timer(true);
}
timer.schedule(new ImageProcessTask(ori), 1000);
}
}
}
class ImageProcessTask extends TimerTask {
private File ori;
public ImageProcessTask(File ori) {
this.ori = ori;
}
public void run() {
ImageMagickUtils.resize(ori);
}
}