From df4a7a3530a0c52c17b1cb9a412de0c5b3fd01b3 Mon Sep 17 00:00:00 2001 From: Parshad Patel Date: Fri, 26 Oct 2018 15:24:33 +0900 Subject: Fix sonar blocker issue in sli/adapters Fix use try-with-resources issues in ansible-adapter,salstack-adapter Issue-ID: CCSDK-629 Change-Id: Ie8457751c155aa95fdfcdf2faad4cd8089a58ad3 Signed-off-by: Parshad Patel --- .../sli/adaptors/saltstack/impl/SaltstackAdapterImpl.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'saltstack-adapter') diff --git a/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdapterImpl.java b/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdapterImpl.java index ef54104e0..34321ea59 100644 --- a/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdapterImpl.java +++ b/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdapterImpl.java @@ -260,16 +260,15 @@ public class SaltstackAdapterImpl implements SaltstackAdapter { doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(), "Input file " + "is not of type .sls"); } - InputStream in = new FileInputStream(file); - byte[] data = new byte[(int) file.length()]; - in.read(data); - String str = new String(data, "UTF-8"); - in.close(); - String slsWithoutExtn = stripExtension(slsFile); - constructedCommand.append(parseFileParam(fileParams)).append("echo -e \"").append(str).append("\" > /srv/salt/"). + try(InputStream in = new FileInputStream(file)){ + byte[] data = new byte[(int) file.length()]; + in.read(data); + String str = new String(data, "UTF-8"); + String slsWithoutExtn = stripExtension(slsFile); + constructedCommand.append(parseFileParam(fileParams)).append("echo -e \"").append(str).append("\" > /srv/salt/"). append(slsFile).append("; ").append(COMMAND_CHANGE_DEFAULT_DIR).append(" salt '"). append(applyTo).append("' state.apply ").append(slsWithoutExtn).append(" ").append(parseEnvParam(envParams)).append(COMMAND_IN_JSON_OUT); - + } logger.info("Command to be executed on server : " + constructedCommand.toString()); } catch (FileNotFoundException e) { -- cgit 1.2.3-korg