|
@@ -27,7 +27,6 @@ import java.util.Date;
|
|
import java.util.Enumeration;
|
|
import java.util.Enumeration;
|
|
import java.util.LinkedList;
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
-import java.util.UUID;
|
|
|
|
import java.util.zip.ZipEntry;
|
|
import java.util.zip.ZipEntry;
|
|
import java.util.zip.ZipFile;
|
|
import java.util.zip.ZipFile;
|
|
import java.util.zip.ZipOutputStream;
|
|
import java.util.zip.ZipOutputStream;
|
|
@@ -39,6 +38,7 @@ import org.apache.tika.Tika;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
+import cn.com.qmth.examcloud.commons.util.UUID;
|
|
import cn.com.qmth.examcloud.core.questions.base.IoUtils;
|
|
import cn.com.qmth.examcloud.core.questions.base.IoUtils;
|
|
|
|
|
|
public class FileUtil {
|
|
public class FileUtil {
|
|
@@ -46,23 +46,27 @@ public class FileUtil {
|
|
private static final Logger log = LoggerFactory.getLogger(FileUtil.class);
|
|
private static final Logger log = LoggerFactory.getLogger(FileUtil.class);
|
|
|
|
|
|
public static String imageUrlToBase64(String src) {
|
|
public static String imageUrlToBase64(String src) {
|
|
|
|
+ File temFile = null;
|
|
File image = null;
|
|
File image = null;
|
|
try {
|
|
try {
|
|
URL url = new URL(src);
|
|
URL url = new URL(src);
|
|
InputStream is = url.openStream();
|
|
InputStream is = url.openStream();
|
|
- String newFileName = UUID.randomUUID().toString();
|
|
|
|
- image = new File("temp/" + newFileName);
|
|
|
|
- if (!image.getParentFile().exists()) {
|
|
|
|
- image.mkdirs();
|
|
|
|
|
|
+ String newFileName = UUID.randomUUID();
|
|
|
|
+ temFile = new File("temp/" + newFileName);
|
|
|
|
+ if (!temFile.getParentFile().exists()) {
|
|
|
|
+ temFile.mkdirs();
|
|
}
|
|
}
|
|
- FileUtils.copyInputStreamToFile(is, image);
|
|
|
|
- String imageType = checkImageType(image);
|
|
|
|
- newFileName = newFileName + "." + imageType;
|
|
|
|
- image.renameTo(new File("temp/" + newFileName));
|
|
|
|
|
|
+ FileUtils.copyInputStreamToFile(is, temFile);
|
|
|
|
+ String imageType = checkImageType(temFile);
|
|
|
|
+ image = new File("temp/" + newFileName + "." + imageType);
|
|
|
|
+ temFile.renameTo(image);
|
|
return fileToBase64(image);
|
|
return fileToBase64(image);
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
throw new RuntimeException(e);
|
|
throw new RuntimeException(e);
|
|
} finally {
|
|
} finally {
|
|
|
|
+ if (temFile != null) {
|
|
|
|
+ image.delete();
|
|
|
|
+ }
|
|
if (image != null) {
|
|
if (image != null) {
|
|
image.delete();
|
|
image.delete();
|
|
}
|
|
}
|
|
@@ -275,10 +279,6 @@ public class FileUtil {
|
|
return "/" + new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + "/";
|
|
return "/" + new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + "/";
|
|
}
|
|
}
|
|
|
|
|
|
- public static String generateFileName() {
|
|
|
|
- return UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public static String generateDateName() {
|
|
public static String generateDateName() {
|
|
return new SimpleDateFormat("yyMMddHHmmss").format(new Date());
|
|
return new SimpleDateFormat("yyMMddHHmmss").format(new Date());
|
|
}
|
|
}
|