From b7375b2488df93ba9df57ad13ec628bbff663819 Mon Sep 17 00:00:00 2001 From: vempo Date: Thu, 7 Sep 2017 10:52:29 +0300 Subject: Fixed a few static analysis violations Fixed mostly not closing resources (InputStream, ResultSet) and catching Throwable instead of Exception in some modules. Issue-ID: SDC-291 Change-Id: I34e331cc3b45c4bb3a71c301f50e1706a7b623fd Signed-off-by: vempo --- .../java/org/openecomp/sdc/common/utils/CommonUtil.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'openecomp-be/lib/openecomp-common-lib') diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java index 07322c626b..f4d6209eec 100644 --- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java +++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java @@ -59,26 +59,24 @@ public class CommonUtil { private static FileContentHandler getFileContentMapFromOrchestrationCandidateZipAndValidateNoFolders( byte[] uploadFileData) throws IOException { - ZipEntry zipEntry; + List folderList = new ArrayList<>(); FileContentHandler mapFileContent = new FileContentHandler(); - try { - ZipInputStream inputZipStream; - byte[] fileByteContent; + try (ZipInputStream inputZipStream = new ZipInputStream(new ByteArrayInputStream(uploadFileData))) { + String currentEntryName; - inputZipStream = new ZipInputStream(new ByteArrayInputStream(uploadFileData)); + ZipEntry zipEntry; while ((zipEntry = inputZipStream.getNextEntry()) != null) { - currentEntryName = zipEntry.getName(); - // else, get the file content (as byte array) and save it in a map. - fileByteContent = FileUtils.toByteArray(inputZipStream); + currentEntryName = zipEntry.getName(); int index = lastIndexFileSeparatorIndex(currentEntryName); if (index != -1) { //todo ? folderList.add(currentEntryName); } else { - mapFileContent.addFile(currentEntryName, fileByteContent); + // else, get the file content (as byte array) and save it in a map. + mapFileContent.addFile(currentEntryName, FileUtils.toByteArray(inputZipStream)); } } -- cgit 1.2.3-korg