diff options
author | Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com> | 2018-02-16 10:26:39 +0530 |
---|---|---|
committer | Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com> | 2018-02-16 10:26:39 +0530 |
commit | 787a05f80539a61185e2d9d327b594b6b8986a93 (patch) | |
tree | 73b2abb4921ac488b9f71971c721556dbef7abbf /ResmanagementService/service/src/main | |
parent | c7e6312f089470096b41891dc400cb1637328811 (diff) |
Make sure the streams are closed properly
Issue-ID: VFC-764
Change-Id: Ic7544a690a5bd64582344946fd8c419ad7b89ca6
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Diffstat (limited to 'ResmanagementService/service/src/main')
-rw-r--r-- | ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrService.java | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrService.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrService.java index 2feaba3..625b41d 100644 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrService.java +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrService.java @@ -41,7 +41,7 @@ import net.sf.json.JSONObject; * <br> * <p> * </p> - * + * * @author * @version VFC 1.0 Sep 22, 2016 */ @@ -77,38 +77,28 @@ public class ResmgrAdapterMgrService implements IResmgrAdapterMgrService { /** * Retrieve VIM driver information. - * + * * @return * @throws IOException */ public static String readVimAdapterInfoFromJson() throws IOException { - InputStream ins = null; - BufferedInputStream bins = null; String fileContent = ""; String fileName = SystemEnvVariablesFactory.getInstance().getAppRoot() + System.getProperty("file.separator") + "etc" + System.getProperty("file.separator") + "adapterInfo" + System.getProperty("file.separator") + RESMGRADAPTERINFO; - try { - ins = new FileInputStream(fileName); - bins = new BufferedInputStream(ins); - - byte[] contentByte = new byte[ins.available()]; - int num = bins.read(contentByte); + try (InputStream ins = new FileInputStream(fileName)) { + try(BufferedInputStream bins = new BufferedInputStream(ins)) { + 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; |