From 1d84cda5feed67db5289573e91348b6380746e17 Mon Sep 17 00:00:00 2001 From: q4speed Date: Tue, 8 Sep 2020 10:49:18 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metersphere/api/service/APITestService.java | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/APITestService.java b/backend/src/main/java/io/metersphere/api/service/APITestService.java index a4161834b6..70c46f1f9e 100644 --- a/backend/src/main/java/io/metersphere/api/service/APITestService.java +++ b/backend/src/main/java/io/metersphere/api/service/APITestService.java @@ -104,9 +104,6 @@ public class APITestService { } private void createBodyFiles(ApiTest test, List bodyUploadIds, List 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")); - } } } }