diff --git a/src/main/java/com/weilab/biology/service/JobService.java b/src/main/java/com/weilab/biology/service/JobService.java index 5264bb9..5ef616c 100644 --- a/src/main/java/com/weilab/biology/service/JobService.java +++ b/src/main/java/com/weilab/biology/service/JobService.java @@ -9,23 +9,19 @@ import com.weilab.biology.core.data.dto.AppConfigDto; import com.weilab.biology.core.data.dto.JobDto; import com.weilab.biology.core.data.dto.JobLessDto; import com.weilab.biology.core.data.enums.JobStatusEnum; -import com.weilab.biology.core.data.po.AppConfig; import com.weilab.biology.core.data.po.Job; import com.weilab.biology.core.data.vo.result.CommonError; import com.weilab.biology.core.data.vo.result.Result; import com.weilab.biology.core.data.vo.result.error.JobError; import com.weilab.biology.mapper.JobMapper; -import com.weilab.biology.util.FileUtils; import com.weilab.biology.util.MailUtil; import com.weilab.biology.util.TaskExecutorUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; -import java.io.IOException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.List; @@ -66,7 +62,7 @@ public class JobService extends ServiceImpl { if (dataFile != null) { FileUtil.writeFromStream(dataFile.getInputStream(), dataPath); } else if (!StrUtil.isBlank(dataStr)) { - FileUtils.writeStringToFile(dataPath, dataStr); + FileUtil.writeBytes(dataStr.getBytes(), dataPath); } //将jobId和dataPath参数添加至param中 diff --git a/src/main/java/com/weilab/biology/util/FileUtils.java b/src/main/java/com/weilab/biology/util/FileUtils.java deleted file mode 100644 index 4169282..0000000 --- a/src/main/java/com/weilab/biology/util/FileUtils.java +++ /dev/null @@ -1,118 +0,0 @@ -package com.weilab.biology.util; - -import org.springframework.web.multipart.MultipartFile; - -import java.io.*; - -/** - * 文件读取工具类 - */ -public class FileUtils { - - /** - * MultipartFile 转换成File - * - * @param multfile 原文件类型 - * @return File - */ - public static File multipartToFile(MultipartFile multfile) { - File file = null; - try { - file = File.createTempFile("prefix", "_" + multfile.getOriginalFilename()); - multfile.transferTo(file); - } catch (IOException e) { - e.printStackTrace(); - } - return file; - } - - /** - * 读取文件内容,作为字符串返回 - */ - public static String readFileAsString(String filePath) throws IOException { - File file = new File(filePath); - if (!file.exists()) { - throw new FileNotFoundException(filePath); - } - - return readFileAsString(file); - } - - /** - * 读取文件内容,作为字符串返回 - */ - public static String readFileAsString(File file) throws IOException { - StringBuilder sb = new StringBuilder((int) (file.length())); - // 创建字节输入流 - FileInputStream fis = new FileInputStream(file); - // 创建一个长度为10240的Buffer - byte[] bbuf = new byte[10240]; - // 用于保存实际读取的字节数 - int hasRead = 0; - while ((hasRead = fis.read(bbuf)) > 0) { - sb.append(new String(bbuf, 0, hasRead)); - } - fis.close(); - return sb.toString(); - } - - /** - * 根据文件路径读取byte[] 数组 - */ - public static byte[] readFileAsBytes(String filePath) throws IOException { - File file = new File(filePath); - if (!file.exists()) { - throw new FileNotFoundException(filePath); - } else { - return readFileAsBytes(file); - } - } - - /** - * 根据文件读取byte[]数组 - */ - public static byte[] readFileAsBytes(File file) throws IOException { - if (file == null) { - throw new FileNotFoundException(); - } else { - ByteArrayOutputStream bos = new ByteArrayOutputStream((int) file.length()); - BufferedInputStream in = null; - - try { - in = new BufferedInputStream(new FileInputStream(file)); - short bufSize = 1024; - byte[] buffer = new byte[bufSize]; - int len1; - while (-1 != (len1 = in.read(buffer, 0, bufSize))) { - bos.write(buffer, 0, len1); - } - - return bos.toByteArray(); - } finally { - try { - if (in != null) { - in.close(); - } - } catch (IOException var14) { - var14.printStackTrace(); - } - bos.close(); - } - } - } - - - public static void writeStringToFile(String filePath, String content) throws IOException { - BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(filePath)); - bufferedOutputStream.write(content.getBytes()); - bufferedOutputStream.flush(); - bufferedOutputStream.close(); - } - - public static void writeByteToFile(String filePath, byte[] content) throws IOException { - BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(filePath)); - bufferedOutputStream.write(content); - bufferedOutputStream.flush(); - bufferedOutputStream.close(); - } -} diff --git a/src/main/java/com/weilab/biology/util/MailUtil.java b/src/main/java/com/weilab/biology/util/MailUtil.java index 5cd0324..9bbf365 100644 --- a/src/main/java/com/weilab/biology/util/MailUtil.java +++ b/src/main/java/com/weilab/biology/util/MailUtil.java @@ -7,9 +7,6 @@ import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSenderImpl; import org.springframework.stereotype.Component; -import java.util.HashMap; -import java.util.Map; - @Component @Slf4j public class MailUtil {