diff options
author | Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com> | 2019-03-12 09:50:58 +0800 |
---|---|---|
committer | Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com> | 2019-03-12 09:50:58 +0800 |
commit | 6addbe8d3b660acbde9191edac2e8f36dcf16197 (patch) | |
tree | 313bb4961d4dd541b103a9abe4913fd4e36c5544 /csarvalidation | |
parent | ebb53e546c55628d718f7d4c3c8c8505cd8c3075 (diff) |
Fix to close the zip stream
Issue-ID: VNFSDK-276
Change-Id: I9af3d3fd1a1e842a8ea7e6d1e6e9ee97e4606f43
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Diffstat (limited to 'csarvalidation')
-rw-r--r-- | csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java b/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java index cfea2b4..a68bd9f 100644 --- a/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java @@ -55,7 +55,7 @@ public class CSARArchive { return SOL0004_2_4_1; } - public Path tempDir; + protected Path tempDir; public static final String TEMP_DIR = "."; @@ -98,7 +98,7 @@ public class CSARArchive { public static final String Entry_Definition__tosca_definitions_version__simple_1_0 = "tosca_simple_yaml_1_0"; public static final String Entry_Definition__tosca_definitions_version__simple_1_1 = "tosca_simple_yaml_1_1"; - public static final String[] Entry_Definition__tosca_definitions_versions = new String[] { + protected static final String[] Entry_Definition__tosca_definitions_versions = new String[] { Entry_Definition__tosca_definitions_version__simple_1_0, Entry_Definition__tosca_definitions_version__simple_1_1 }; @@ -875,25 +875,25 @@ public class CSARArchive { throw new RuntimeException(csarPath + " does not exist"); } - ZipInputStream csar = new ZipInputStream(new BufferedInputStream(new FileInputStream(csarFile))); + try (ZipInputStream csar = new ZipInputStream(new BufferedInputStream(new FileInputStream(csarFile)))){ + ZipEntry entry; + byte[] buffer = new byte[2048]; + while ((entry = csar.getNextEntry()) != null) { - ZipEntry entry; - byte[] buffer = new byte[2048]; - while ((entry = csar.getNextEntry()) != null) { + File filePath = new File(this.tempDir + File.separator + entry.getName()); - File filePath = new File(this.tempDir + File.separator + entry.getName()); - - if (!filePath.getParentFile().isDirectory()) { - filePath.getParentFile().delete(); - } - filePath.getParentFile().mkdirs(); + if (!filePath.getParentFile().isDirectory()) { + filePath.getParentFile().delete(); + } + filePath.getParentFile().mkdirs(); - try (FileOutputStream fos = new FileOutputStream(filePath); - BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length)) { + try (FileOutputStream fos = new FileOutputStream(filePath); + BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length)) { - int len; - while ((len = csar.read(buffer)) > 0) { - bos.write(buffer, 0, len); + int len; + while ((len = csar.read(buffer)) > 0) { + bos.write(buffer, 0, len); + } } } } |