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) {
|
private void createBodyFiles(ApiTest test, List<String> bodyUploadIds, List<MultipartFile> bodyFiles) {
|
||||||
if (bodyFiles == null || bodyFiles.isEmpty()) {
|
|
||||||
|
|
||||||
}
|
|
||||||
String dir = BODY_FILE_DIR + "/" + test.getId();
|
String dir = BODY_FILE_DIR + "/" + test.getId();
|
||||||
File testDir = new File(dir);
|
File testDir = new File(dir);
|
||||||
if (!testDir.exists()) {
|
if (!testDir.exists()) {
|
||||||
|
@ -115,24 +112,12 @@ public class APITestService {
|
||||||
for (int i = 0; i < bodyUploadIds.size(); i++) {
|
for (int i = 0; i < bodyUploadIds.size(); i++) {
|
||||||
MultipartFile item = bodyFiles.get(i);
|
MultipartFile item = bodyFiles.get(i);
|
||||||
File file = new File(testDir + "/" + bodyUploadIds.get(i) + "_" + item.getOriginalFilename());
|
File file = new File(testDir + "/" + bodyUploadIds.get(i) + "_" + item.getOriginalFilename());
|
||||||
InputStream in = null;
|
try (InputStream in = item.getInputStream(); OutputStream out = new FileOutputStream(file)) {
|
||||||
OutputStream out = null;
|
|
||||||
try {
|
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
in = item.getInputStream();
|
|
||||||
out = new FileOutputStream(file);
|
|
||||||
FileUtil.copyStream(in, out);
|
FileUtil.copyStream(in, out);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LogUtil.error(e);
|
LogUtil.error(e);
|
||||||
MSException.throwException(Translator.get("upload_fail"));
|
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