From 3a705078def1fd0a627b69027a8c63852216fa91 Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam k00365106 Date: Fri, 16 Feb 2018 14:05:39 +0530 Subject: Make sure the streams are closed properly - api Issue-ID: VFC-764 Change-Id: I718adfb397e611c9f106053950f82f7d25656190 Signed-off-by: Kanagaraj Manickam k00365106 --- .../impl/VnfmAdapter2DriverMgrService.java | 29 ++++++++-------------- .../internalsvc/impl/VnfmAdapterMgrService.java | 27 ++++++++------------ .../vnfmadapter/service/constant/Constant.java | 4 +-- 3 files changed, 23 insertions(+), 37 deletions(-) (limited to 'huawei/vnfmadapter/VnfmadapterService/service') diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapter2DriverMgrService.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapter2DriverMgrService.java index fb5e5b81..535053bf 100644 --- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapter2DriverMgrService.java +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapter2DriverMgrService.java @@ -40,7 +40,7 @@ import net.sf.json.JSONObject; *
*

*

- * + * * @author * @version VFC 1.0 Jan 23, 2017 */ @@ -77,38 +77,29 @@ public class VnfmAdapter2DriverMgrService implements IVnfmAdapter2DriverMgrServi /** * Retrieve VIM driver information. - * + * * @return * @throws IOException */ public static String readVnfmAdapterInfoFromJson() throws IOException { - InputStream ins = null; - BufferedInputStream bins = null; String fileContent = ""; String fileName = SystemEnvVariablesFactory.getInstance().getAppRoot() + System.getProperty(Constant.FILE_SEPARATOR) + "etc" + System.getProperty(Constant.FILE_SEPARATOR) + "adapterInfo" + System.getProperty(Constant.FILE_SEPARATOR) + VNFMADAPTER2DRIVERMGR; - try { - ins = new FileInputStream(fileName); - bins = new BufferedInputStream(ins); + try (InputStream ins = new FileInputStream(fileName)){ + try(BufferedInputStream bins = new BufferedInputStream(ins)){ - byte[] contentByte = new byte[ins.available()]; - int num = bins.read(contentByte); + byte[] contentByte = new byte[ins.available()]; + int num = bins.read(contentByte); - if(num > 0) { - fileContent = new String(contentByte); + if(num > 0) { + fileContent = new String(contentByte); + } } } catch(FileNotFoundException e) { LOG.error(fileName + "is not found!", e); - } finally { - if(ins != null) { - ins.close(); - } - if(bins != null) { - bins.close(); - } } return fileContent; @@ -167,6 +158,8 @@ public class VnfmAdapter2DriverMgrService implements IVnfmAdapter2DriverMgrServi } } catch(InterruptedException e) { LOG.error(e.getMessage(), e); + // Restore interrupted state... + Thread.currentThread().interrupt(); } sendRequest(this.paramsMap, this.adapterInfo); diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapterMgrService.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapterMgrService.java index 3afdafeb..28c018cb 100644 --- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapterMgrService.java +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapterMgrService.java @@ -76,38 +76,29 @@ public class VnfmAdapterMgrService implements IVnfmAdapterMgrService { /** * Retrieve VIM driver information. - * + * * @return * @throws IOException */ public String readVnfmAdapterInfoFromJson() throws IOException { - InputStream ins = null; - BufferedInputStream bins = null; String fileContent = ""; String fileName = SystemEnvVariablesFactory.getInstance().getAppRoot() + System.getProperty(Constant.FILE_SEPARATOR) + "etc" + System.getProperty(Constant.FILE_SEPARATOR) + "adapterInfo" + System.getProperty(Constant.FILE_SEPARATOR) + VNFMADAPTERINFO; - try { - ins = new FileInputStream(fileName); - bins = new BufferedInputStream(ins); + try (InputStream ins = new FileInputStream(fileName)) { + try (BufferedInputStream bins = new BufferedInputStream(ins)){ - byte[] contentByte = new byte[ins.available()]; - int num = bins.read(contentByte); + byte[] contentByte = new byte[ins.available()]; + int num = bins.read(contentByte); - if(num > 0) { - fileContent = new String(contentByte); + if(num > 0) { + fileContent = new String(contentByte); + } } } catch(FileNotFoundException e) { LOG.error(fileName + "is not found!", e); - } finally { - if(ins != null) { - ins.close(); - } - if(bins != null) { - bins.close(); - } } return fileContent; @@ -166,6 +157,8 @@ public class VnfmAdapterMgrService implements IVnfmAdapterMgrService { } } catch(InterruptedException e) { LOG.error(e.getMessage(), e); + // Restore interrupted state... + Thread.currentThread().interrupt(); } sendRequest(this.paramsMap, this.adapterInfo); diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/Constant.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/Constant.java index 3b1036e2..d26f849d 100644 --- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/Constant.java +++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/Constant.java @@ -152,11 +152,11 @@ public class Constant { public static final String FILE_SEPARATOR = "file.separator"; - public static final String PASSWORD = "password"; + public static final String PASSWORD = "password"; // NOSONAR public static final String USERNAME = "userName"; - public static final String LOCAL_HOST = "127.0.0.1"; + public static final String LOCAL_HOST = "127.0.0.1"; // NOSONAR private Constant() { // private constructor -- cgit 1.2.3-korg