From 3d5dd63fd91d20fc2b508efecde062532f07fc49 Mon Sep 17 00:00:00 2001 From: Daniel Espen Date: Thu, 29 Jun 2023 11:47:46 +0200 Subject: [PATCH] Fixes FileUpload file streams not closing in case of exceptions Signed-off-by: Daniel Espen --- .../basyx/submodel/restapi/vab/VABSubmodelAPI.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/eclipse/basyx/submodel/restapi/vab/VABSubmodelAPI.java b/src/main/java/org/eclipse/basyx/submodel/restapi/vab/VABSubmodelAPI.java index 9b6e6c9f..3ce9a036 100644 --- a/src/main/java/org/eclipse/basyx/submodel/restapi/vab/VABSubmodelAPI.java +++ b/src/main/java/org/eclipse/basyx/submodel/restapi/vab/VABSubmodelAPI.java @@ -164,13 +164,10 @@ private void createFile(String idShortPath, Object newValue, ISubmodelElement su java.io.File targetFile = new java.io.File(filePath); - FileOutputStream outStream = new FileOutputStream(targetFile); - InputStream inStream = (InputStream) newValue; - - IOUtils.copy(inStream, outStream); - - inStream.close(); - outStream.close(); + try (FileOutputStream outStream = new FileOutputStream(targetFile); + InputStream inStream = (InputStream) newValue) { + IOUtils.copy(inStream, outStream); + } } private String getFilePath(String idShortPath, File file) {