diff options
author | Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com> | 2018-02-16 14:05:39 +0530 |
---|---|---|
committer | Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com> | 2018-02-16 14:25:53 +0530 |
commit | 3a705078def1fd0a627b69027a8c63852216fa91 (patch) | |
tree | e477b330bd68fee64f1861dbb8bea8321c00ea7e /huawei/vnfmadapter/VnfmadapterService/service | |
parent | bb1d702a7675354817c28c0888264d06202dbee6 (diff) |
Make sure the streams are closed properly - api
Issue-ID: VFC-764
Change-Id: I718adfb397e611c9f106053950f82f7d25656190
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Diffstat (limited to 'huawei/vnfmadapter/VnfmadapterService/service')
3 files changed, 23 insertions, 37 deletions
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; * <br> * <p> * </p> - * + * * @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 |