refactor: 优化代码
This commit is contained in:
parent
dad8ad2be9
commit
1d84cda5fe
|
@ -104,9 +104,6 @@ public class APITestService {
|
|||
}
|
||||
|
||||
private void createBodyFiles(ApiTest test, List<String> bodyUploadIds, List<MultipartFile> bodyFiles) {
|
||||
if (bodyFiles == null || bodyFiles.isEmpty()) {
|
||||
|
||||
}
|
||||
String dir = BODY_FILE_DIR + "/" + test.getId();
|
||||
File testDir = new File(dir);
|
||||
if (!testDir.exists()) {
|
||||
|
@ -115,24 +112,12 @@ public class APITestService {
|
|||
for (int i = 0; i < bodyUploadIds.size(); i++) {
|
||||
MultipartFile item = bodyFiles.get(i);
|
||||
File file = new File(testDir + "/" + bodyUploadIds.get(i) + "_" + item.getOriginalFilename());
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
try {
|
||||
try (InputStream in = item.getInputStream(); OutputStream out = new FileOutputStream(file)) {
|
||||
file.createNewFile();
|
||||
in = item.getInputStream();
|
||||
out = new FileOutputStream(file);
|
||||
FileUtil.copyStream(in, out);
|
||||
} catch (IOException e) {
|
||||
LogUtil.error(e);
|
||||
MSException.throwException(Translator.get("upload_fail"));
|
||||
} finally {
|
||||
try {
|
||||
in.close();
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
LogUtil.error(e);
|
||||
MSException.throwException(Translator.get("upload_fail"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue