From 3b98cea01fc44f7fc0d18fc03acd24b487e595ec Mon Sep 17 00:00:00 2001 From: Avinash S Date: Wed, 7 Mar 2018 10:49:41 +0000 Subject: Fix sonar issues for VNFSDK Validation Sonar blocker fix Issue-ID: VNFSDK-219 Change-Id: Ib581a95eba891b6d1b02ce5a1c3d1a24c44aed80 Signed-off-by: Avinash S --- .../org/onap/validation/csar/CsarValidator.java | 47 +++++++++++++--------- 1 file changed, 28 insertions(+), 19 deletions(-) (limited to 'csarvalidation') diff --git a/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java b/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java index a286665..8b6be13 100644 --- a/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java +++ b/csarvalidation/src/main/java/org/onap/validation/csar/CsarValidator.java @@ -30,16 +30,16 @@ import org.yaml.snakeyaml.Yaml; public class CsarValidator { - private static final Logger LOG = LoggerFactory.getLogger(CsarValidator.class); + private static final Logger LOG = LoggerFactory.getLogger(CsarValidator.class); //Schema files static private ValidatorSchemaLoader vsl; // Map of CSAR file and un-zipped file indices - static private HashMap csarFiles; + static private HashMap csarFiles; // Map of packageId and CSAR files - private static HashMap> csar = new HashMap>(); + private static HashMap> csar = new HashMap>(); private static String MAINSERV_TEMPLATE = CommonConstants.MAINSERV_TEMPLATE; private static String MAINSERV_MANIFEST; @@ -104,22 +104,31 @@ public class CsarValidator { */ public static boolean validateCsarIntegrity(String csarWithPath) { - try { - RandomAccessFile raf = new RandomAccessFile(csarWithPath, "r"); - long n = raf.readInt(); - raf.close(); - - // Check for the CSAR's integrity - if (n != 0x504B0304) { - LOG.error("CSAR %s is not a valid CSAR/ZIP file! "); - return false; - } - return true; - } catch (IOException e1) { - LOG.error("CSAR %s is not a valid CSAR/ZIP file! ", e1); - return false; - } - } + try { + RandomAccessFile raf = new RandomAccessFile(csarWithPath, "r"); + try { + long n = raf.readInt(); + + // Check for the CSAR's integrity + if (n != 0x504B0304) { + LOG.error("CSAR %s contents are not a valid! "); + return false; + } + return true; + } catch (FileNotFoundException e1) { + LOG.error("CSAR %s is not a valid CSAR/ZIP file! ", e1); + return false; + } + finally { + raf.close(); + return true; + } + } + catch (IOException e1) { + LOG.error("CSAR %s is not a valid CSAR/ZIP file! ", e1); + return false; + } + } /** * -- cgit 1.2.3-korg